media: fix relay-info with Farstream 0.2
[siplcs.git] / src / core / sipe-sign.c
blob1fadc0584501254764bcfd770bec673f65a72c7c
1 /*
2 * @file sipe-sign.c
4 * pidgin-sipe
6 * Copyright (C) 2011-2013 SIPE Project <http://sipe.sourceforge.net/>
7 * Copyright (C) 2008 Novell, Inc.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
24 #include <string.h>
26 #include <glib.h>
28 #include "sipmsg.h"
29 #include "sipe-backend.h"
30 #include "sipe-sign.h"
32 static gchar * const empty_string = "";
34 void sipmsg_breakdown_parse(struct sipmsg_breakdown * msg, gchar * realm, gchar * target,
35 const gchar *protocol)
37 const gchar * hdr;
38 if (msg == NULL || msg->msg == NULL) {
39 SIPE_DEBUG_INFO_NOFORMAT("sipmsg_breakdown_parse msg or msg->msg is NULL");
40 return;
43 msg->rand = msg->num = msg->realm = msg->target_name =
44 msg->cseq = msg->from_url = msg->from_tag = msg->to_url = msg->to_tag =
45 msg->p_assertet_identity_sip_uri = msg->p_assertet_identity_tel_uri = empty_string;
46 msg->call_id = msg->expires = empty_string;
48 if ((hdr = sipmsg_find_header(msg->msg, "Proxy-Authorization")) ||
49 (hdr = sipmsg_find_header(msg->msg, "Proxy-Authentication-Info")) ||
50 (hdr = sipmsg_find_header(msg->msg, "Authentication-Info")) ) {
51 msg->protocol = sipmsg_find_part_of_header(hdr, NULL, " ", empty_string);
52 msg->rand = sipmsg_find_part_of_header(hdr, "rand=\"", "\"", empty_string);
53 msg->num = sipmsg_find_part_of_header(hdr, "num=\"", "\"", empty_string);
54 msg->realm = sipmsg_find_part_of_header(hdr, "realm=\"", "\"", empty_string);
55 msg->target_name = sipmsg_find_part_of_header(hdr, "targetname=\"", "\"", empty_string);
56 } else {
57 msg->protocol = g_strdup(protocol);
58 msg->realm = g_strdup(realm);
59 msg->target_name = g_strdup(target);
62 msg->call_id = sipmsg_find_header(msg->msg, "Call-ID");
64 hdr = sipmsg_find_header(msg->msg, "CSeq");
65 if (NULL != hdr) {
66 msg->cseq = sipmsg_find_part_of_header(hdr, NULL, " ", empty_string);
69 hdr = sipmsg_find_header(msg->msg, "From");
70 if (NULL != hdr) {
71 msg->from_url = sipmsg_find_part_of_header(hdr, "<", ">", empty_string);
72 msg->from_tag = sipmsg_find_part_of_header(hdr, ";tag=", ";", empty_string);
75 hdr = sipmsg_find_header(msg->msg, "To");
76 if (NULL != hdr) {
77 msg->to_url = sipmsg_find_part_of_header(hdr, "<", ">", empty_string);
78 msg->to_tag = sipmsg_find_part_of_header(hdr, ";tag=", ";", empty_string);
81 hdr = sipmsg_find_header(msg->msg, "P-Asserted-Identity");
82 if (NULL == hdr) {
83 hdr = sipmsg_find_header(msg->msg, "P-Preferred-Identity");
85 if (NULL != hdr) {
86 gchar *sip_uri = NULL;
87 gchar *tel_uri = NULL;
89 sipmsg_parse_p_asserted_identity(hdr, &sip_uri, &tel_uri);
90 if (sip_uri)
91 msg->p_assertet_identity_sip_uri = sip_uri;
92 if (tel_uri)
93 msg->p_assertet_identity_tel_uri = tel_uri;
96 msg->expires = sipmsg_find_header(msg->msg, "Expires");
99 void
100 sipmsg_breakdown_free(struct sipmsg_breakdown * msg)
102 if (msg->protocol != empty_string)
103 g_free(msg->protocol);
104 if (msg->rand != empty_string)
105 g_free(msg->rand);
106 if (msg->num != empty_string)
107 g_free(msg->num);
108 if (msg->realm != empty_string)
109 g_free(msg->realm);
110 if (msg->target_name != empty_string)
111 g_free(msg->target_name);
113 // straight from header
114 //g_free(msg->call_id);
116 if (msg->cseq != empty_string)
117 g_free(msg->cseq);
118 if (msg->from_url != empty_string)
119 g_free(msg->from_url);
120 if (msg->from_tag != empty_string)
121 g_free(msg->from_tag);
122 if (msg->to_url != empty_string)
123 g_free(msg->to_url);
124 if (msg->to_tag != empty_string)
125 g_free(msg->to_tag);
127 if (msg->p_assertet_identity_sip_uri != empty_string)
128 g_free(msg->p_assertet_identity_sip_uri);
129 if (msg->p_assertet_identity_tel_uri != empty_string)
130 g_free(msg->p_assertet_identity_tel_uri);
132 // straight from header
133 //g_free (msg->expires);
136 gchar *
137 sipmsg_breakdown_get_string(int version,
138 struct sipmsg_breakdown * msgbd)
140 gchar *response_str;
141 gchar *msg;
142 if (msgbd->realm == empty_string || msgbd->realm == NULL) {
143 SIPE_DEBUG_INFO_NOFORMAT("realm NULL, so returning NULL signature string");
144 return NULL;
147 response_str = msgbd->msg->response != 0 ? g_strdup_printf("<%d>", msgbd->msg->response) : empty_string;
148 if (version < 3) {
149 msg = g_strdup_printf(
150 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 11
151 "<%s>%s", // 12 - 13
152 msgbd->protocol, msgbd->rand, msgbd->num, msgbd->realm, msgbd->target_name, msgbd->call_id, msgbd->cseq,
153 msgbd->msg->method, msgbd->from_url, msgbd->from_tag, msgbd->to_tag,
154 msgbd->expires ? msgbd->expires : empty_string, response_str
156 } else {
157 msg = g_strdup_printf(
158 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 14
159 "<%s>%s", // 15 - 16
160 msgbd->protocol, msgbd->rand, msgbd->num, msgbd->realm, msgbd->target_name, msgbd->call_id, msgbd->cseq,
161 msgbd->msg->method, msgbd->from_url, msgbd->from_tag, msgbd->to_url, msgbd->to_tag,
162 msgbd->p_assertet_identity_sip_uri, msgbd->p_assertet_identity_tel_uri,
163 msgbd->expires ? msgbd->expires : empty_string, response_str
167 if (response_str != empty_string) {
168 g_free(response_str);
171 return msg;
175 Local Variables:
176 mode: c
177 c-file-style: "bsd"
178 indent-tabs-mode: t
179 tab-width: 8
180 End: