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
28 #include "sipe-sign.h"
30 static gchar
* const empty_string
= "";
32 void sipmsg_breakdown_parse(struct sipmsg_breakdown
* msg
, gchar
* realm
, gchar
* target
)
35 if (msg
== NULL
|| msg
->msg
== NULL
) {
36 purple_debug(PURPLE_DEBUG_MISC
, "sipmsg_breakdown_parse msg or msg->msg is NULL", "\n");
40 msg
->rand
= msg
->num
= msg
->realm
= msg
->target_name
=
41 msg
->cseq
= msg
->from_url
= msg
->from_tag
= msg
->to_url
= msg
->to_tag
=
42 msg
->p_assertet_identity_sip_uri
= msg
->p_assertet_identity_tel_uri
= empty_string
;
43 msg
->call_id
= msg
->expires
= empty_string
;
45 if ((hdr
= sipmsg_find_header(msg
->msg
, "Proxy-Authorization")) ||
46 (hdr
= sipmsg_find_header(msg
->msg
, "Proxy-Authenticate")) ||
47 (hdr
= sipmsg_find_header(msg
->msg
, "Proxy-Authentication-Info")) ||
48 (hdr
= sipmsg_find_header(msg
->msg
, "Authentication-Info")) ) {
49 msg
->protocol
= sipmsg_find_part_of_header(hdr
, NULL
, " ", empty_string
);
50 msg
->rand
= sipmsg_find_part_of_header(hdr
, "rand=\"", "\"", empty_string
);
51 msg
->num
= sipmsg_find_part_of_header(hdr
, "num=\"", "\"", empty_string
);
52 msg
->realm
= sipmsg_find_part_of_header(hdr
, "realm=\"", "\"", empty_string
);
53 msg
->target_name
= sipmsg_find_part_of_header(hdr
, "targetname=\"", "\"", empty_string
);
55 msg
->protocol
= strstr(target
, "sip/") ? g_strdup("Kerberos") : g_strdup("NTLM");
56 msg
->realm
= g_strdup(realm
);
57 msg
->target_name
= g_strdup(target
);
60 msg
->call_id
= sipmsg_find_header(msg
->msg
, "Call-ID");
62 hdr
= sipmsg_find_header(msg
->msg
, "CSeq");
64 msg
->cseq
= sipmsg_find_part_of_header(hdr
, NULL
, " ", empty_string
);
67 hdr
= sipmsg_find_header(msg
->msg
, "From");
69 msg
->from_url
= sipmsg_find_part_of_header(hdr
, "<", ">", empty_string
);
70 msg
->from_tag
= sipmsg_find_part_of_header(hdr
, ";tag=", ";", empty_string
);
73 hdr
= sipmsg_find_header(msg
->msg
, "To");
75 msg
->to_url
= sipmsg_find_part_of_header(hdr
, "<", ">", empty_string
);
76 msg
->to_tag
= sipmsg_find_part_of_header(hdr
, ";tag=", ";", empty_string
);
79 P-Asserted-Identity: "Cullen Jennings" <sip:fluffy@cisco.com>
80 P-Asserted-Identity: tel:+14085264000
82 hdr
= sipmsg_find_header(msg
->msg
, "P-Asserted-Identity");
84 hdr
= sipmsg_find_header(msg
->msg
, "P-Preferred-Identity");
87 gchar
*tmp
= sipmsg_find_part_of_header(hdr
, "<", ">", empty_string
);
88 if (g_str_has_prefix(tmp
, "sip:")) {
89 msg
->p_assertet_identity_sip_uri
= tmp
;
90 } else if (g_str_has_prefix(tmp
, "tel:")){
91 msg
->p_assertet_identity_tel_uri
= tmp
;
97 msg
->expires
= sipmsg_find_header(msg
->msg
, "Expires");
101 sipmsg_breakdown_free(struct sipmsg_breakdown
* msg
)
103 if (msg
->protocol
!= empty_string
)
104 g_free(msg
->protocol
);
105 if (msg
->rand
!= empty_string
)
107 if (msg
->num
!= empty_string
)
109 if (msg
->realm
!= empty_string
)
111 if (msg
->target_name
!= empty_string
)
112 g_free(msg
->target_name
);
114 // straight from header
115 //g_free(msg->call_id);
117 if (msg
->cseq
!= empty_string
)
119 if (msg
->from_url
!= empty_string
)
120 g_free(msg
->from_url
);
121 if (msg
->from_tag
!= empty_string
)
122 g_free(msg
->from_tag
);
123 if (msg
->to_url
!= empty_string
)
125 if (msg
->to_tag
!= empty_string
)
128 if (msg
->p_assertet_identity_sip_uri
!= empty_string
)
129 g_free(msg
->p_assertet_identity_sip_uri
);
130 if (msg
->p_assertet_identity_tel_uri
!= empty_string
)
131 g_free(msg
->p_assertet_identity_tel_uri
);
133 // straight from header
134 //g_free (msg->expires);
138 sipmsg_breakdown_get_string(int version
,
139 struct sipmsg_breakdown
* msgbd
)
143 if (msgbd
->realm
== empty_string
|| msgbd
->realm
== NULL
) {
144 purple_debug(PURPLE_DEBUG_MISC
, "sipe", "realm NULL, so returning NULL signature string\n");
148 response_str
= msgbd
->msg
->response
!= 0 ? g_strdup_printf("<%d>", msgbd
->msg
->response
) : empty_string
;
150 msg
= g_strdup_printf(
151 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 11
153 msgbd
->protocol
, msgbd
->rand
, msgbd
->num
, msgbd
->realm
, msgbd
->target_name
, msgbd
->call_id
, msgbd
->cseq
,
154 msgbd
->msg
->method
, msgbd
->from_url
, msgbd
->from_tag
, msgbd
->to_tag
,
155 msgbd
->expires
? msgbd
->expires
: empty_string
, response_str
158 msg
= g_strdup_printf(
159 "<%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s><%s>" // 1 - 14
161 msgbd
->protocol
, msgbd
->rand
, msgbd
->num
, msgbd
->realm
, msgbd
->target_name
, msgbd
->call_id
, msgbd
->cseq
,
162 msgbd
->msg
->method
, msgbd
->from_url
, msgbd
->from_tag
, msgbd
->to_url
, msgbd
->to_tag
,
163 msgbd
->p_assertet_identity_sip_uri
, msgbd
->p_assertet_identity_tel_uri
,
164 msgbd
->expires
? msgbd
->expires
: empty_string
, response_str
168 if (response_str
!= empty_string
) {
169 g_free(response_str
);