sip_multipart.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJSIP_SIP_MULTIPART_H__
  19. #define __PJSIP_SIP_MULTIPART_H__
  20. /**
  21. * @file pjsip/sip_multipart.h
  22. * @brief Multipart support.
  23. */
  24. #include <pjsip/sip_msg.h>
  25. PJ_BEGIN_DECL
  26. /**
  27. * @defgroup PJSIP_MULTIPART Multipart message bodies.
  28. * @ingroup PJSIP_MSG
  29. * @brief Support for multipart message bodies.
  30. * @{
  31. */
  32. /**
  33. * This structure describes the individual body part inside a multipart
  34. * message body. It mainly contains the message body itself and optional
  35. * headers.
  36. */
  37. typedef struct pjsip_multipart_part
  38. {
  39. /**
  40. * Standard list element.
  41. */
  42. PJ_DECL_LIST_MEMBER(struct pjsip_multipart_part);
  43. /**
  44. * Optional message headers.
  45. */
  46. pjsip_hdr hdr;
  47. /**
  48. * Pointer to the message body.
  49. */
  50. pjsip_msg_body *body;
  51. } pjsip_multipart_part;
  52. /**
  53. * Create an empty multipart body.
  54. *
  55. * @param pool Memory pool to allocate memory from.
  56. * @param ctype Optional MIME media type of the multipart
  57. * bodies. If not specified, "multipart/mixed"
  58. * will be used.
  59. * @param boundary Optional string to be set as part boundary.
  60. * The boundary string excludes the leading
  61. * hyphens. If this parameter is NULL or empty,
  62. * a random boundary will be generated.
  63. *
  64. * @return Multipart body instance with no part.
  65. */
  66. PJ_DECL(pjsip_msg_body*) pjsip_multipart_create(pj_pool_t *pool,
  67. const pjsip_media_type *ctype,
  68. const pj_str_t *boundary);
  69. /**
  70. * Create an empty multipart part.
  71. *
  72. * @param pool The memory pool.
  73. *
  74. * @return The multipart part.
  75. */
  76. PJ_DECL(pjsip_multipart_part*) pjsip_multipart_create_part(pj_pool_t *pool);
  77. /**
  78. * Perform a deep clone to a multipart part.
  79. *
  80. * @param pool The memory pool.
  81. * @param part The part to be duplicated.
  82. *
  83. * @return Copy of the multipart part.
  84. */
  85. PJ_DECL(pjsip_multipart_part*)
  86. pjsip_multipart_clone_part(pj_pool_t *pool,
  87. const pjsip_multipart_part *part);
  88. /**
  89. * Add a part into multipart bodies.
  90. *
  91. * @param pool The memory pool.
  92. * @param mp The multipart bodies.
  93. * @param part The part to be added into the bodies.
  94. *
  95. * @return PJ_SUCCESS on success.
  96. */
  97. PJ_DECL(pj_status_t) pjsip_multipart_add_part(pj_pool_t *pool,
  98. pjsip_msg_body *mp,
  99. pjsip_multipart_part *part);
  100. /**
  101. * Get the first part of multipart bodies.
  102. *
  103. * @param mp The multipart bodies.
  104. *
  105. * @return The first part, or NULL if the multipart
  106. * bodies currently doesn't hold any elements.
  107. */
  108. PJ_DECL(pjsip_multipart_part*)
  109. pjsip_multipart_get_first_part(const pjsip_msg_body *mp);
  110. /**
  111. * Get the next part after the specified part.
  112. *
  113. * @param mp The multipart bodies.
  114. * @param part The part.
  115. *
  116. * @return The next part, or NULL if there is no other part after
  117. * the part.
  118. */
  119. PJ_DECL(pjsip_multipart_part*)
  120. pjsip_multipart_get_next_part(const pjsip_msg_body *mp,
  121. pjsip_multipart_part *part);
  122. /**
  123. * Find a body inside multipart bodies which has the specified content type.
  124. *
  125. * @param mp The multipart body.
  126. * @param content_type Content type to find.
  127. * @param start If specified, the search will begin at
  128. * start->next. Otherwise it will begin at
  129. * the first part in the multipart bodies.
  130. *
  131. * @return The first part with the specified content type
  132. * if found, or NULL.
  133. */
  134. PJ_DECL(pjsip_multipart_part*)
  135. pjsip_multipart_find_part( const pjsip_msg_body *mp,
  136. const pjsip_media_type *content_type,
  137. const pjsip_multipart_part *start);
  138. /**
  139. * Find a body inside multipart bodies which has a header matching the
  140. * supplied one. Most useful for finding a part with a specific Content-ID.
  141. *
  142. * @param pool Memory pool to use for temp space.
  143. * @param mp The multipart body.
  144. * @param search_hdr Header to search for.
  145. * @param start If specified, the search will begin at
  146. * start->next part. Otherwise it will begin at
  147. * the first part in the multipart bodies.
  148. *
  149. * @return The first part which has a header matching the
  150. * specified one, or NULL if not found.
  151. */
  152. PJ_DECL(pjsip_multipart_part*)
  153. pjsip_multipart_find_part_by_header(pj_pool_t *pool,
  154. const pjsip_msg_body *mp,
  155. void *search_hdr,
  156. const pjsip_multipart_part *start);
  157. /**
  158. * Find a body inside multipart bodies which has a header matching the
  159. * supplied name and value. Most useful for finding a part with a specific
  160. * Content-ID.
  161. *
  162. * @param pool Memory pool to use for temp space.
  163. * @param mp The multipart body.
  164. * @param hdr_name Header name to search for.
  165. * @param hdr_value Header value search for.
  166. * @param start If specified, the search will begin at
  167. * start->next part. Otherwise it will begin at
  168. * the first part in the multipart bodies.
  169. *
  170. * @return The first part which has a header matching the
  171. * specified one, or NULL if not found.
  172. */
  173. PJ_DECL(pjsip_multipart_part*)
  174. pjsip_multipart_find_part_by_header_str(pj_pool_t *pool,
  175. const pjsip_msg_body *mp,
  176. const pj_str_t *hdr_name,
  177. const pj_str_t *hdr_value,
  178. const pjsip_multipart_part *start);
  179. /**
  180. * Find a body inside multipart bodies which has a Content-ID value matching the
  181. * supplied "cid" URI in pj_str form. The "cid:" scheme will be assumed if the
  182. * URL doesn't start with it. Enclosing angle brackets will also be handled
  183. * correctly if they exist.
  184. *
  185. * @see RFC2392 Content-ID and Message-ID Uniform Resource Locators
  186. *
  187. * @param pool Memory pool to use for temp space.
  188. * @param mp The multipart body.
  189. * @param cid The "cid" URI to search for in pj_str form.
  190. *
  191. * @return The first part which has a Content-ID header matching the
  192. * specified "cid" URI. or NULL if not found.
  193. */
  194. PJ_DECL(pjsip_multipart_part*)
  195. pjsip_multipart_find_part_by_cid_str(pj_pool_t *pool,
  196. const pjsip_msg_body *mp,
  197. pj_str_t *cid);
  198. /**
  199. * Find a body inside multipart bodies which has a Content-ID value matching the
  200. * supplied "cid" URI.
  201. *
  202. * @see RFC2392 Content-ID and Message-ID Uniform Resource Locators
  203. *
  204. * @param pool Memory pool to use for temp space.
  205. * @param mp The multipart body.
  206. * @param cid The "cid" URI to search for.
  207. *
  208. * @return The first part which had a Content-ID header matching the
  209. * specified "cid" URI. or NULL if not found.
  210. */
  211. PJ_DECL(pjsip_multipart_part*)
  212. pjsip_multipart_find_part_by_cid_uri(pj_pool_t *pool,
  213. const pjsip_msg_body *mp,
  214. pjsip_other_uri *cid);
  215. /**
  216. * Parse multipart message.
  217. *
  218. * @param pool Memory pool.
  219. * @param buf Input buffer.
  220. * @param len The buffer length.
  221. * @param ctype Content type of the multipart body.
  222. * @param options Parsing options, must be zero for now.
  223. *
  224. * @return Multipart message body.
  225. */
  226. PJ_DECL(pjsip_msg_body*) pjsip_multipart_parse(pj_pool_t *pool,
  227. char *buf, pj_size_t len,
  228. const pjsip_media_type *ctype,
  229. unsigned options);
  230. /**
  231. * Get the boundary string and the raw message body of the specified
  232. * multipart message body. Note that raw message body will only be available
  233. * if the multipart message body is generated by pjsip_multipart_parse().
  234. *
  235. * @param mp The multipart message body.
  236. * @param boundary Optional parameter to receive the boundary string.
  237. * @param raw_data Optional parameter to receive the raw message body.
  238. *
  239. * @return PJ_SUCCESS on success.
  240. */
  241. PJ_DECL(pj_status_t) pjsip_multipart_get_raw(pjsip_msg_body *mp,
  242. pj_str_t *boundary,
  243. pj_str_t *raw_data);
  244. /**
  245. * @} PJSIP_MULTIPART
  246. */
  247. PJ_END_DECL
  248. #endif /* __PJSIP_SIP_MULTIPART_H__ */