You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
4.1 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #include "pEp_internal.h"
  2. #include <memory.h>
  3. #include <assert.h>
  4. PEP_STATUS init_transport_system(PEP_SESSION session)
  5. {
  6. assert(session);
  7. pEpSession *_session = (pEpSession *) session;
  8. PEP_transport_t* transports = _session->transports;
  9. assert(PEP_trans__count == 1);
  10. memset(transports, 0, sizeof(PEP_transport_t) * PEP_trans__count);
  11. transports[0].id = PEP_trans_auto;
  12. return PEP_STATUS_OK;
  13. }
  14. void release_transport_system(PEP_SESSION session)
  15. {
  16. assert(session);
  17. // nothing yet
  18. }
  19. identity_list *new_identity_list(const pEp_identity *ident)
  20. {
  21. identity_list *id_list = calloc(1, sizeof(identity_list));
  22. assert(id_list);
  23. if (id_list == NULL)
  24. return NULL;
  25. if (ident) {
  26. id_list->ident = identity_dup(ident);
  27. assert(id_list->ident);
  28. if (id_list->ident == NULL) {
  29. free(id_list);
  30. return NULL;
  31. }
  32. }
  33. return id_list;
  34. }
  35. identity_list *identity_list_dup(const identity_list *src)
  36. {
  37. assert(src);
  38. identity_list *id_list = new_identity_list(src->ident);
  39. assert(id_list);
  40. if (id_list == NULL)
  41. return NULL;
  42. if (src->next) {
  43. id_list->next = identity_list_dup(src->next);
  44. if (id_list->next == NULL) {
  45. free_identity_list(id_list);
  46. return NULL;
  47. }
  48. }
  49. return id_list;
  50. }
  51. void free_identity_list(identity_list *id_list)
  52. {
  53. if (id_list) {
  54. free_identity_list(id_list->next);
  55. free_identity(id_list->ident);
  56. free(id_list);
  57. }
  58. }
  59. identity_list *identity_list_add(identity_list *id_list, const pEp_identity *ident)
  60. {
  61. assert(id_list);
  62. assert(ident);
  63. if (id_list->ident == NULL) {
  64. id_list->ident = identity_dup(ident);
  65. assert(id_list->ident);
  66. if (id_list->ident == NULL)
  67. return NULL;
  68. else
  69. return id_list;
  70. }
  71. else if (id_list->next == NULL) {
  72. id_list->next = new_identity_list(ident);
  73. assert(id_list->next);
  74. return id_list->next;
  75. }
  76. else {
  77. return identity_list_add(id_list->next, ident);
  78. }
  79. }
  80. message *new_message(
  81. msg_direction dir,
  82. const pEp_identity *from,
  83. const identity_list *to,
  84. const char *shortmsg
  85. )
  86. {
  87. message *msg = calloc(1, sizeof(message));
  88. assert(msg);
  89. if (msg == NULL)
  90. return NULL;
  91. if (msg->shortmsg) {
  92. msg->shortmsg = strdup(shortmsg);
  93. assert(msg->shortmsg);
  94. if (msg->shortmsg == NULL) {
  95. free(msg);
  96. return NULL;
  97. }
  98. msg->shortmsg_size = strlen(msg->shortmsg);
  99. }
  100. msg->dir = dir;
  101. msg->from = identity_dup(from);
  102. assert(msg->from);
  103. if (msg->from == NULL) {
  104. free_message(msg);
  105. return NULL;
  106. }
  107. msg->to = identity_list_dup(to);
  108. assert(msg->to);
  109. if (msg->to == NULL) {
  110. free_message(msg);
  111. return NULL;
  112. }
  113. return msg;
  114. }
  115. void free_message(message *msg)
  116. {
  117. free(msg->id);
  118. free(msg->shortmsg);
  119. free(msg->longmsg);
  120. free(msg->longmsg_formatted);
  121. free(msg->rawmsg);
  122. free_identity_list(msg->to);
  123. free_identity_list(msg->cc);
  124. free_identity_list(msg->bcc);
  125. free(msg->refering_id);
  126. free_message_ref_list(msg->refered_by);
  127. free(msg);
  128. }
  129. message_ref_list *new_message_ref_list(message *msg)
  130. {
  131. message_ref_list *msg_list = calloc(1, sizeof(message_ref_list));
  132. assert(msg_list);
  133. if (msg_list == NULL)
  134. return NULL;
  135. msg_list->msg_ref = msg;
  136. return msg_list;
  137. }
  138. void free_message_ref_list(message_ref_list *msg_list)
  139. {
  140. if (msg_list) {
  141. free_message_ref_list(msg_list->next);
  142. free(msg_list);
  143. }
  144. }
  145. message_ref_list *message_ref_list_add(message_ref_list *msg_list, message *msg)
  146. {
  147. assert(msg_list);
  148. assert(msg);
  149. if (msg_list->msg_ref == NULL) {
  150. msg_list->msg_ref = msg;
  151. return msg_list;
  152. }
  153. else if (msg_list->next == NULL) {
  154. msg_list->next = new_message_ref_list(msg);
  155. assert(msg_list->next);
  156. return msg_list->next;
  157. }
  158. else {
  159. return message_ref_list_add(msg_list->next, msg);
  160. }
  161. }