sip_msg.h 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJSIP_SIP_MSG_H__
  20. #define __PJSIP_SIP_MSG_H__
  21. /**
  22. * @file pjsip/sip_msg.h
  23. * @brief SIP Message Structure.
  24. */
  25. #include <pjsip/sip_types.h>
  26. #include <pjsip/sip_uri.h>
  27. #include <pj/list.h>
  28. PJ_BEGIN_DECL
  29. /**
  30. * @defgroup PJSIP_MSG Messaging Elements
  31. * @ingroup PJSIP_CORE
  32. * @brief Various SIP message elements such as methods, headers, URIs, etc.
  33. * @{
  34. */
  35. /* **************************************************************************/
  36. /**
  37. * @defgroup PJSIP_MSG_METHOD Methods
  38. * @brief Method names and manipulation.
  39. * @ingroup PJSIP_MSG
  40. * @{
  41. */
  42. /**
  43. * This enumeration declares SIP methods as described by RFC3261. Additional
  44. * methods do exist, and they are described by corresponding RFCs for the SIP
  45. * extentensions. Since they won't alter the characteristic of the processing
  46. * of the message, they don't need to be explicitly mentioned here.
  47. */
  48. typedef enum pjsip_method_e
  49. {
  50. PJSIP_INVITE_METHOD, /**< INVITE method, for establishing dialogs. */
  51. PJSIP_CANCEL_METHOD, /**< CANCEL method, for cancelling request. */
  52. PJSIP_ACK_METHOD, /**< ACK method. */
  53. PJSIP_BYE_METHOD, /**< BYE method, for terminating dialog. */
  54. PJSIP_REGISTER_METHOD, /**< REGISTER method. */
  55. PJSIP_OPTIONS_METHOD, /**< OPTIONS method. */
  56. PJSIP_OTHER_METHOD /**< Other method. */
  57. } pjsip_method_e;
  58. /**
  59. * This structure represents a SIP method.
  60. * Application must always use either #pjsip_method_init or #pjsip_method_set
  61. * to make sure that method name is initialized correctly. This way, the name
  62. * member will always contain a valid method string regardless whether the ID
  63. * is recognized or not.
  64. */
  65. struct pjsip_method
  66. {
  67. pjsip_method_e id; /**< Method ID, from \a pjsip_method_e. */
  68. pj_str_t name; /**< Method name, which will always contain the
  69. method string. */
  70. };
  71. /*
  72. * For convenience, standard method structures are defined in the library.
  73. */
  74. /** INVITE method constant. @see pjsip_get_invite_method() */
  75. PJ_DECL_DATA(const pjsip_method) pjsip_invite_method;
  76. /** CANCEL method constant. @see pjsip_get_cancel_method() */
  77. PJ_DECL_DATA(const pjsip_method) pjsip_cancel_method;
  78. /** ACK method constant. @see pjsip_get_ack_method() */
  79. PJ_DECL_DATA(const pjsip_method) pjsip_ack_method;
  80. /** BYE method constant. @see pjsip_get_bye_method() */
  81. PJ_DECL_DATA(const pjsip_method) pjsip_bye_method;
  82. /** REGISTER method constant. @see pjsip_get_register_method() */
  83. PJ_DECL_DATA(const pjsip_method) pjsip_register_method;
  84. /** OPTIONS method constant. @see pjsip_get_options_method() */
  85. PJ_DECL_DATA(const pjsip_method) pjsip_options_method;
  86. /*
  87. * Accessor functions for standard SIP methods.
  88. */
  89. /** Get INVITE method constant. */
  90. PJ_DECL(const pjsip_method*) pjsip_get_invite_method(void);
  91. /** Get CANCEL method constant. */
  92. PJ_DECL(const pjsip_method*) pjsip_get_cancel_method(void);
  93. /** Get ACK method constant. */
  94. PJ_DECL(const pjsip_method*) pjsip_get_ack_method(void);
  95. /** Get BYE method constant. */
  96. PJ_DECL(const pjsip_method*) pjsip_get_bye_method(void);
  97. /** Get REGISTER method constant.*/
  98. PJ_DECL(const pjsip_method*) pjsip_get_register_method(void);
  99. /** Get OPTIONS method constant. */
  100. PJ_DECL(const pjsip_method*) pjsip_get_options_method(void);
  101. /*
  102. * Accessor functions
  103. */
  104. /**
  105. * Initialize the method structure from a string.
  106. * This function will check whether the method is a known method then set
  107. * both the id and name accordingly.
  108. *
  109. * @param m The method to initialize.
  110. * @param pool Pool where memory allocation will be allocated from, if required.
  111. * @param str The method string.
  112. */
  113. PJ_DECL(void) pjsip_method_init( pjsip_method *m,
  114. pj_pool_t *pool,
  115. const pj_str_t *str);
  116. /**
  117. * Initialize the method structure from a string, without cloning the string.
  118. * See #pjsip_method_init.
  119. *
  120. * @param m The method structure to be initialized.
  121. * @param str The method string.
  122. */
  123. PJ_DECL(void) pjsip_method_init_np( pjsip_method *m,
  124. pj_str_t *str);
  125. /**
  126. * Set the method with the predefined method ID.
  127. * This function will also set the name member of the structure to the correct
  128. * string according to the method.
  129. *
  130. * @param m The method structure.
  131. * @param id The method ID.
  132. */
  133. PJ_DECL(void) pjsip_method_set( pjsip_method *m, pjsip_method_e id );
  134. /**
  135. * Copy one method structure to another. If the method is of the known methods,
  136. * then memory allocation is not required.
  137. *
  138. * @param pool Pool to allocate memory from, if required.
  139. * @param method The destination method to copy to.
  140. * @param rhs The source method to copy from.
  141. */
  142. PJ_DECL(void) pjsip_method_copy( pj_pool_t *pool,
  143. pjsip_method *method,
  144. const pjsip_method *rhs );
  145. /**
  146. * Compare one method with another, and conveniently determine whether the
  147. * first method is equal, less than, or greater than the second method.
  148. *
  149. * @param m1 The first method.
  150. * @param m2 The second method.
  151. *
  152. * @return Zero if equal, otherwise will return -1 if less or +1 if greater.
  153. */
  154. PJ_DECL(int) pjsip_method_cmp( const pjsip_method *m1, const pjsip_method *m2);
  155. /**
  156. * @}
  157. */
  158. /* **************************************************************************/
  159. /**
  160. * @defgroup PJSIP_MSG_HDR Header Fields
  161. * @brief Declarations for various SIP header fields.
  162. * @ingroup PJSIP_MSG
  163. * @{
  164. */
  165. /**
  166. * Header types, as defined by RFC3261.
  167. */
  168. typedef enum pjsip_hdr_e
  169. {
  170. /*
  171. * These are the headers documented in RFC3261. Headers not documented
  172. * there must have type PJSIP_H_OTHER, and the header type itself is
  173. * recorded in the header name string.
  174. *
  175. * DO NOT CHANGE THE VALUE/ORDER OF THE HEADER IDs!!!.
  176. */
  177. PJSIP_H_ACCEPT,
  178. PJSIP_H_ACCEPT_ENCODING_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  179. PJSIP_H_ACCEPT_LANGUAGE_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  180. PJSIP_H_ALERT_INFO_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  181. PJSIP_H_ALLOW,
  182. PJSIP_H_AUTHENTICATION_INFO_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  183. PJSIP_H_AUTHORIZATION,
  184. PJSIP_H_CALL_ID,
  185. PJSIP_H_CALL_INFO_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  186. PJSIP_H_CONTACT,
  187. PJSIP_H_CONTENT_DISPOSITION_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  188. PJSIP_H_CONTENT_ENCODING_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  189. PJSIP_H_CONTENT_LANGUAGE_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  190. PJSIP_H_CONTENT_LENGTH,
  191. PJSIP_H_CONTENT_TYPE,
  192. PJSIP_H_CSEQ,
  193. PJSIP_H_DATE_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  194. PJSIP_H_ERROR_INFO_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  195. PJSIP_H_EXPIRES,
  196. PJSIP_H_FROM,
  197. PJSIP_H_IN_REPLY_TO_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  198. PJSIP_H_MAX_FORWARDS,
  199. PJSIP_H_MIME_VERSION_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  200. PJSIP_H_MIN_EXPIRES,
  201. PJSIP_H_ORGANIZATION_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  202. PJSIP_H_PRIORITY_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  203. PJSIP_H_PROXY_AUTHENTICATE,
  204. PJSIP_H_PROXY_AUTHORIZATION,
  205. PJSIP_H_PROXY_REQUIRE_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  206. PJSIP_H_RECORD_ROUTE,
  207. PJSIP_H_REPLY_TO_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  208. PJSIP_H_REQUIRE,
  209. PJSIP_H_RETRY_AFTER,
  210. PJSIP_H_ROUTE,
  211. PJSIP_H_SERVER_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  212. PJSIP_H_SUBJECT_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  213. PJSIP_H_SUPPORTED,
  214. PJSIP_H_TIMESTAMP_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  215. PJSIP_H_TO,
  216. PJSIP_H_UNSUPPORTED,
  217. PJSIP_H_USER_AGENT_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  218. PJSIP_H_VIA,
  219. PJSIP_H_WARNING_UNIMP, /* N/A, use pjsip_generic_string_hdr */
  220. PJSIP_H_WWW_AUTHENTICATE,
  221. PJSIP_H_OTHER
  222. } pjsip_hdr_e;
  223. /**
  224. * This structure provides the pointer to basic functions that are needed
  225. * for generic header operations. All header fields will have pointer to
  226. * this structure, so that they can be manipulated uniformly.
  227. */
  228. typedef struct pjsip_hdr_vptr
  229. {
  230. /**
  231. * Function to clone the header.
  232. *
  233. * @param pool Memory pool to allocate the new header.
  234. * @param hdr Header to clone.
  235. *
  236. * @return A new instance of the header.
  237. */
  238. void *(*clone)(pj_pool_t *pool, const void *hdr);
  239. /**
  240. * Pointer to function to shallow clone the header.
  241. * Shallow cloning will just make a memory copy of the original header,
  242. * thus all pointers in original header will be kept intact. Because the
  243. * function does not need to perform deep copy, the operation should be
  244. * faster, but the application must make sure that the original header
  245. * is still valid throughout the lifetime of new header.
  246. *
  247. * @param pool Memory pool to allocate the new header.
  248. * @param hdr The header to clone.
  249. */
  250. void *(*shallow_clone)(pj_pool_t *pool, const void *hdr);
  251. /** Pointer to function to print the header to the specified buffer.
  252. * Returns the length of string written, or -1 if the remaining buffer
  253. * is not enough to hold the header.
  254. *
  255. * @param hdr The header to print.
  256. * @param buf The buffer.
  257. * @param len The size of the buffer.
  258. *
  259. * @return The size copied to buffer, or -1 if there's not enough space.
  260. */
  261. int (*print_on)(void *hdr, char *buf, pj_size_t len);
  262. } pjsip_hdr_vptr;
  263. /**
  264. * Generic fields for all SIP headers are declared using this macro, to make
  265. * sure that all headers will have exactly the same layout in their start of
  266. * the storage. This behaves like C++ inheritance actually.
  267. */
  268. #define PJSIP_DECL_HDR_MEMBER(hdr) \
  269. /** List members. */ \
  270. PJ_DECL_LIST_MEMBER(hdr); \
  271. /** Header type */ \
  272. pjsip_hdr_e type; \
  273. /** Header name. */ \
  274. pj_str_t name; \
  275. /** Header short name version. */ \
  276. pj_str_t sname; \
  277. /** Virtual function table. */ \
  278. pjsip_hdr_vptr *vptr
  279. /**
  280. * Generic SIP header structure, for generic manipulation for headers in the
  281. * message. All header fields can be typecasted to this type.
  282. */
  283. struct pjsip_hdr
  284. {
  285. PJSIP_DECL_HDR_MEMBER(struct pjsip_hdr);
  286. };
  287. /**
  288. * This generic function will clone any header, by calling "clone" function
  289. * in header's virtual function table.
  290. *
  291. * @param pool The pool to allocate memory from.
  292. * @param hdr The header to clone.
  293. *
  294. * @return A new instance copied from the original header.
  295. */
  296. PJ_DECL(void*) pjsip_hdr_clone( pj_pool_t *pool, const void *hdr );
  297. /**
  298. * This generic function will clone any header, by calling "shallow_clone"
  299. * function in header's virtual function table.
  300. *
  301. * @param pool The pool to allocate memory from.
  302. * @param hdr The header to clone.
  303. *
  304. * @return A new instance copied from the original header.
  305. */
  306. PJ_DECL(void*) pjsip_hdr_shallow_clone( pj_pool_t *pool, const void *hdr );
  307. /**
  308. * This generic function will print any header, by calling "print"
  309. * function in header's virtual function table.
  310. *
  311. * @param hdr The header to print.
  312. * @param buf The buffer.
  313. * @param len The size of the buffer.
  314. *
  315. * @return The size copied to buffer, or -1 if there's not enough space.
  316. */
  317. PJ_DECL(int) pjsip_hdr_print_on( void *hdr, char *buf, pj_size_t len);
  318. /**
  319. * Find a header in a header list by the header type.
  320. *
  321. * @param hdr_list The "head" of the header list.
  322. * @param type The header type to find.
  323. * @param start The first header field where the search should begin.
  324. * If NULL is specified, then the search will begin from the
  325. * first header, otherwise the search will begin at the
  326. * specified header.
  327. *
  328. * @return The header field, or NULL if no header with the specified
  329. * type is found.
  330. */
  331. PJ_DECL(void*) pjsip_hdr_find( const void *hdr_list,
  332. pjsip_hdr_e type,
  333. const void *start);
  334. /**
  335. * Find a header in a header list by its name.
  336. *
  337. * @param hdr_list The "head" of the header list.
  338. * @param name The header name to find.
  339. * @param start The first header field where the search should begin.
  340. * If NULL is specified, then the search will begin from the
  341. * first header, otherwise the search will begin at the
  342. * specified header.
  343. *
  344. * @return The header field, or NULL if no header with the specified
  345. * type is found.
  346. */
  347. PJ_DECL(void*) pjsip_hdr_find_by_name( const void *hdr_list,
  348. const pj_str_t *name,
  349. const void *start);
  350. /**
  351. * Find a header in a header list by its name and short name version.
  352. *
  353. * @param hdr_list The "head" of the header list.
  354. * @param name The header name to find.
  355. * @param sname The short name version of the header name.
  356. * @param start The first header field where the search should begin.
  357. * If NULL is specified, then the search will begin from the
  358. * first header, otherwise the search will begin at the
  359. * specified header.
  360. *
  361. * @return The header field, or NULL if no header with the specified
  362. * type is found.
  363. */
  364. PJ_DECL(void*) pjsip_hdr_find_by_names( const void *hdr_list,
  365. const pj_str_t *name,
  366. const pj_str_t *sname,
  367. const void *start);
  368. /**
  369. * @}
  370. */
  371. /* **************************************************************************/
  372. /**
  373. * @defgroup PJSIP_MSG_LINE Request and Status Line.
  374. * @brief Request and status line structures and manipulation.
  375. * @ingroup PJSIP_MSG
  376. * @{
  377. */
  378. /**
  379. * This structure describes SIP request line.
  380. */
  381. typedef struct pjsip_request_line
  382. {
  383. pjsip_method method; /**< Method for this request line. */
  384. pjsip_uri *uri; /**< URI for this request line. */
  385. } pjsip_request_line;
  386. /**
  387. * This structure describes SIP status line.
  388. */
  389. typedef struct pjsip_status_line
  390. {
  391. int code; /**< Status code. */
  392. pj_str_t reason; /**< Reason string. */
  393. } pjsip_status_line;
  394. /**
  395. * This enumeration lists standard SIP status codes according to RFC 3261.
  396. * In addition, it also declares new status class 7xx for errors generated
  397. * by the stack. This status class however should not get transmitted on the
  398. * wire.
  399. */
  400. typedef enum pjsip_status_code
  401. {
  402. PJSIP_SC_NULL = 0,
  403. PJSIP_SC_TRYING = 100,
  404. PJSIP_SC_RINGING = 180,
  405. PJSIP_SC_CALL_BEING_FORWARDED = 181,
  406. PJSIP_SC_QUEUED = 182,
  407. PJSIP_SC_PROGRESS = 183,
  408. PJSIP_SC_EARLY_DIALOG_TERMINATED = 199,
  409. PJSIP_SC_OK = 200,
  410. PJSIP_SC_ACCEPTED = 202,
  411. PJSIP_SC_NO_NOTIFICATION = 204,
  412. PJSIP_SC_MULTIPLE_CHOICES = 300,
  413. PJSIP_SC_MOVED_PERMANENTLY = 301,
  414. PJSIP_SC_MOVED_TEMPORARILY = 302,
  415. PJSIP_SC_USE_PROXY = 305,
  416. PJSIP_SC_ALTERNATIVE_SERVICE = 380,
  417. PJSIP_SC_BAD_REQUEST = 400,
  418. PJSIP_SC_UNAUTHORIZED = 401,
  419. PJSIP_SC_PAYMENT_REQUIRED = 402,
  420. PJSIP_SC_FORBIDDEN = 403,
  421. PJSIP_SC_NOT_FOUND = 404,
  422. PJSIP_SC_METHOD_NOT_ALLOWED = 405,
  423. PJSIP_SC_NOT_ACCEPTABLE = 406,
  424. PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED = 407,
  425. PJSIP_SC_REQUEST_TIMEOUT = 408,
  426. PJSIP_SC_CONFLICT = 409,
  427. PJSIP_SC_GONE = 410,
  428. PJSIP_SC_LENGTH_REQUIRED = 411,
  429. PJSIP_SC_CONDITIONAL_REQUEST_FAILED = 412,
  430. PJSIP_SC_REQUEST_ENTITY_TOO_LARGE = 413,
  431. PJSIP_SC_REQUEST_URI_TOO_LONG = 414,
  432. PJSIP_SC_UNSUPPORTED_MEDIA_TYPE = 415,
  433. PJSIP_SC_UNSUPPORTED_URI_SCHEME = 416,
  434. PJSIP_SC_UNKNOWN_RESOURCE_PRIORITY = 417,
  435. PJSIP_SC_BAD_EXTENSION = 420,
  436. PJSIP_SC_EXTENSION_REQUIRED = 421,
  437. PJSIP_SC_SESSION_TIMER_TOO_SMALL = 422,
  438. PJSIP_SC_INTERVAL_TOO_BRIEF = 423,
  439. PJSIP_SC_BAD_LOCATION_INFORMATION = 424,
  440. PJSIP_SC_USE_IDENTITY_HEADER = 428,
  441. PJSIP_SC_PROVIDE_REFERRER_HEADER = 429,
  442. PJSIP_SC_FLOW_FAILED = 430,
  443. PJSIP_SC_ANONIMITY_DISALLOWED = 433,
  444. PJSIP_SC_BAD_IDENTITY_INFO = 436,
  445. PJSIP_SC_UNSUPPORTED_CERTIFICATE = 437,
  446. PJSIP_SC_INVALID_IDENTITY_HEADER = 438,
  447. PJSIP_SC_FIRST_HOP_LACKS_OUTBOUND_SUPPORT = 439,
  448. PJSIP_SC_MAX_BREADTH_EXCEEDED = 440,
  449. PJSIP_SC_BAD_INFO_PACKAGE = 469,
  450. PJSIP_SC_CONSENT_NEEDED = 470,
  451. PJSIP_SC_TEMPORARILY_UNAVAILABLE = 480,
  452. PJSIP_SC_CALL_TSX_DOES_NOT_EXIST = 481,
  453. PJSIP_SC_LOOP_DETECTED = 482,
  454. PJSIP_SC_TOO_MANY_HOPS = 483,
  455. PJSIP_SC_ADDRESS_INCOMPLETE = 484,
  456. PJSIP_AC_AMBIGUOUS = 485,
  457. PJSIP_SC_BUSY_HERE = 486,
  458. PJSIP_SC_REQUEST_TERMINATED = 487,
  459. PJSIP_SC_NOT_ACCEPTABLE_HERE = 488,
  460. PJSIP_SC_BAD_EVENT = 489,
  461. PJSIP_SC_REQUEST_UPDATED = 490,
  462. PJSIP_SC_REQUEST_PENDING = 491,
  463. PJSIP_SC_UNDECIPHERABLE = 493,
  464. PJSIP_SC_SECURITY_AGREEMENT_NEEDED = 494,
  465. PJSIP_SC_INTERNAL_SERVER_ERROR = 500,
  466. PJSIP_SC_NOT_IMPLEMENTED = 501,
  467. PJSIP_SC_BAD_GATEWAY = 502,
  468. PJSIP_SC_SERVICE_UNAVAILABLE = 503,
  469. PJSIP_SC_SERVER_TIMEOUT = 504,
  470. PJSIP_SC_VERSION_NOT_SUPPORTED = 505,
  471. PJSIP_SC_MESSAGE_TOO_LARGE = 513,
  472. PJSIP_SC_PUSH_NOTIFICATION_SERVICE_NOT_SUPPORTED = 555,
  473. PJSIP_SC_PRECONDITION_FAILURE = 580,
  474. PJSIP_SC_BUSY_EVERYWHERE = 600,
  475. PJSIP_SC_DECLINE = 603,
  476. PJSIP_SC_DOES_NOT_EXIST_ANYWHERE = 604,
  477. PJSIP_SC_NOT_ACCEPTABLE_ANYWHERE = 606,
  478. PJSIP_SC_UNWANTED = 607,
  479. PJSIP_SC_REJECTED = 608,
  480. PJSIP_SC_TSX_TIMEOUT = PJSIP_SC_REQUEST_TIMEOUT,
  481. /*PJSIP_SC_TSX_RESOLVE_ERROR = 702,*/
  482. PJSIP_SC_TSX_TRANSPORT_ERROR = PJSIP_SC_SERVICE_UNAVAILABLE,
  483. /* This is not an actual status code, but rather a constant
  484. * to force GCC to use 32bit to represent this enum, since
  485. * we have a code in PJSUA-LIB that assigns an integer
  486. * to this enum (see pjsua_acc_get_info() function).
  487. */
  488. PJSIP_SC__force_32bit = 0x7FFFFFFF
  489. } pjsip_status_code;
  490. /**
  491. * Get the default status text for the status code.
  492. *
  493. * @param status_code SIP Status Code
  494. *
  495. * @return textual message for the status code.
  496. */
  497. PJ_DECL(const pj_str_t*) pjsip_get_status_text(int status_code);
  498. /**
  499. * This macro returns non-zero (TRUE) if the specified status_code is
  500. * in the same class as the code_class.
  501. *
  502. * @param status_code The status code.
  503. * @param code_class The status code in the class (for example 100, 200).
  504. */
  505. #define PJSIP_IS_STATUS_IN_CLASS(status_code, code_class) \
  506. (status_code/100 == code_class/100)
  507. /**
  508. * @}
  509. */
  510. /* **************************************************************************/
  511. /**
  512. * @addtogroup PJSIP_MSG_MEDIA Media/MIME Type
  513. * @brief Media/MIME type declaration and manipulations.
  514. * @ingroup PJSIP_MSG
  515. * @{
  516. */
  517. /**
  518. * This structure describes SIP media type, as used for example in
  519. * Accept and Content-Type header..
  520. */
  521. typedef struct pjsip_media_type
  522. {
  523. pj_str_t type; /**< Media type. */
  524. pj_str_t subtype; /**< Media subtype. */
  525. pjsip_param param; /**< Media type parameters */
  526. } pjsip_media_type;
  527. /**
  528. * Initialize the media type with the specified type and subtype string.
  529. *
  530. * @param mt The media type.
  531. * @param type Optionally specify the media type.
  532. * @param subtype Optionally specify the media subtype.
  533. */
  534. PJ_DECL(void) pjsip_media_type_init(pjsip_media_type *mt,
  535. pj_str_t *type,
  536. pj_str_t *subtype);
  537. /**
  538. * Initialize the media type with the specified type and subtype string.
  539. *
  540. * @param mt The media type.
  541. * @param type Optionally specify the media type.
  542. * @param subtype Optionally specify the media subtype.
  543. */
  544. PJ_DECL(void) pjsip_media_type_init2(pjsip_media_type *mt,
  545. char *type,
  546. char *subtype);
  547. /**
  548. * Compare two media types.
  549. *
  550. * @param mt1 The first media type.
  551. * @param mt2 The second media type.
  552. * @param cmp_param Specify how to compare the media type parameters:
  553. * - 0: do not compare parameters
  554. * - 1: compare parameters but ignore parameters that
  555. * only appear in one of the media type.
  556. * - 2: compare the parameters.
  557. *
  558. * @return Zero if both media types are equal, -1 if mt1 < mt2,
  559. * 1 if mt1 > mt2.
  560. */
  561. PJ_DECL(int) pjsip_media_type_cmp(const pjsip_media_type *mt1,
  562. const pjsip_media_type *mt2,
  563. int cmp_param);
  564. /**
  565. * Copy SIP media type to another.
  566. *
  567. * @param pool Pool to duplicate strings.
  568. * @param dst Destination structure.
  569. * @param src Source structure.
  570. */
  571. PJ_DECL(void) pjsip_media_type_cp(pj_pool_t *pool,
  572. pjsip_media_type *dst,
  573. const pjsip_media_type *src);
  574. /**
  575. * Print media type to the specified buffer.
  576. *
  577. * @param buf Destination buffer.
  578. * @param len Length of the buffer.
  579. * @param mt The media type to be printed.
  580. *
  581. * @return The number of characters printed to the buffer, or -1
  582. * if there's not enough space in the buffer.
  583. */
  584. PJ_DECL(int) pjsip_media_type_print(char *buf, unsigned len,
  585. const pjsip_media_type *mt);
  586. /**
  587. * @}
  588. */
  589. /* **************************************************************************/
  590. /**
  591. * @addtogroup PJSIP_MSG_BODY Message Body
  592. * @brief SIP message body structures and manipulation.
  593. * @ingroup PJSIP_MSG
  594. * @{
  595. */
  596. /**
  597. * Generic abstraction to message body.
  598. * When an incoming message is parsed (pjsip_parse_msg()), the parser fills in
  599. * all members with the appropriate value. The 'data' and 'len' member will
  600. * describe portion of incoming packet which denotes the message body.
  601. * When application needs to attach message body to outgoing SIP message, it
  602. * must fill in all members of this structure.
  603. */
  604. struct pjsip_msg_body
  605. {
  606. /** MIME content type.
  607. * For incoming messages, the parser will fill in this member with the
  608. * content type found in Content-Type header.
  609. *
  610. * For outgoing messages, application may fill in this member with
  611. * appropriate value, because the stack will generate Content-Type header
  612. * based on the value specified here.
  613. *
  614. * If the content_type is empty, no Content-Type AND Content-Length header
  615. * will be added to the message. The stack assumes that application adds
  616. * these headers themselves.
  617. */
  618. pjsip_media_type content_type;
  619. /** Pointer to buffer which holds the message body data.
  620. * For incoming messages, the parser will fill in this member with the
  621. * pointer to the body string.
  622. *
  623. * When sending outgoing message, this member doesn't need to point to the
  624. * actual message body string. It can be assigned with arbitrary pointer,
  625. * because the value will only need to be understood by the print_body()
  626. * function. The stack itself will not try to interpret this value, but
  627. * instead will always call the print_body() whenever it needs to get the
  628. * actual body string.
  629. */
  630. void *data;
  631. /** The length of the data.
  632. * For incoming messages, the parser will fill in this member with the
  633. * actual length of message body.
  634. *
  635. * When sending outgoing message, again just like the "data" member, the
  636. * "len" member doesn't need to point to the actual length of the body
  637. * string.
  638. */
  639. unsigned len;
  640. /** Pointer to function to print this message body.
  641. * Application must set a proper function here when sending outgoing
  642. * message.
  643. *
  644. * @param msg_body This structure itself.
  645. * @param buf The buffer.
  646. * @param size The buffer size.
  647. *
  648. * @return The length of the string printed, or -1 if there is
  649. * not enough space in the buffer to print the whole
  650. * message body.
  651. */
  652. int (*print_body)(struct pjsip_msg_body *msg_body,
  653. char *buf, pj_size_t size);
  654. /** Clone the data part only of this message body. Note that this only
  655. * duplicates the data part of the body instead of the whole message
  656. * body. If application wants to duplicate the entire message body
  657. * structure, it must call #pjsip_msg_body_clone().
  658. *
  659. * @param pool Pool used to clone the data.
  660. * @param data The data inside message body, to be cloned.
  661. * @param len The length of the data.
  662. *
  663. * @return New data duplicated from the original data.
  664. */
  665. void* (*clone_data)(pj_pool_t *pool, const void *data, unsigned len);
  666. };
  667. /**
  668. * General purpose function to textual data in a SIP body. Attach this function
  669. * in a SIP message body only if the data in pjsip_msg_body is a textual
  670. * message ready to be embedded in a SIP message. If the data in the message
  671. * body is not a textual body, then application must supply a custom function
  672. * to print that body.
  673. *
  674. * @param msg_body The message body.
  675. * @param buf Buffer to copy the message body to.
  676. * @param size The size of the buffer.
  677. *
  678. * @return The length copied to the buffer, or -1.
  679. */
  680. PJ_DECL(int) pjsip_print_text_body( pjsip_msg_body *msg_body,
  681. char *buf, pj_size_t size);
  682. /**
  683. * General purpose function to clone textual data in a SIP body. Attach this
  684. * function as "clone_data" member of the SIP body only if the data type
  685. * is a text (i.e. C string, not pj_str_t), and the length indicates the
  686. * length of the text.
  687. *
  688. * @param pool Pool used to clone the data.
  689. * @param data Textual data.
  690. * @param len The length of the string.
  691. *
  692. * @return New text duplicated from the original text.
  693. */
  694. PJ_DECL(void*) pjsip_clone_text_data( pj_pool_t *pool, const void *data,
  695. unsigned len);
  696. /**
  697. * Clone the message body in src_body to the dst_body. This will duplicate
  698. * the contents of the message body using the \a clone_data member of the
  699. * source message body.
  700. *
  701. * @param pool Pool to use to duplicate the message body.
  702. * @param dst_body Destination message body.
  703. * @param src_body Source message body to duplicate.
  704. *
  705. * @return PJ_SUCCESS on success.
  706. */
  707. PJ_DECL(pj_status_t) pjsip_msg_body_copy( pj_pool_t *pool,
  708. pjsip_msg_body *dst_body,
  709. const pjsip_msg_body *src_body );
  710. /**
  711. * Create cloned message body. This will duplicate the contents of the message
  712. * body using the \a clone_data member of the source message body.
  713. *
  714. * @param pool Pool to use to duplicate the message body.
  715. * @param body Source message body to duplicate.
  716. *
  717. * @return The cloned message body on successfull.
  718. */
  719. PJ_DECL(pjsip_msg_body*) pjsip_msg_body_clone( pj_pool_t *pool,
  720. const pjsip_msg_body *body );
  721. /**
  722. * Create a text message body. Use this function to create message body when
  723. * the content is a simple text. For non-text message body (e.g.
  724. * pjmedia_sdp_session or pj_xml_node), application must construct the message
  725. * manually.
  726. *
  727. * @param pool Pool to allocate message body and its contents.
  728. * @param type MIME type (e.g. "text").
  729. * @param subtype MIME subtype (e.g. "plain").
  730. * @param text The text content to be put in the message body.
  731. *
  732. * @return A new message body with the specified Content-Type and
  733. * text.
  734. */
  735. PJ_DECL(pjsip_msg_body*) pjsip_msg_body_create( pj_pool_t *pool,
  736. const pj_str_t *type,
  737. const pj_str_t *subtype,
  738. const pj_str_t *text );
  739. /**
  740. * @}
  741. */
  742. /* **************************************************************************/
  743. /**
  744. * @defgroup PJSIP_MSG_MSG Message Structure
  745. * @brief SIP message (request and response) structure and operations.
  746. * @ingroup PJSIP_MSG
  747. * @{
  748. */
  749. /**
  750. * Message type (request or response).
  751. */
  752. typedef enum pjsip_msg_type_e
  753. {
  754. PJSIP_REQUEST_MSG, /**< Indicates request message. */
  755. PJSIP_RESPONSE_MSG /**< Indicates response message. */
  756. } pjsip_msg_type_e;
  757. /**
  758. * This structure describes a SIP message.
  759. */
  760. struct pjsip_msg
  761. {
  762. /** Message type (ie request or response). */
  763. pjsip_msg_type_e type;
  764. /** The first line of the message can be either request line for request
  765. * messages, or status line for response messages. It is represented here
  766. * as a union.
  767. */
  768. union
  769. {
  770. /** Request Line. */
  771. struct pjsip_request_line req;
  772. /** Status Line. */
  773. struct pjsip_status_line status;
  774. } line;
  775. /** List of message headers. */
  776. pjsip_hdr hdr;
  777. /** Pointer to message body, or NULL if no message body is attached to
  778. * this mesage.
  779. */
  780. pjsip_msg_body *body;
  781. };
  782. /**
  783. * Create new request or response message.
  784. *
  785. * @param pool The pool.
  786. * @param type Message type.
  787. * @return New message, or THROW exception if failed.
  788. */
  789. PJ_DECL(pjsip_msg*) pjsip_msg_create( pj_pool_t *pool, pjsip_msg_type_e type);
  790. /**
  791. * Perform a deep clone of a SIP message.
  792. *
  793. * @param pool The pool for creating the new message.
  794. * @param msg The message to be duplicated.
  795. *
  796. * @return New message, which is duplicated from the original
  797. * message.
  798. */
  799. PJ_DECL(pjsip_msg*) pjsip_msg_clone( pj_pool_t *pool, const pjsip_msg *msg);
  800. /**
  801. * Find a header in the message by the header type.
  802. *
  803. * @param msg The message.
  804. * @param type The header type to find.
  805. * @param start The first header field where the search should begin.
  806. * If NULL is specified, then the search will begin from the
  807. * first header, otherwise the search will begin at the
  808. * specified header.
  809. *
  810. * @return The header field, or NULL if no header with the specified
  811. * type is found.
  812. */
  813. PJ_DECL(void*) pjsip_msg_find_hdr( const pjsip_msg *msg,
  814. pjsip_hdr_e type, const void *start);
  815. /**
  816. * Find a header in the message by its name.
  817. *
  818. * @param msg The message.
  819. * @param name The header name to find.
  820. * @param start The first header field where the search should begin.
  821. * If NULL is specified, then the search will begin from the
  822. * first header, otherwise the search will begin at the
  823. * specified header.
  824. *
  825. * @return The header field, or NULL if no header with the specified
  826. * type is found.
  827. */
  828. PJ_DECL(void*) pjsip_msg_find_hdr_by_name( const pjsip_msg *msg,
  829. const pj_str_t *name,
  830. const void *start);
  831. /**
  832. * Find a header in the message by its name and short name version.
  833. *
  834. * @param msg The message.
  835. * @param name The header name to find.
  836. * @param sname The short name version of the header name.
  837. * @param start The first header field where the search should begin.
  838. * If NULL is specified, then the search will begin from the
  839. * first header, otherwise the search will begin at the
  840. * specified header.
  841. *
  842. * @return The header field, or NULL if no header with the specified
  843. * type is found.
  844. */
  845. PJ_DECL(void*) pjsip_msg_find_hdr_by_names(const pjsip_msg *msg,
  846. const pj_str_t *name,
  847. const pj_str_t *sname,
  848. const void *start);
  849. /**
  850. * Find and remove a header in the message.
  851. *
  852. * @param msg The message.
  853. * @param hdr The header type to find.
  854. * @param start The first header field where the search should begin,
  855. * or NULL to search from the first header in the message.
  856. *
  857. * @return The header field, or NULL if not found.
  858. */
  859. PJ_DECL(void*) pjsip_msg_find_remove_hdr( pjsip_msg *msg,
  860. pjsip_hdr_e hdr, void *start);
  861. /**
  862. * Add a header to the message, putting it last in the header list.
  863. *
  864. * @param msg The message.
  865. * @param hdr The header to add.
  866. *
  867. * @bug Once the header is put in a list (or message), it can not be put in
  868. * other list (or message). Otherwise Real Bad Thing will happen.
  869. */
  870. PJ_INLINE(void) pjsip_msg_add_hdr( pjsip_msg *msg, pjsip_hdr *hdr )
  871. {
  872. pj_list_insert_before(&msg->hdr, hdr);
  873. }
  874. /**
  875. * Add header field to the message, putting it in the front of the header list.
  876. *
  877. * @param msg The message.
  878. * @param hdr The header to add.
  879. *
  880. * @bug Once the header is put in a list (or message), it can not be put in
  881. * other list (or message). Otherwise Real Bad Thing will happen.
  882. */
  883. PJ_INLINE(void) pjsip_msg_insert_first_hdr( pjsip_msg *msg, pjsip_hdr *hdr )
  884. {
  885. pj_list_insert_after(&msg->hdr, hdr);
  886. }
  887. /**
  888. * Print the message to the specified buffer.
  889. *
  890. * @param msg The message to print.
  891. * @param buf The buffer
  892. * @param size The size of the buffer.
  893. *
  894. * @return The length of the printed characters (in bytes), or NEGATIVE
  895. * value if the message is too large for the specified buffer.
  896. */
  897. PJ_DECL(pj_ssize_t) pjsip_msg_print(const pjsip_msg *msg,
  898. char *buf, pj_size_t size);
  899. /*
  900. * Some usefull macros to find common headers.
  901. */
  902. /**
  903. * Find Call-ID header.
  904. *
  905. * @param msg The message.
  906. * @return Call-ID header instance.
  907. */
  908. #define PJSIP_MSG_CID_HDR(msg) \
  909. ((pjsip_cid_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_CALL_ID, NULL))
  910. /**
  911. * Find CSeq header.
  912. *
  913. * @param msg The message.
  914. * @return CSeq header instance.
  915. */
  916. #define PJSIP_MSG_CSEQ_HDR(msg) \
  917. ((pjsip_cseq_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_CSEQ, NULL))
  918. /**
  919. * Find From header.
  920. *
  921. * @param msg The message.
  922. * @return From header instance.
  923. */
  924. #define PJSIP_MSG_FROM_HDR(msg) \
  925. ((pjsip_from_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_FROM, NULL))
  926. /**
  927. * Find To header.
  928. *
  929. * @param msg The message.
  930. * @return To header instance.
  931. */
  932. #define PJSIP_MSG_TO_HDR(msg) \
  933. ((pjsip_to_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_TO, NULL))
  934. /**
  935. * @}
  936. */
  937. /* **************************************************************************/
  938. /**
  939. * @addtogroup PJSIP_MSG_HDR
  940. * @{
  941. */
  942. /**
  943. * Generic SIP header, which contains hname and a string hvalue.
  944. * Note that this header is not supposed to be used as 'base' class for headers.
  945. */
  946. typedef struct pjsip_generic_string_hdr
  947. {
  948. /** Standard header field. */
  949. PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_string_hdr);
  950. /** hvalue */
  951. pj_str_t hvalue;
  952. } pjsip_generic_string_hdr;
  953. /**
  954. * Create a new instance of generic header. A generic header can have an
  955. * arbitrary header name.
  956. *
  957. * @param pool The pool.
  958. * @param hname The header name to be assigned to the header, or NULL to
  959. * assign the header name with some string.
  960. * @param hvalue Optional string to be assigned as the value.
  961. *
  962. * @return The header, or THROW exception.
  963. */
  964. PJ_DECL(pjsip_generic_string_hdr*)
  965. pjsip_generic_string_hdr_create( pj_pool_t *pool,
  966. const pj_str_t *hname,
  967. const pj_str_t *hvalue);
  968. /**
  969. * Initialize a preallocated memory with the header structure. This function
  970. * should only be called when application uses its own memory allocation to
  971. * allocate memory block for the specified header (e.g. in C++, when the
  972. * header is allocated with "new" operator).
  973. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  974. * which allocates memory and initialize it in one go.
  975. *
  976. * @param pool Pool for additional memory allocation if required.
  977. * @param mem Pre-allocated memory to be initialized as the header.
  978. * @param hname The header name to be assigned to the header, or NULL to
  979. * assign the header name with some string later.
  980. * @param hvalue Optional string to be assigned as the value.
  981. *
  982. * @return The header instance, which points to the same memory
  983. * location as the mem argument.
  984. */
  985. PJ_DECL(pjsip_generic_string_hdr*)
  986. pjsip_generic_string_hdr_init( pj_pool_t *pool,
  987. void *mem,
  988. const pj_str_t *hname,
  989. const pj_str_t *hvalue);
  990. /**
  991. * Construct a generic string header without allocating memory from the pool.
  992. * This function is useful to create a temporary header which life-time is
  993. * very short (for example, creating the header in the stack to be passed
  994. * as argument to a function which will copy the header).
  995. *
  996. * @param h The header to be initialized.
  997. * @param hname The header name to be assigned to the header, or NULL to
  998. * assign the header name with some string.
  999. * @param hvalue Optional string to be assigned as the value.
  1000. *
  1001. */
  1002. PJ_DECL(void) pjsip_generic_string_hdr_init2(pjsip_generic_string_hdr *h,
  1003. pj_str_t *hname,
  1004. pj_str_t *hvalue);
  1005. /* **************************************************************************/
  1006. /**
  1007. * Generic SIP header, which contains hname and an integer ivalue.
  1008. */
  1009. typedef struct pjsip_generic_int_hdr
  1010. {
  1011. /** Standard header field. */
  1012. PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_int_hdr);
  1013. /** ivalue */
  1014. pj_uint32_t ivalue;
  1015. } pjsip_generic_int_hdr;
  1016. /**
  1017. * Create a new instance of generic header. A generic header can have an
  1018. * arbitrary header name.
  1019. *
  1020. * @param pool The pool.
  1021. * @param hname The header name to be assigned to the header, or NULL to
  1022. * assign the header name with some string.
  1023. * @param hvalue The value to be assigned to the header.
  1024. *
  1025. * @return The header, or THROW exception.
  1026. */
  1027. PJ_DECL(pjsip_generic_int_hdr*) pjsip_generic_int_hdr_create( pj_pool_t *pool,
  1028. const pj_str_t *hname,
  1029. unsigned hvalue );
  1030. /**
  1031. * Initialize a preallocated memory with the header structure. This function
  1032. * should only be called when application uses its own memory allocation to
  1033. * allocate memory block for the specified header (e.g. in C++, when the
  1034. * header is allocated with "new" operator).
  1035. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1036. * which allocates memory and initialize it in one go.
  1037. *
  1038. * @param pool Pool for additional memory allocation if required.
  1039. * @param mem Pre-allocated memory to be initialized as the header.
  1040. * @param hname The header name to be assigned to the header, or NULL to
  1041. * assign the header name with some string later.
  1042. * @param value Value to be assigned to the header.
  1043. *
  1044. * @return The header instance, which points to the same memory
  1045. * location as the mem argument.
  1046. */
  1047. PJ_DECL(pjsip_generic_int_hdr*) pjsip_generic_int_hdr_init( pj_pool_t *pool,
  1048. void *mem,
  1049. const pj_str_t *hname,
  1050. unsigned value );
  1051. /* **************************************************************************/
  1052. /** Maximum elements in the header array. */
  1053. #define PJSIP_GENERIC_ARRAY_MAX_COUNT 32
  1054. /**
  1055. * Generic array of string header.
  1056. */
  1057. typedef struct pjsip_generic_array_hdr
  1058. {
  1059. /** Standard header fields. */
  1060. PJSIP_DECL_HDR_MEMBER(struct pjsip_generic_array_hdr);
  1061. /** Number of tags/elements. */
  1062. unsigned count;
  1063. /** Tags/elements. */
  1064. pj_str_t values[PJSIP_GENERIC_ARRAY_MAX_COUNT];
  1065. } pjsip_generic_array_hdr;
  1066. /**
  1067. * Create generic array header.
  1068. *
  1069. * @param pool Pool to allocate memory from.
  1070. * @param hname Header name.
  1071. *
  1072. * @return New generic array header.
  1073. */
  1074. PJ_DECL(pjsip_generic_array_hdr*) pjsip_generic_array_hdr_create(pj_pool_t *pool,
  1075. const pj_str_t *hname);
  1076. /**
  1077. * Initialize a preallocated memory with the header structure. This function
  1078. * should only be called when application uses its own memory allocation to
  1079. * allocate memory block for the specified header (e.g. in C++, when the
  1080. * header is allocated with "new" operator).
  1081. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1082. * which allocates memory and initialize it in one go.
  1083. *
  1084. * @param pool Pool for additional memory allocation if required.
  1085. * @param mem Pre-allocated memory to be initialized as the header.
  1086. * @param hname The header name to be assigned to the header, or NULL to
  1087. * assign the header name with some string later.
  1088. *
  1089. * @return The header instance, which points to the same memory
  1090. * location as the mem argument.
  1091. */
  1092. PJ_DECL(pjsip_generic_array_hdr*) pjsip_generic_array_hdr_init(pj_pool_t *pool,
  1093. void *mem,
  1094. const pj_str_t *hname);
  1095. /* **************************************************************************/
  1096. /** Accept header. */
  1097. typedef pjsip_generic_array_hdr pjsip_accept_hdr;
  1098. /** Maximum fields in Accept header. */
  1099. #define PJSIP_MAX_ACCEPT_COUNT PJSIP_GENERIC_ARRAY_MAX_COUNT
  1100. /**
  1101. * Create new Accept header instance.
  1102. *
  1103. * @param pool The pool.
  1104. *
  1105. * @return New Accept header instance.
  1106. */
  1107. PJ_DECL(pjsip_accept_hdr*) pjsip_accept_hdr_create(pj_pool_t *pool);
  1108. /**
  1109. * Initialize a preallocated memory with the header structure. This function
  1110. * should only be called when application uses its own memory allocation to
  1111. * allocate memory block for the specified header (e.g. in C++, when the
  1112. * header is allocated with "new" operator).
  1113. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1114. * which allocates memory and initialize it in one go.
  1115. *
  1116. * @param pool Pool for additional memory allocation if required.
  1117. * @param mem Pre-allocated memory to be initialized as the header.
  1118. *
  1119. * @return The header instance, which points to the same memory
  1120. * location as the mem argument.
  1121. */
  1122. PJ_DECL(pjsip_accept_hdr*) pjsip_accept_hdr_init( pj_pool_t *pool,
  1123. void *mem );
  1124. /* **************************************************************************/
  1125. /**
  1126. * Allow header.
  1127. */
  1128. typedef pjsip_generic_array_hdr pjsip_allow_hdr;
  1129. /**
  1130. * Create new Allow header instance.
  1131. *
  1132. * @param pool The pool.
  1133. *
  1134. * @return New Allow header instance.
  1135. */
  1136. PJ_DECL(pjsip_allow_hdr*) pjsip_allow_hdr_create(pj_pool_t *pool);
  1137. /**
  1138. * Initialize a preallocated memory with the header structure. This function
  1139. * should only be called when application uses its own memory allocation to
  1140. * allocate memory block for the specified header (e.g. in C++, when the
  1141. * header is allocated with "new" operator).
  1142. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1143. * which allocates memory and initialize it in one go.
  1144. *
  1145. * @param pool Pool for additional memory allocation if required.
  1146. * @param mem Pre-allocated memory to be initialized as the header.
  1147. *
  1148. * @return The header instance, which points to the same memory
  1149. * location as the mem argument.
  1150. */
  1151. PJ_DECL(pjsip_allow_hdr*) pjsip_allow_hdr_init( pj_pool_t *pool,
  1152. void *mem );
  1153. /* **************************************************************************/
  1154. /**
  1155. * Call-ID header.
  1156. */
  1157. typedef struct pjsip_cid_hdr
  1158. {
  1159. PJSIP_DECL_HDR_MEMBER(struct pjsip_cid_hdr);
  1160. pj_str_t id; /**< Call-ID string. */
  1161. } pjsip_cid_hdr;
  1162. /**
  1163. * Create new Call-ID header.
  1164. *
  1165. * @param pool The pool.
  1166. *
  1167. * @return new Call-ID header.
  1168. */
  1169. PJ_DECL(pjsip_cid_hdr*) pjsip_cid_hdr_create( pj_pool_t *pool );
  1170. /**
  1171. * Initialize a preallocated memory with the header structure. This function
  1172. * should only be called when application uses its own memory allocation to
  1173. * allocate memory block for the specified header (e.g. in C++, when the
  1174. * header is allocated with "new" operator).
  1175. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1176. * which allocates memory and initialize it in one go.
  1177. *
  1178. * @param pool Pool for additional memory allocation if required.
  1179. * @param mem Pre-allocated memory to be initialized as the header.
  1180. *
  1181. * @return The header instance, which points to the same memory
  1182. * location as the mem argument.
  1183. */
  1184. PJ_DECL(pjsip_cid_hdr*) pjsip_cid_hdr_init( pj_pool_t *pool,
  1185. void *mem );
  1186. /* **************************************************************************/
  1187. /**
  1188. * Content-Length header.
  1189. */
  1190. typedef struct pjsip_clen_hdr
  1191. {
  1192. PJSIP_DECL_HDR_MEMBER(struct pjsip_clen_hdr);
  1193. int len; /**< Content length. */
  1194. } pjsip_clen_hdr;
  1195. /**
  1196. * Create new Content-Length header.
  1197. *
  1198. * @param pool the pool.
  1199. * @return A new Content-Length header instance.
  1200. */
  1201. PJ_DECL(pjsip_clen_hdr*) pjsip_clen_hdr_create( pj_pool_t *pool );
  1202. /**
  1203. * Initialize a preallocated memory with the header structure. This function
  1204. * should only be called when application uses its own memory allocation to
  1205. * allocate memory block for the specified header (e.g. in C++, when the
  1206. * header is allocated with "new" operator).
  1207. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1208. * which allocates memory and initialize it in one go.
  1209. *
  1210. * @param pool Pool for additional memory allocation if required.
  1211. * @param mem Pre-allocated memory to be initialized as the header.
  1212. *
  1213. * @return The header instance, which points to the same memory
  1214. * location as the mem argument.
  1215. */
  1216. PJ_DECL(pjsip_clen_hdr*) pjsip_clen_hdr_init( pj_pool_t *pool,
  1217. void *mem );
  1218. /* **************************************************************************/
  1219. /**
  1220. * CSeq header.
  1221. */
  1222. typedef struct pjsip_cseq_hdr
  1223. {
  1224. PJSIP_DECL_HDR_MEMBER(struct pjsip_cseq_hdr);
  1225. pj_int32_t cseq; /**< CSeq number. */
  1226. pjsip_method method; /**< CSeq method. */
  1227. } pjsip_cseq_hdr;
  1228. /** Create new CSeq header.
  1229. *
  1230. * @param pool The pool.
  1231. * @return A new CSeq header instance.
  1232. */
  1233. PJ_DECL(pjsip_cseq_hdr*) pjsip_cseq_hdr_create( pj_pool_t *pool );
  1234. /**
  1235. * Initialize a preallocated memory with the header structure. This function
  1236. * should only be called when application uses its own memory allocation to
  1237. * allocate memory block for the specified header (e.g. in C++, when the
  1238. * header is allocated with "new" operator).
  1239. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1240. * which allocates memory and initialize it in one go.
  1241. *
  1242. * @param pool Pool for additional memory allocation if required.
  1243. * @param mem Pre-allocated memory to be initialized as the header.
  1244. *
  1245. * @return The header instance, which points to the same memory
  1246. * location as the mem argument.
  1247. */
  1248. PJ_DECL(pjsip_cseq_hdr*) pjsip_cseq_hdr_init( pj_pool_t *pool,
  1249. void *mem );
  1250. /* **************************************************************************/
  1251. /** Expires not specified. */
  1252. #define PJSIP_EXPIRES_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
  1253. /**
  1254. * Contact header.
  1255. * In this library, contact header only contains single URI. If a message has
  1256. * multiple URI in the Contact header, the URI will be put in separate Contact
  1257. * headers.
  1258. */
  1259. typedef struct pjsip_contact_hdr
  1260. {
  1261. PJSIP_DECL_HDR_MEMBER(struct pjsip_contact_hdr);
  1262. int star; /**< The contact contains only a '*'
  1263. character */
  1264. pjsip_uri *uri; /**< URI in the contact. */
  1265. int q1000; /**< The "q" value times 1000
  1266. (to avoid float) */
  1267. pj_uint32_t expires; /**< Expires parameter, otherwise
  1268. PJSIP_EXPIRES_NOT_SPECIFIED
  1269. if not present. */
  1270. pjsip_param other_param; /**< Other parameters, concatenated in
  1271. a single string. */
  1272. } pjsip_contact_hdr;
  1273. /**
  1274. * Create a new Contact header.
  1275. *
  1276. * @param pool The pool.
  1277. * @return A new instance of Contact header.
  1278. */
  1279. PJ_DECL(pjsip_contact_hdr*) pjsip_contact_hdr_create( pj_pool_t *pool );
  1280. /**
  1281. * Initialize a preallocated memory with the header structure. This function
  1282. * should only be called when application uses its own memory allocation to
  1283. * allocate memory block for the specified header (e.g. in C++, when the
  1284. * header is allocated with "new" operator).
  1285. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1286. * which allocates memory and initialize it in one go.
  1287. *
  1288. * @param pool Pool for additional memory allocation if required.
  1289. * @param mem Pre-allocated memory to be initialized as the header.
  1290. *
  1291. * @return The header instance, which points to the same memory
  1292. * location as the mem argument.
  1293. */
  1294. PJ_DECL(pjsip_contact_hdr*) pjsip_contact_hdr_init( pj_pool_t *pool,
  1295. void *mem );
  1296. /* **************************************************************************/
  1297. /**
  1298. * Content-Type.
  1299. */
  1300. typedef struct pjsip_ctype_hdr
  1301. {
  1302. PJSIP_DECL_HDR_MEMBER(struct pjsip_ctype_hdr);
  1303. pjsip_media_type media; /**< Media type. */
  1304. } pjsip_ctype_hdr;
  1305. /**
  1306. * Create a nwe Content Type header.
  1307. *
  1308. * @param pool The pool.
  1309. * @return A new Content-Type header.
  1310. */
  1311. PJ_DECL(pjsip_ctype_hdr*) pjsip_ctype_hdr_create( pj_pool_t *pool );
  1312. /**
  1313. * Initialize a preallocated memory with the header structure. This function
  1314. * should only be called when application uses its own memory allocation to
  1315. * allocate memory block for the specified header (e.g. in C++, when the
  1316. * header is allocated with "new" operator).
  1317. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1318. * which allocates memory and initialize it in one go.
  1319. *
  1320. * @param pool Pool for additional memory allocation if required.
  1321. * @param mem Pre-allocated memory to be initialized as the header.
  1322. *
  1323. * @return The header instance, which points to the same memory
  1324. * location as the mem argument.
  1325. */
  1326. PJ_DECL(pjsip_ctype_hdr*) pjsip_ctype_hdr_init( pj_pool_t *pool,
  1327. void *mem );
  1328. /* **************************************************************************/
  1329. /** Expires header. */
  1330. typedef pjsip_generic_int_hdr pjsip_expires_hdr;
  1331. /**
  1332. * Create a new Expires header.
  1333. *
  1334. * @param pool The pool.
  1335. * @param value The expiration value.
  1336. *
  1337. * @return A new Expires header.
  1338. */
  1339. PJ_DECL(pjsip_expires_hdr*) pjsip_expires_hdr_create( pj_pool_t *pool,
  1340. unsigned value);
  1341. /**
  1342. * Initialize a preallocated memory with the header structure. This function
  1343. * should only be called when application uses its own memory allocation to
  1344. * allocate memory block for the specified header (e.g. in C++, when the
  1345. * header is allocated with "new" operator).
  1346. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1347. * which allocates memory and initialize it in one go.
  1348. *
  1349. * @param pool Pool for additional memory allocation if required.
  1350. * @param mem Pre-allocated memory to be initialized as the header.
  1351. * @param value The expiration value.
  1352. *
  1353. * @return The header instance, which points to the same memory
  1354. * location as the mem argument.
  1355. */
  1356. PJ_DECL(pjsip_expires_hdr*) pjsip_expires_hdr_init( pj_pool_t *pool,
  1357. void *mem,
  1358. unsigned value );
  1359. /* **************************************************************************/
  1360. /**
  1361. * To or From header.
  1362. */
  1363. typedef struct pjsip_fromto_hdr
  1364. {
  1365. PJSIP_DECL_HDR_MEMBER(struct pjsip_fromto_hdr);
  1366. pjsip_uri *uri; /**< URI in From/To header. */
  1367. pj_str_t tag; /**< Header "tag" parameter. */
  1368. pjsip_param other_param; /**< Other params, concatenated as a single string. */
  1369. } pjsip_fromto_hdr;
  1370. /** Alias for From header. */
  1371. typedef pjsip_fromto_hdr pjsip_from_hdr;
  1372. /** Alias for To header. */
  1373. typedef pjsip_fromto_hdr pjsip_to_hdr;
  1374. /**
  1375. * Create a From header.
  1376. *
  1377. * @param pool The pool.
  1378. * @return New instance of From header.
  1379. */
  1380. PJ_DECL(pjsip_from_hdr*) pjsip_from_hdr_create( pj_pool_t *pool );
  1381. /**
  1382. * Initialize a preallocated memory with the header structure. This function
  1383. * should only be called when application uses its own memory allocation to
  1384. * allocate memory block for the specified header (e.g. in C++, when the
  1385. * header is allocated with "new" operator).
  1386. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1387. * which allocates memory and initialize it in one go.
  1388. *
  1389. * @param pool Pool for additional memory allocation if required.
  1390. * @param mem Pre-allocated memory to be initialized as the header.
  1391. *
  1392. * @return The header instance, which points to the same memory
  1393. * location as the mem argument.
  1394. */
  1395. PJ_DECL(pjsip_from_hdr*) pjsip_from_hdr_init( pj_pool_t *pool,
  1396. void *mem );
  1397. /**
  1398. * Create a To header.
  1399. *
  1400. * @param pool The pool.
  1401. * @return New instance of To header.
  1402. */
  1403. PJ_DECL(pjsip_to_hdr*) pjsip_to_hdr_create( pj_pool_t *pool );
  1404. /**
  1405. * Initialize a preallocated memory with the header structure. This function
  1406. * should only be called when application uses its own memory allocation to
  1407. * allocate memory block for the specified header (e.g. in C++, when the
  1408. * header is allocated with "new" operator).
  1409. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1410. * which allocates memory and initialize it in one go.
  1411. *
  1412. * @param pool Pool for additional memory allocation if required.
  1413. * @param mem Pre-allocated memory to be initialized as the header.
  1414. *
  1415. * @return The header instance, which points to the same memory
  1416. * location as the mem argument.
  1417. */
  1418. PJ_DECL(pjsip_to_hdr*) pjsip_to_hdr_init( pj_pool_t *pool,
  1419. void *mem );
  1420. /**
  1421. * Convert the header to a From header.
  1422. *
  1423. * @param hdr The generic from/to header.
  1424. * @return "From" header.
  1425. */
  1426. PJ_DECL(pjsip_from_hdr*) pjsip_fromto_hdr_set_from( pjsip_fromto_hdr *hdr );
  1427. /**
  1428. * Convert the header to a To header.
  1429. *
  1430. * @param hdr The generic from/to header.
  1431. * @return "To" header.
  1432. */
  1433. PJ_DECL(pjsip_to_hdr*) pjsip_fromto_hdr_set_to( pjsip_fromto_hdr *hdr );
  1434. /* **************************************************************************/
  1435. /**
  1436. * Max-Forwards header.
  1437. */
  1438. typedef pjsip_generic_int_hdr pjsip_max_fwd_hdr;
  1439. /**
  1440. * Create new Max-Forwards header instance.
  1441. *
  1442. * @param pool The pool.
  1443. * @param value The Max-Forwards value.
  1444. *
  1445. * @return New Max-Forwards header instance.
  1446. */
  1447. PJ_DECL(pjsip_max_fwd_hdr*)
  1448. pjsip_max_fwd_hdr_create(pj_pool_t *pool, unsigned value);
  1449. /**
  1450. * Initialize a preallocated memory with the header structure. This function
  1451. * should only be called when application uses its own memory allocation to
  1452. * allocate memory block for the specified header (e.g. in C++, when the
  1453. * header is allocated with "new" operator).
  1454. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1455. * which allocates memory and initialize it in one go.
  1456. *
  1457. * @param pool Pool for additional memory allocation if required.
  1458. * @param mem Pre-allocated memory to be initialized as the header.
  1459. * @param value The Max-Forwards value.
  1460. *
  1461. * @return The header instance, which points to the same memory
  1462. * location as the mem argument.
  1463. */
  1464. PJ_DECL(pjsip_max_fwd_hdr*)
  1465. pjsip_max_fwd_hdr_init( pj_pool_t *pool, void *mem, unsigned value );
  1466. /* **************************************************************************/
  1467. /**
  1468. * Min-Expires header.
  1469. */
  1470. typedef pjsip_generic_int_hdr pjsip_min_expires_hdr;
  1471. /**
  1472. * Create new Min-Expires header instance.
  1473. *
  1474. * @param pool The pool.
  1475. * @param value The Min-Expires value.
  1476. *
  1477. * @return New Min-Expires header instance.
  1478. */
  1479. PJ_DECL(pjsip_min_expires_hdr*) pjsip_min_expires_hdr_create(pj_pool_t *pool,
  1480. unsigned value);
  1481. /**
  1482. * Initialize a preallocated memory with the header structure. This function
  1483. * should only be called when application uses its own memory allocation to
  1484. * allocate memory block for the specified header (e.g. in C++, when the
  1485. * header is allocated with "new" operator).
  1486. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1487. * which allocates memory and initialize it in one go.
  1488. *
  1489. * @param pool Pool for additional memory allocation if required.
  1490. * @param mem Pre-allocated memory to be initialized as the header.
  1491. * @param value The Min-Expires value.
  1492. *
  1493. * @return The header instance, which points to the same memory
  1494. * location as the mem argument.
  1495. */
  1496. PJ_DECL(pjsip_min_expires_hdr*) pjsip_min_expires_hdr_init( pj_pool_t *pool,
  1497. void *mem,
  1498. unsigned value );
  1499. /* **************************************************************************/
  1500. /**
  1501. * Record-Route and Route headers.
  1502. */
  1503. typedef struct pjsip_routing_hdr
  1504. {
  1505. PJSIP_DECL_HDR_MEMBER(struct pjsip_routing_hdr); /**< Generic header fields. */
  1506. pjsip_name_addr name_addr; /**< The URL in the Route/Record-Route header. */
  1507. pjsip_param other_param; /**< Other parameter. */
  1508. } pjsip_routing_hdr;
  1509. /** Alias for Record-Route header. */
  1510. typedef pjsip_routing_hdr pjsip_rr_hdr;
  1511. /** Alias for Route header. */
  1512. typedef pjsip_routing_hdr pjsip_route_hdr;
  1513. /**
  1514. * Create new Record-Route header from the pool.
  1515. *
  1516. * @param pool The pool.
  1517. * @return A new instance of Record-Route header.
  1518. */
  1519. PJ_DECL(pjsip_rr_hdr*) pjsip_rr_hdr_create( pj_pool_t *pool );
  1520. /**
  1521. * Initialize a preallocated memory with the header structure. This function
  1522. * should only be called when application uses its own memory allocation to
  1523. * allocate memory block for the specified header (e.g. in C++, when the
  1524. * header is allocated with "new" operator).
  1525. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1526. * which allocates memory and initialize it in one go.
  1527. *
  1528. * @param pool Pool for additional memory allocation if required.
  1529. * @param mem Pre-allocated memory to be initialized as the header.
  1530. *
  1531. * @return The header instance, which points to the same memory
  1532. * location as the mem argument.
  1533. */
  1534. PJ_DECL(pjsip_rr_hdr*) pjsip_rr_hdr_init( pj_pool_t *pool,
  1535. void *mem );
  1536. /**
  1537. * Create new Route header from the pool.
  1538. *
  1539. * @param pool The pool.
  1540. * @return A new instance of "Route" header.
  1541. */
  1542. PJ_DECL(pjsip_route_hdr*) pjsip_route_hdr_create( pj_pool_t *pool );
  1543. /**
  1544. * Initialize a preallocated memory with the header structure. This function
  1545. * should only be called when application uses its own memory allocation to
  1546. * allocate memory block for the specified header (e.g. in C++, when the
  1547. * header is allocated with "new" operator).
  1548. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1549. * which allocates memory and initialize it in one go.
  1550. *
  1551. * @param pool Pool for additional memory allocation if required.
  1552. * @param mem Pre-allocated memory to be initialized as the header.
  1553. *
  1554. * @return The header instance, which points to the same memory
  1555. * location as the mem argument.
  1556. */
  1557. PJ_DECL(pjsip_route_hdr*) pjsip_route_hdr_init( pj_pool_t *pool,
  1558. void *mem );
  1559. /**
  1560. * Convert generic routing header to Record-Route header.
  1561. *
  1562. * @param r The generic routing header, or a "Routing" header.
  1563. * @return Record-Route header.
  1564. */
  1565. PJ_DECL(pjsip_rr_hdr*) pjsip_routing_hdr_set_rr( pjsip_routing_hdr *r );
  1566. /**
  1567. * Convert generic routing header to "Route" header.
  1568. *
  1569. * @param r The generic routing header, or a "Record-Route" header.
  1570. * @return "Route" header.
  1571. */
  1572. PJ_DECL(pjsip_route_hdr*) pjsip_routing_hdr_set_route( pjsip_routing_hdr *r );
  1573. /* **************************************************************************/
  1574. /**
  1575. * Require header.
  1576. */
  1577. typedef pjsip_generic_array_hdr pjsip_require_hdr;
  1578. /**
  1579. * Create new Require header instance.
  1580. *
  1581. * @param pool The pool.
  1582. *
  1583. * @return New Require header instance.
  1584. */
  1585. PJ_DECL(pjsip_require_hdr*) pjsip_require_hdr_create(pj_pool_t *pool);
  1586. /**
  1587. * Initialize a preallocated memory with the header structure. This function
  1588. * should only be called when application uses its own memory allocation to
  1589. * allocate memory block for the specified header (e.g. in C++, when the
  1590. * header is allocated with "new" operator).
  1591. * For normal applications, they should use pjsip_xxx_hdr_create() instead,
  1592. * which allocates memory and initialize it in one go.
  1593. *
  1594. * @param pool Pool for additional memory allocation if required.
  1595. * @param mem Pre-allocated memory to be initialized as the header.
  1596. *
  1597. * @return The header instance, which points to the same memory
  1598. * location as the mem argument.
  1599. */
  1600. PJ_DECL(pjsip_require_hdr*) pjsip_require_hdr_init( pj_pool_t *pool,
  1601. void *mem );
  1602. /* **************************************************************************/
  1603. /**
  1604. * Retry-After header.
  1605. */
  1606. typedef struct pjsip_retry_after_hdr
  1607. {
  1608. /** Standard header field. */
  1609. PJSIP_DECL_HDR_MEMBER(struct pjsip_retry_after_hdr);
  1610. pj_int32_t ivalue; /**< Retry-After value */
  1611. pjsip_param param; /**< Optional parameters */
  1612. pj_str_t comment; /**< Optional comments. */
  1613. } pjsip_retry_after_hdr;
  1614. /**
  1615. * Create new Retry-After header instance.
  1616. *
  1617. * @param pool The pool.
  1618. * @param value The Retry-After value.
  1619. *
  1620. * @return New Retry-After header instance.
  1621. */
  1622. PJ_DECL(pjsip_retry_after_hdr*) pjsip_retry_after_hdr_create(pj_pool_t *pool,
  1623. int value);
  1624. /**
  1625. * Initialize a preallocated memory with the header structure.
  1626. *
  1627. * @param pool Pool for additional memory allocation if required.
  1628. * @param mem Pre-allocated memory to be initialized as the header.
  1629. * @param value The Retry-After value.
  1630. *
  1631. * @return The header instance, which points to the same memory
  1632. * location as the mem argument.
  1633. */
  1634. PJ_DECL(pjsip_retry_after_hdr*) pjsip_retry_after_hdr_init( pj_pool_t *pool,
  1635. void *mem,
  1636. int value );
  1637. /* **************************************************************************/
  1638. /**
  1639. * Supported header.
  1640. */
  1641. typedef pjsip_generic_array_hdr pjsip_supported_hdr;
  1642. /**
  1643. * Create new Supported header instance.
  1644. *
  1645. * @param pool The pool.
  1646. *
  1647. * @return New Supported header instance.
  1648. */
  1649. PJ_DECL(pjsip_supported_hdr*) pjsip_supported_hdr_create(pj_pool_t *pool);
  1650. /**
  1651. * Initialize a preallocated memory with the header structure.
  1652. *
  1653. * @param pool Pool for additional memory allocation if required.
  1654. * @param mem Pre-allocated memory to be initialized as the header.
  1655. *
  1656. * @return The header instance, which points to the same memory
  1657. * location as the mem argument.
  1658. */
  1659. PJ_DECL(pjsip_supported_hdr*) pjsip_supported_hdr_init( pj_pool_t *pool,
  1660. void *mem );
  1661. /* **************************************************************************/
  1662. /**
  1663. * Unsupported header.
  1664. */
  1665. typedef pjsip_generic_array_hdr pjsip_unsupported_hdr;
  1666. /**
  1667. * Create new Unsupported header instance.
  1668. *
  1669. * @param pool The pool.
  1670. *
  1671. * @return New Unsupported header instance.
  1672. */
  1673. PJ_DECL(pjsip_unsupported_hdr*) pjsip_unsupported_hdr_create(pj_pool_t *pool);
  1674. /**
  1675. * Initialize a preallocated memory with the header structure.
  1676. *
  1677. * @param pool Pool for additional memory allocation if required.
  1678. * @param mem Pre-allocated memory to be initialized as the header.
  1679. *
  1680. * @return The header instance, which points to the same memory
  1681. * location as the mem argument.
  1682. */
  1683. PJ_DECL(pjsip_unsupported_hdr*) pjsip_unsupported_hdr_init( pj_pool_t *pool,
  1684. void *mem );
  1685. /* **************************************************************************/
  1686. /**
  1687. * SIP Via header.
  1688. * In this implementation, Via header can only have one element in each header.
  1689. * If a message arrives with multiple elements in a single Via, then they will
  1690. * be split up into multiple Via headers.
  1691. */
  1692. typedef struct pjsip_via_hdr
  1693. {
  1694. PJSIP_DECL_HDR_MEMBER(struct pjsip_via_hdr);
  1695. pj_str_t transport; /**< Transport type. */
  1696. pjsip_host_port sent_by; /**< Host and optional port */
  1697. int ttl_param; /**< TTL parameter, or -1 if it's not specified. */
  1698. int rport_param; /**< "rport" parameter, 0 to specify without
  1699. port number, -1 means doesn't exist. */
  1700. pj_str_t maddr_param; /**< "maddr" parameter. */
  1701. pj_str_t recvd_param; /**< "received" parameter. */
  1702. pj_str_t branch_param; /**< "branch" parameter. */
  1703. pjsip_param other_param; /**< Other parameters, concatenated as single string. */
  1704. pj_str_t comment; /**< Comment. */
  1705. } pjsip_via_hdr;
  1706. /**
  1707. * Create a new Via header.
  1708. *
  1709. * @param pool The pool.
  1710. * @return A new "Via" header instance.
  1711. */
  1712. PJ_DECL(pjsip_via_hdr*) pjsip_via_hdr_create( pj_pool_t *pool );
  1713. /**
  1714. * Initialize a preallocated memory with the header structure.
  1715. *
  1716. * @param pool Pool for additional memory allocation if required.
  1717. * @param mem Pre-allocated memory to be initialized as the header.
  1718. *
  1719. * @return The header instance, which points to the same memory
  1720. * location as the mem argument.
  1721. */
  1722. PJ_DECL(pjsip_via_hdr*) pjsip_via_hdr_init( pj_pool_t *pool,
  1723. void *mem );
  1724. /* **************************************************************************/
  1725. /**
  1726. * SIP Warning header.
  1727. * In this version, Warning header is just a typedef for generic string
  1728. * header.
  1729. */
  1730. typedef pjsip_generic_string_hdr pjsip_warning_hdr;
  1731. /**
  1732. * Create a warning header with the specified contents.
  1733. *
  1734. * @param pool Pool to allocate memory from.
  1735. * @param code Warning code, 300-399.
  1736. * @param host The host portion of the Warning header.
  1737. * @param text The warning text, which MUST not be quoted with
  1738. * double quote.
  1739. *
  1740. * @return The Warning header field.
  1741. */
  1742. PJ_DECL(pjsip_warning_hdr*) pjsip_warning_hdr_create( pj_pool_t *pool,
  1743. int code,
  1744. const pj_str_t *host,
  1745. const pj_str_t *text);
  1746. /**
  1747. * Create a warning header and initialize the contents from the error
  1748. * message for the specified status code. The warning code will be
  1749. * set to 399.
  1750. *
  1751. * @param pool Pool to allocate memory from.
  1752. * @param host The host portion of the Warning header.
  1753. * @param status The error status code, which error text will be
  1754. * put in as the Warning text.
  1755. *
  1756. * @return The Warning header field.
  1757. */
  1758. PJ_DECL(pjsip_warning_hdr*)
  1759. pjsip_warning_hdr_create_from_status( pj_pool_t *pool,
  1760. const pj_str_t *host,
  1761. pj_status_t status);
  1762. /* **************************************************************************/
  1763. /** Accept-Encoding header. */
  1764. typedef pjsip_generic_string_hdr pjsip_accept_encoding_hdr;
  1765. /** Create Accept-Encoding header. */
  1766. #define pjsip_accept_encoding_hdr_create pjsip_generic_string_hdr_create
  1767. /** Accept-Language header. */
  1768. typedef pjsip_generic_string_hdr pjsip_accept_lang_hdr;
  1769. /** Create Accept-Language header. */
  1770. #define pjsip_accept_lang_hdr_create pjsip_generic_string_hdr_create
  1771. /** Alert-Info header. */
  1772. typedef pjsip_generic_string_hdr pjsip_alert_info_hdr;
  1773. /** Create Alert-Info header. */
  1774. #define pjsip_alert_info_hdr_create pjsip_generic_string_hdr_create
  1775. /** Authentication-Info header. */
  1776. typedef pjsip_generic_string_hdr pjsip_auth_info_hdr;
  1777. /** Create Authentication-Info header. */
  1778. #define pjsip_auth_info_hdr_create pjsip_generic_string_hdr_create
  1779. /** Call-Info header. */
  1780. typedef pjsip_generic_string_hdr pjsip_call_info_hdr;
  1781. /** Create Call-Info header. */
  1782. #define pjsip_call_info_hdr_create pjsip_generic_string_hdr_create
  1783. /** Content-Disposition header. */
  1784. typedef pjsip_generic_string_hdr pjsip_content_disposition_hdr;
  1785. /** Create Content-Disposition header. */
  1786. #define pjsip_content_disposition_hdr_create pjsip_generic_string_hdr_create
  1787. /** Content-Encoding header. */
  1788. typedef pjsip_generic_string_hdr pjsip_content_encoding_hdr;
  1789. /** Create Content-Encoding header. */
  1790. #define pjsip_content_encoding_hdr_create pjsip_generic_string_hdr_create
  1791. /** Content-Language header. */
  1792. typedef pjsip_generic_string_hdr pjsip_content_lang_hdr;
  1793. /** Create Content-Language header. */
  1794. #define pjsip_content_lang_hdr_create pjsip_generic_string_hdr_create
  1795. /** Date header. */
  1796. typedef pjsip_generic_string_hdr pjsip_date_hdr;
  1797. /** Create Date header. */
  1798. #define pjsip_date_hdr_create pjsip_generic_string_hdr_create
  1799. /** Error-Info header. */
  1800. typedef pjsip_generic_string_hdr pjsip_err_info_hdr;
  1801. /** Create Error-Info header. */
  1802. #define pjsip_err_info_hdr_create pjsip_generic_string_hdr_create
  1803. /** In-Reply-To header. */
  1804. typedef pjsip_generic_string_hdr pjsip_in_reply_to_hdr;
  1805. /** Create In-Reply-To header. */
  1806. #define pjsip_in_reply_to_hdr_create pjsip_generic_string_hdr_create
  1807. /** MIME-Version header. */
  1808. typedef pjsip_generic_string_hdr pjsip_mime_version_hdr;
  1809. /** Create MIME-Version header. */
  1810. #define pjsip_mime_version_hdr_create pjsip_generic_string_hdr_create
  1811. /** Organization header. */
  1812. typedef pjsip_generic_string_hdr pjsip_organization_hdr;
  1813. /** Create Organization header. */
  1814. #define pjsip_organization_hdr_create pjsip_genric_string_hdr_create
  1815. /** Priority header. */
  1816. typedef pjsip_generic_string_hdr pjsip_priority_hdr;
  1817. /** Create Priority header. */
  1818. #define pjsip_priority_hdr_create pjsip_generic_string_hdr_create
  1819. /** Proxy-Require header. */
  1820. typedef pjsip_generic_string_hdr pjsip_proxy_require_hdr;
  1821. /** Reply-To header. */
  1822. typedef pjsip_generic_string_hdr pjsip_reply_to_hdr;
  1823. /** Create Reply-To header. */
  1824. #define pjsip_reply_to_hdr_create pjsip_generic_string_hdr_create
  1825. /** Server header. */
  1826. typedef pjsip_generic_string_hdr pjsip_server_hdr;
  1827. /** Create Server header. */
  1828. #define pjsip_server_hdr_create pjsip_generic_string_hdr_create
  1829. /** Subject header. */
  1830. typedef pjsip_generic_string_hdr pjsip_subject_hdr;
  1831. /** Create Subject header. */
  1832. #define pjsip_subject_hdr_create pjsip_generic_string_hdr_create
  1833. /** Timestamp header. */
  1834. typedef pjsip_generic_string_hdr pjsip_timestamp_hdr;
  1835. /** Create Timestamp header. */
  1836. #define pjsip_timestamp_hdr_create pjsip_generic_string_hdr_create
  1837. /** User-Agent header. */
  1838. typedef pjsip_generic_string_hdr pjsip_user_agent_hdr;
  1839. /** Create User-Agent header. */
  1840. #define pjsip_user_agent_hdr_create pjsip_generic_string_hdr_create
  1841. /**
  1842. * @}
  1843. */
  1844. /**
  1845. * @} PJSIP_MSG
  1846. */
  1847. PJ_END_DECL
  1848. #endif /* __PJSIP_SIP_MSG_H__ */