contact_parser.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <section id="contact_parser" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <sectioninfo>
  6. <revhistory>
  7. <revision>
  8. <revnumber>$Revision$</revnumber>
  9. <date>$Date$</date>
  10. </revision>
  11. </revhistory>
  12. </sectioninfo>
  13. <title>Contact Header Field Parser</title>
  14. <para>
  15. The parser is located under <filename>parser/contact</filename>
  16. subdirectory. The parser is not called automatically when the main
  17. parser finds a Contact header field. It is your responsibility to call
  18. the parser if you want a Contact header field body to be parsed.
  19. </para>
  20. <para>
  21. Main function is <function>parse_contact</function> in file
  22. <filename>parse_contact.c</filename>. The function accepts one
  23. parameter which is structure <structname>hdr_field</structname>
  24. representing the header field to be parsed. A single Contact header
  25. field may contain multiple contacts, the parser will parse all of them
  26. and will create linked list of all such contacts.
  27. </para>
  28. <para>
  29. The function creates and initializes an instance of
  30. <structname>contact_body</structname> structure. Then function
  31. <function>contact_parser</function> will be called. If everything went
  32. OK, pointer to the newly created structure will be stored in
  33. <structfield>parsed</structfield> field of the
  34. <structname>hdr_field</structname> structure representing the parsed
  35. header field.
  36. </para>
  37. <para>
  38. Function <function>contact_parser</function> will then check if the
  39. contact is star, if not it will call
  40. <function>parse_contacts</function> function that will parse all
  41. contacts of the header field.
  42. </para>
  43. <para>
  44. Function <function>parse_contacts</function> can be found in file
  45. <filename>contact.c</filename>. It extracts <acronym>URI</acronym> and
  46. parses all contact parameters.
  47. </para>
  48. <para>
  49. The Contact parameter parser can be found in file
  50. <filename>cparam.c</filename>.
  51. </para>
  52. <para>
  53. The following structures will be created during parsing:
  54. </para>
  55. <note>
  56. <para>
  57. Mind that none of string in the following structures is zero
  58. terminated ! Be very careful when processing the strings with
  59. functions that require zero termination (printf for example) !
  60. </para>
  61. </note>
  62. <programlisting>
  63. typedef struct contact_body {
  64. unsigned char star; /* Star contact */
  65. contact_t* contacts; /* List of contacts */
  66. } contact_body_t;
  67. </programlisting>
  68. <para>
  69. This is the main structure. Pointer to instance of this structure will be stored in
  70. <structfield>parsed</structfield> field of structure representing the header field to be parsed.
  71. The structure contains two field:
  72. <itemizedlist>
  73. <listitem>
  74. <para>
  75. <structfield>star</structfield> field - This field will
  76. contain 1 if the Contact was star (see
  77. <acronym>RFC3261</acronym> for more details).
  78. </para>
  79. </listitem>
  80. <listitem>
  81. <para>
  82. <structfield>contacts</structfield> field - This field
  83. contains pointer to linked list of all contacts found in
  84. the Contact header field.
  85. </para>
  86. </listitem>
  87. </itemizedlist>
  88. </para>
  89. <programlisting>
  90. typedef struct contact {
  91. str uri; /* contact uri */
  92. cparam_t* q; /* q parameter hook */
  93. cparam_t* expires; /* expires parameter hook */
  94. cparam_t* method; /* method parameter hook */
  95. cparam_t* params; /* List of all parameters */
  96. struct contact* next; /* Next contact in the list */
  97. } contact_t;
  98. </programlisting>
  99. <para>
  100. This structure represents one Contact (Mind that there might be several
  101. contacts in one Contact header field delimited by a comma). Its fields
  102. have the following meaning:
  103. <itemizedlist>
  104. <listitem>
  105. <para>
  106. <structfield>uri</structfield> - This field contains
  107. pointer to begin of <acronym>URI</acronym> and its length.
  108. </para>
  109. </listitem>
  110. <listitem>
  111. <para>
  112. <structfield>q</structfield> - This is a hook to structure representing q parameter.
  113. If there is no such parameter, the hook contains 0.
  114. </para>
  115. </listitem>
  116. <listitem>
  117. <para>
  118. <structfield>expires</structfield> - This is a hook to
  119. structure representing expires parameter. If there is no
  120. such parameter, the hook contains 0.
  121. </para>
  122. </listitem>
  123. <listitem>
  124. <para>
  125. <structfield>method</structfield> - This is a hook to
  126. structure representing method parameter. If there is no
  127. such parameter, the hook contains 0.
  128. </para>
  129. </listitem>
  130. <listitem>
  131. <para>
  132. <structfield>params</structfield> - Linked list of all
  133. parameters.
  134. </para>
  135. </listitem>
  136. <listitem>
  137. <para>
  138. <structfield>next</structfield> - Pointer to the next
  139. contact that was in the same header field.
  140. </para>
  141. </listitem>
  142. </itemizedlist>
  143. </para>
  144. <programlisting>
  145. typedef enum cptype {
  146. CP_OTHER = 0, /* Unknown parameter */
  147. CP_Q, /* Q parameter */
  148. CP_EXPIRES, /* Expires parameter */
  149. CP_METHOD /* Method parameter */
  150. } cptype_t;
  151. </programlisting>
  152. <para>
  153. This is an enum of recognized types of contact parameters. Q parameter
  154. will have type set to CP_Q, Expires parameter will have type set to
  155. CP_EXPIRES and Method parameter will have type set to CP_METHOD. All
  156. other parameters will have type set to CP_OTHER.
  157. </para>
  158. <programlisting>
  159. /*
  160. * Structure representing a contact
  161. */
  162. typedef struct cparam {
  163. cptype_t type; /* Type of the parameter */
  164. str name; /* Parameter name */
  165. str body; /* Parameter body */
  166. struct cparam* next; /* Next parameter in the list */
  167. } cparam_t;
  168. </programlisting>
  169. <para>
  170. This structure represents a contact parameter. Field description
  171. follows:
  172. <itemizedlist>
  173. <listitem>
  174. <para>
  175. <structfield>type</structfield> - Type of the parameter,
  176. see <structname>cptype</structname> enum for more details.
  177. </para>
  178. </listitem>
  179. <listitem>
  180. <para>
  181. <structfield>name</structfield> - Name of the parameter
  182. (i.e. the part before "=").
  183. </para>
  184. </listitem>
  185. <listitem>
  186. <para>
  187. <structfield>body</structfield> - Body of the parameter
  188. (i.e. the part after "=").
  189. </para>
  190. </listitem>
  191. <listitem>
  192. <para>
  193. <structfield>next</structfield> - Next parameter in the linked list.
  194. </para>
  195. </listitem>
  196. </itemizedlist>
  197. </para>
  198. </section>