Simplify keep alive timeout setting code
[siplcs.git] / src / sipe-sign.c
blob72900be4efed1f6dca143305f2065949b5593e15
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 <glib.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <ctype.h>
28 #ifndef _WIN32
29 #include <et/com_err.h>
30 #else
31 #include <protocols/zephyr/com_err.h>
32 #include "internal.h"
33 #endif
34 #include "debug.h"
35 #include "util.h"
37 #include "sipe-sign.h"
39 static gchar * const empty_string = "";
41 void sipmsg_breakdown_parse(struct sipmsg_breakdown * msg, gchar * realm, gchar * target)
43 gchar * hdr;
44 if (msg == NULL || msg->msg == NULL) {
45 purple_debug(PURPLE_DEBUG_MISC, "sipmsg_breakdown_parse msg or msg->msg is NULL", "\n");
46 return;
50 msg->rand = msg->num = msg->realm = msg->target_name = msg->call_id =
51 msg->cseq = msg->from_url = msg->from_tag = msg->to_tag = msg->expires = empty_string;
53 if ((hdr = sipmsg_find_header(msg->msg, "Proxy-Authorization")) ||
54 (hdr = sipmsg_find_header(msg->msg, "Proxy-Authenticate")) ||
55 (hdr = sipmsg_find_header(msg->msg, "Proxy-Authentication-Info")) ||
56 (hdr = sipmsg_find_header(msg->msg, "Authentication-Info")) ) {
57 msg->rand = sipmsg_find_part_of_header(hdr, "rand=\"", "\"", empty_string);
58 msg->num = sipmsg_find_part_of_header(hdr, "num=\"", "\"", empty_string);
59 msg->realm = sipmsg_find_part_of_header(hdr, "realm=\"", "\"", empty_string);
60 msg->target_name = sipmsg_find_part_of_header(hdr, "targetname=\"", "\"", empty_string);
61 } else {
62 msg->realm = g_strdup(realm);
63 msg->target_name = g_strdup(target);
66 msg->call_id = sipmsg_find_header(msg->msg, "Call-ID");
68 hdr = sipmsg_find_header(msg->msg, "CSeq");
69 if (NULL != hdr) {
70 msg->cseq = sipmsg_find_part_of_header(hdr, NULL, " ", empty_string);
73 hdr = sipmsg_find_header(msg->msg, "From");
74 if (NULL != hdr) {
75 msg->from_url = sipmsg_find_part_of_header(hdr, "<", ">", empty_string);
76 msg->from_tag = sipmsg_find_part_of_header(hdr, ";tag=", ";", empty_string);
79 hdr = sipmsg_find_header(msg->msg, "To");
80 if (NULL != hdr) {
81 msg->to_tag = sipmsg_find_part_of_header(hdr, ";tag=", ";", empty_string);
84 msg->expires = sipmsg_find_header(msg->msg, "Expires");
87 void
88 sipmsg_breakdown_free(struct sipmsg_breakdown * msg)
90 if (msg->rand != empty_string)
91 g_free(msg->rand);
92 if (msg->num != empty_string)
93 g_free(msg->num);
94 if (msg->realm != empty_string)
95 g_free(msg->realm);
96 if (msg->target_name != empty_string)
97 g_free(msg->target_name);
99 // straight from header
100 //g_free(msg->call_id);
102 if (msg->cseq != empty_string)
103 g_free(msg->cseq);
104 if (msg->from_url != empty_string)
105 g_free(msg->from_url);
106 if (msg->from_tag != empty_string)
107 g_free(msg->from_tag);
108 if (msg->to_tag != empty_string)
109 g_free(msg->to_tag);
111 // straight from header
112 //g_free (msg->expires);
115 gchar *
116 sipmsg_breakdown_get_string(struct sipmsg_breakdown * msgbd)
118 gchar *response_str;
119 gchar *msg;
120 if (msgbd->realm == empty_string || msgbd->realm == NULL) {
121 purple_debug(PURPLE_DEBUG_MISC, "sipe", "realm NULL, so returning NULL signature string\n");
122 return NULL;
125 response_str = msgbd->msg->response != 0 ? g_strdup_printf("<%d>", msgbd->msg->response) : empty_string;
126 msg = g_strdup_printf(
127 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 11
128 "<%s>%s", // 12 - 13
129 "NTLM", msgbd->rand, msgbd->num, msgbd->realm, msgbd->target_name, msgbd->call_id, msgbd->cseq,
130 msgbd->msg->method, msgbd->from_url, msgbd->from_tag, msgbd->to_tag,
131 msgbd->expires ? msgbd->expires : empty_string, response_str
134 if (response_str != empty_string) {
135 g_free(response_str);
138 return msg;