2009/2/26 Fabio Margarido <fabiomargar...@gmail.com>: > I'd like to know what's the best way to check if a header is present (and > get its contents) in a sip_t (or msg_t) structure by name (as a string) or > if there is a way to loop through all the headers in a sip_t structure, > checking if each one's name matches an arbitrary string the user of my > application has passed and get the contents of the headers in case there is > a match.
You can get msg_href_t by name with msg_find_hclass(), like msg_href_t *href = msg_find_hclass(msg_mclass(msg), name, NULL); msg_header_t **slot = (char *)sip + href->hr_offset; if (href->hr_class->hc_name[0]) { /* Well-known header */ } else { /* Unknown header */ } The header contents (including its name) are in (*slot)->sh_data, lenght in (*slot)->sh_len. In order to gain access to the unparsed contents, you have to add NTATAG_SIP_FLAGS(MSG_FLG_EXTRACT_COPY) when calling nua_create() or nta_agent_create()). Alternatively, you can convert the header field to string with sip_header_as_string(). Header field is usually a thing that you can put on separate headers or on a a single header separated with commas. E.g., header Contact: <sip:192.168.1.100>, <sip:fec0::1> contains two header fields and it could be represented as two headers Contact: <sip:192.168.1.100> Contact: <sip:fec0::1> The (*slot)->sh_next pointer will contain the next header field or next header with the same name. The authentication headers are an exception in SIP, there the header field contains all the comma-separated values from a single header. Sofia SIP makes another exception for so called list headers where the header field consists of single token, so if the original message contains headers Require: 100rel Require: timer the 100rel and timer are collected in a single list (on sip->sip_require->k_items[] array) and they are returned in a single call to sip_header_as_string(). If you want to make your application bomb-proof, you probably have to go through the list of bad headers in sip->sip_error, too. -- Pekka.Pessi mail at nokia.com ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel