Fix sipe_buddy_menu_copy_to_cb when copying buddy not yet in our list
[siplcs.git] / src / core / sipe-sign.c
blob6ec1e27baf34611525da594c1cb58258c4bda042
1 /*
2 * @file sipe-sign.c
4 * pidgin-sipe
6 * Copyright (C) 2008 Novell, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include <string.h>
25 #include <glib.h>
27 #include "sipmsg.h"
28 #include "sipe-backend.h"
29 #include "sipe-sign.h"
31 static gchar * const empty_string = "";
33 void sipmsg_breakdown_parse(struct sipmsg_breakdown * msg, gchar * realm, gchar * target)
35 const gchar * hdr;
36 if (msg == NULL || msg->msg == NULL) {
37 SIPE_DEBUG_INFO_NOFORMAT("sipmsg_breakdown_parse msg or msg->msg is NULL");
38 return;
41 msg->rand = msg->num = msg->realm = msg->target_name =
42 msg->cseq = msg->from_url = msg->from_tag = msg->to_url = msg->to_tag =
43 msg->p_assertet_identity_sip_uri = msg->p_assertet_identity_tel_uri = empty_string;
44 msg->call_id = msg->expires = empty_string;
46 if ((hdr = sipmsg_find_header(msg->msg, "Proxy-Authorization")) ||
47 (hdr = sipmsg_find_header(msg->msg, "Proxy-Authenticate")) ||
48 (hdr = sipmsg_find_header(msg->msg, "Proxy-Authentication-Info")) ||
49 (hdr = sipmsg_find_header(msg->msg, "Authentication-Info")) ) {
50 msg->protocol = sipmsg_find_part_of_header(hdr, NULL, " ", empty_string);
51 msg->rand = sipmsg_find_part_of_header(hdr, "rand=\"", "\"", empty_string);
52 msg->num = sipmsg_find_part_of_header(hdr, "num=\"", "\"", empty_string);
53 msg->realm = sipmsg_find_part_of_header(hdr, "realm=\"", "\"", empty_string);
54 msg->target_name = sipmsg_find_part_of_header(hdr, "targetname=\"", "\"", empty_string);
55 } else {
56 msg->protocol = strstr(target, "sip/") ? g_strdup("Kerberos") : g_strdup("NTLM");
57 msg->realm = g_strdup(realm);
58 msg->target_name = g_strdup(target);
61 msg->call_id = sipmsg_find_header(msg->msg, "Call-ID");
63 hdr = sipmsg_find_header(msg->msg, "CSeq");
64 if (NULL != hdr) {
65 msg->cseq = sipmsg_find_part_of_header(hdr, NULL, " ", empty_string);
68 hdr = sipmsg_find_header(msg->msg, "From");
69 if (NULL != hdr) {
70 msg->from_url = sipmsg_find_part_of_header(hdr, "<", ">", empty_string);
71 msg->from_tag = sipmsg_find_part_of_header(hdr, ";tag=", ";", empty_string);
74 hdr = sipmsg_find_header(msg->msg, "To");
75 if (NULL != hdr) {
76 msg->to_url = sipmsg_find_part_of_header(hdr, "<", ">", empty_string);
77 msg->to_tag = sipmsg_find_part_of_header(hdr, ";tag=", ";", empty_string);
80 hdr = sipmsg_find_header(msg->msg, "P-Asserted-Identity");
81 if (NULL == hdr) {
82 hdr = sipmsg_find_header(msg->msg, "P-Preferred-Identity");
84 if (NULL != hdr) {
85 gchar *sip_uri = NULL;
86 gchar *tel_uri = NULL;
88 sipmsg_parse_p_asserted_identity(hdr, &sip_uri, &tel_uri);
89 if (sip_uri)
90 msg->p_assertet_identity_sip_uri = sip_uri;
91 if (tel_uri)
92 msg->p_assertet_identity_tel_uri = tel_uri;
95 msg->expires = sipmsg_find_header(msg->msg, "Expires");
98 void
99 sipmsg_breakdown_free(struct sipmsg_breakdown * msg)
101 if (msg->protocol != empty_string)
102 g_free(msg->protocol);
103 if (msg->rand != empty_string)
104 g_free(msg->rand);
105 if (msg->num != empty_string)
106 g_free(msg->num);
107 if (msg->realm != empty_string)
108 g_free(msg->realm);
109 if (msg->target_name != empty_string)
110 g_free(msg->target_name);
112 // straight from header
113 //g_free(msg->call_id);
115 if (msg->cseq != empty_string)
116 g_free(msg->cseq);
117 if (msg->from_url != empty_string)
118 g_free(msg->from_url);
119 if (msg->from_tag != empty_string)
120 g_free(msg->from_tag);
121 if (msg->to_url != empty_string)
122 g_free(msg->to_url);
123 if (msg->to_tag != empty_string)
124 g_free(msg->to_tag);
126 if (msg->p_assertet_identity_sip_uri != empty_string)
127 g_free(msg->p_assertet_identity_sip_uri);
128 if (msg->p_assertet_identity_tel_uri != empty_string)
129 g_free(msg->p_assertet_identity_tel_uri);
131 // straight from header
132 //g_free (msg->expires);
135 gchar *
136 sipmsg_breakdown_get_string(int version,
137 struct sipmsg_breakdown * msgbd)
139 gchar *response_str;
140 gchar *msg;
141 if (msgbd->realm == empty_string || msgbd->realm == NULL) {
142 SIPE_DEBUG_INFO_NOFORMAT("realm NULL, so returning NULL signature string");
143 return NULL;
146 response_str = msgbd->msg->response != 0 ? g_strdup_printf("<%d>", msgbd->msg->response) : empty_string;
147 if (version < 3) {
148 msg = g_strdup_printf(
149 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 11
150 "<%s>%s", // 12 - 13
151 msgbd->protocol, msgbd->rand, msgbd->num, msgbd->realm, msgbd->target_name, msgbd->call_id, msgbd->cseq,
152 msgbd->msg->method, msgbd->from_url, msgbd->from_tag, msgbd->to_tag,
153 msgbd->expires ? msgbd->expires : empty_string, response_str
155 } else {
156 msg = g_strdup_printf(
157 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 14
158 "<%s>%s", // 15 - 16
159 msgbd->protocol, msgbd->rand, msgbd->num, msgbd->realm, msgbd->target_name, msgbd->call_id, msgbd->cseq,
160 msgbd->msg->method, msgbd->from_url, msgbd->from_tag, msgbd->to_url, msgbd->to_tag,
161 msgbd->p_assertet_identity_sip_uri, msgbd->p_assertet_identity_tel_uri,
162 msgbd->expires ? msgbd->expires : empty_string, response_str
166 if (response_str != empty_string) {
167 g_free(response_str);
170 return msg;
174 Local Variables:
175 mode: c
176 c-file-style: "bsd"
177 indent-tabs-mode: t
178 tab-width: 8
179 End: