sipmsg: add helpers to find common headers
[siplcs.git] / src / core / sipmsg.h
blob52f05c8d10f3c63aa0ba844f96199353b438fcf5
1 /**
2 * @file sipmsg.h
4 * pidgin-sipe
6 * Copyright (C) 2010-2019 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2008 Novell, Inc.
8 * Copyright (C) 2005, Thomas Butter <butter@uni-mannheim.de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Interface dependencies:
28 * <glib.h>
31 #define SIPMSG_RESPONSE_FATAL_ERROR -1
32 #define SIPMSG_BODYLEN_CHUNKED -1
34 struct sipmsg {
35 int response; /* 0 means request, otherwise response code */
36 gchar *responsestr;
37 gchar *method;
38 gchar *target;
39 GSList *headers;
40 GSList *new_headers;
41 int bodylen;
42 gchar *body;
43 gchar *signature;
44 gchar *rand;
45 gchar *num;
48 struct sipendpoint {
49 gchar *contact;
50 gchar *epid;
54 struct sipmsg *sipmsg_parse_msg(const gchar *msg);
55 struct sipmsg *sipmsg_parse_header(const gchar *header);
56 struct sipmsg *sipmsg_copy(const struct sipmsg *other);
57 void sipmsg_add_header_now(struct sipmsg *msg, const gchar *name, const gchar *value);
58 void sipmsg_add_header(struct sipmsg *msg, const gchar *name, const gchar *value);
59 void sipmsg_strip_headers(struct sipmsg *msg, const gchar *keepers[]);
60 void sipmsg_merge_new_headers(struct sipmsg *msg);
61 void sipmsg_free(struct sipmsg *msg);
63 /**
64 * Parses CSeq from SIP message
66 * @param msg (in) SIP message
68 * @return int type CSeq value (i.e. without method).
70 int sipmsg_parse_cseq(struct sipmsg *msg);
72 GSList *sipmsg_parse_endpoints_header(const gchar *header);
73 /**
74 * Parses sip: and tel: URI out of P-Asserted-Identity header from INVITE request.
75 * You must free the values.
77 * Example headers:
78 * P-Asserted-Identity: "Cullen Jennings" <sip:fluffy@cisco.com>
79 * P-Asserted-Identity: tel:+14085264000
80 * P-Asserted-Identity: "Lunch, Lucas" <sip:llucas@cisco.com>,<tel:+420123456;ext=88463>
82 * @param header (in) P-Asserted-Identity header contents
83 * @param sip_uri (out) parsed sip: URI or NULL if missing
84 * @param tel_uri (out) parsed tel: URI or NULL if missing
86 void sipmsg_parse_p_asserted_identity(const gchar *header, gchar **sip_uri,
87 gchar **tel_uri);
88 const gchar *sipmsg_find_header(const struct sipmsg *msg, const gchar *name);
89 const gchar *sipmsg_find_header_instance(const struct sipmsg *msg, const gchar *name, int which);
90 gchar *sipmsg_find_part_of_header(const char *hdr, const char * before, const char * after, const char * def);
91 const gchar *sipmsg_find_auth_header(struct sipmsg *msg, const gchar *name);
92 void sipmsg_remove_header_now(struct sipmsg *msg, const gchar *name);
93 char *sipmsg_to_string(const struct sipmsg *msg);
95 /**
96 * Formats message to html if not yet.
97 * Either - keep as is if text/html, or escape text, or escape text and apply format string if any
99 * @param body in case of 'ms_text_format is Content-Type header' or NULL otherwise
100 * @param ms_text_format either ms-text-format ot Content-Type header.
102 * Allocates memory. Must be feed when done.
104 gchar *get_html_message(const gchar *ms_text_format, const gchar *body);
107 * Returns UTF-16LE/'modified base64' encoded X-MMS-IM-Format
108 * based on input x_mms_im_format.
110 gchar *sipmsg_get_msgr_string(gchar *x_mms_im_format);
113 * Parses the Purple message formatting (html) into the MSN format.
115 * @param html The html message to format.
116 * @param attributes The returned attributes string.
117 * @param message The returned message string.
119 * @return The new message.
121 void sipe_parse_html(const char *html, char **attributes, char **message);
124 * Extracts reason string from ms-diagnostics header of SIP message
126 * @param msg SIP message
128 * @return reason string. Must be g_free()'d after use.
130 gchar *sipmsg_get_ms_diagnostics_reason(struct sipmsg *msg);
133 * Extracts reason string from ms-diagnostics-public header of SIP message
135 * @param msg SIP message
137 * @return reason string. Must be g_free()'d after use.
139 gchar *sipmsg_get_ms_diagnostics_public_reason(struct sipmsg *msg);
142 * Parses Warning header of SIP message, if present.
144 * @param msg (in) SIP message
145 * @param reason (out) parsed warning text or NULL if missing. Must be g_free()'d
146 * after use.
148 * @return warning code or -1 if warning header is not present in message.
150 int sipmsg_parse_warning(struct sipmsg *msg, gchar **reason);
153 * Helpers to find some common headers in SIP message
155 * @param msg (in) SIP message
157 * @return header text or NULL if header is not present message.
159 const gchar *sipmsg_find_call_id_header(const struct sipmsg *msg);
160 const gchar *sipmsg_find_content_type_header(const struct sipmsg *msg);
161 const gchar *sipmsg_find_cseq_header(const struct sipmsg *msg);
162 const gchar *sipmsg_find_event_header(const struct sipmsg *msg);
163 const gchar *sipmsg_find_expires_header(const struct sipmsg *msg);
164 const gchar *sipmsg_find_from_header(const struct sipmsg *msg);
165 const gchar *sipmsg_find_to_header(const struct sipmsg *msg);
168 * Parse addresses out of SIP message headers
170 * @param msg (in) SIP message
171 * @param name (in) header name
173 * @return address or @c NULL if header not found or parse failure.
174 * Must be @c g_free()'d after use.
176 gchar *sipmsg_parse_contact_address(const struct sipmsg *msg);
177 gchar *sipmsg_parse_from_address(const struct sipmsg *msg);
178 gchar *sipmsg_parse_to_address(const struct sipmsg *msg);
179 gchar *sipmsg_parse_address_from_header(const struct sipmsg *msg,
180 const gchar *name);
183 * Generate and append new tag to the "To:" header in the message
185 * @param msg (in) SIP message
187 void sipmsg_update_to_header_tag(struct sipmsg *msg);