Browse code

PA clarification: - removed unused print_xxx (presentity, ...) functions - statical buffers for presence documents and headers changed to dynamical - FIFO pa.trace command working with new FIFO interface (fifo module) - XCAP queries automaticaly process redirect (libcurl feature) - useful for usage of Apache2 with mod_speling as XCAP server - corrected bug in parsing PIDF (contact is not required now as PUBLISHed by gaim) - other cosmetical changes

Vaclav Kubart authored on 03/01/2006 15:14:17
Showing 7 changed files
... ...
@@ -42,7 +42,7 @@
42 42
 #include "dprint.h"
43 43
 
44 44
 #define ERROR_LOG(a,args...)		LOG(L_ERR,a,##args)
45
-#define DEBUG_LOG(a,args...)		LOG(L_DBG,a,##args)
45
+#define DEBUG_LOG(a,args...)		LOG(L_INFO,a,##args)
46 46
 #define TRACE_LOG(a,args...)		LOG(L_INFO,a,##args)
47 47
 #define WARN_LOG(a,args...)			LOG(L_WARN,a,##args)
48 48
 #define FLUSH_LOG()					do{}while(0)
49 49
new file mode 100644
... ...
@@ -0,0 +1,94 @@
1
+/* 
2
+ * Copyright (C) 2005 iptelorg GmbH
3
+ *
4
+ * This file is part of ser, a free SIP server.
5
+ *
6
+ * ser is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * For a license to use the ser software under conditions
12
+ * other than those described here, or to purchase support for this
13
+ * software, please contact iptel.org by e-mail at the following addresses:
14
+ *    info@iptel.org
15
+ *
16
+ * ser is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program; if not, write to the Free Software
23
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ */
25
+
26
+#include <presence/lpidf.h>
27
+#include <cds/dstring.h>
28
+#include <cds/memory.h>
29
+#include <cds/logger.h>
30
+#include <cds/list.h>
31
+#include <presence/xml_utils.h>
32
+#include <string.h>
33
+
34
+/* ------------------------------ LPIDF document creation ------------------------------ */
35
+
36
+static void doc_add_tuple(dstring_t *buf, presentity_info_t *p, presence_tuple_info_t *t)
37
+{
38
+	char tmp[64];
39
+	
40
+	if (t->status == presence_tuple_closed) return; /* do not append closed tuples */
41
+	
42
+	dstr_append_zt(buf, "Contact: ");
43
+	dstr_append_str(buf, &t->contact);
44
+	dstr_append_zt(buf, ";q=");
45
+	sprintf(tmp, "%1.2f", t->priority);
46
+	dstr_append_zt(buf, tmp);
47
+	dstr_append_zt(buf, "\r\n");
48
+}
49
+
50
+static void doc_add_presentity(dstring_t *buf, presentity_info_t *p)
51
+{
52
+	presence_tuple_info_t *t;
53
+	/* presence_note_t *n; */
54
+
55
+	dstr_append_zt(buf, "To: ");
56
+	dstr_append_str(buf, &p->presentity);
57
+	dstr_append_zt(buf, "\r\n");
58
+	
59
+	t = p->first_tuple;
60
+	while (t) {
61
+		doc_add_tuple(buf, p, t);
62
+		t = t->next;
63
+	}
64
+}
65
+
66
+int create_lpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type)
67
+{
68
+	dstring_t buf;
69
+	
70
+	if (!dst) return -1;
71
+	
72
+	str_clear(dst);
73
+	if (dst_content_type) str_clear(dst_content_type);
74
+
75
+	if (!p) return -1;
76
+	
77
+	if (dst_content_type) 
78
+		str_dup_zt(dst_content_type, "text/lpidf");
79
+
80
+/*	if (!p->first_tuple) return 0;*/	/* no tuples => nothing to say */ 
81
+	
82
+	dstr_init(&buf, 2048);
83
+	
84
+	doc_add_presentity(&buf, p);
85
+	
86
+	dst->len = dstr_get_data_length(&buf);
87
+	dst->s = cds_malloc(dst->len);
88
+	if (!dst->s) dst->len = 0;
89
+	else dstr_get_data(&buf, dst->s);
90
+	dstr_destroy(&buf);
91
+	
92
+	return 0;
93
+}
94
+
0 95
new file mode 100644
... ...
@@ -0,0 +1,34 @@
1
+/* 
2
+ * Copyright (C) 2005 iptelorg GmbH
3
+ *
4
+ * This file is part of ser, a free SIP server.
5
+ *
6
+ * ser is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * For a license to use the ser software under conditions
12
+ * other than those described here, or to purchase support for this
13
+ * software, please contact iptel.org by e-mail at the following addresses:
14
+ *    info@iptel.org
15
+ *
16
+ * ser is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program; if not, write to the Free Software
23
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ */
25
+
26
+#ifndef __PRESENCE_XPIDF_H
27
+#define __PRESENCE_XPIDF_H
28
+
29
+#include <cds/sstr.h>
30
+#include <presence/pres_doc.h>
31
+
32
+int create_lpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type);
33
+
34
+#endif
... ...
@@ -81,7 +81,7 @@ static void doc_add_tuple(dstring_t *buf, presentity_info_t *p, presence_tuple_i
81 81
 
82 82
 static void doc_add_empty_tuple(dstring_t *buf)
83 83
 {
84
-	/* "empty" tuple is needed in PIDF by Microsoft Windows Messenger v. 5.1) */
84
+	/* "empty" tuple is needed in PIDF by Microsoft Windows Messenger v. 5.1 and linphone 1.2) */
85 85
 	DEBUG_LOG("doc_add_empty_tuple()\n");
86 86
 	
87 87
 	dstr_append_zt(buf, "\t<tuple id=\"none\">\r\n");
... ...
@@ -144,7 +144,7 @@ static void doc_add_presentity(dstring_t *buf, presentity_info_t *p, int use_cpi
144 144
 	
145 145
 	DEBUG_LOG("doc_add_presentity(): adding tuples\n");
146 146
 	t = p->first_tuple;
147
-	/* if (!t) doc_add_empty_tuple(buf); */ /* This only for MS? */
147
+	if (!t) doc_add_empty_tuple(buf); /* correction for some strange clients :-) */
148 148
 	while (t) {
149 149
 		doc_add_tuple(buf, p, t);
150 150
 		t = t->next;
... ...
@@ -171,9 +171,13 @@ int create_pidf_document_ex(presentity_info_t *p, str_t *dst, str_t *dst_content
171 171
 
172 172
 	if (!p) return -1;
173 173
 	
174
-	if (dst_content_type) 
175
-		str_dup_zt(dst_content_type, "application/pidf+xml;charset=\"UTF-8\"");
176
-
174
+	if (dst_content_type) {
175
+		if (use_cpim_pidf_ns)
176
+			str_dup_zt(dst_content_type, "application/cpim-pidf+xml");
177
+		else
178
+			str_dup_zt(dst_content_type, "application/pidf+xml;charset=\"UTF-8\"");
179
+	}
180
+	
177 181
 /*	if (!p->first_tuple) return 0;*/	/* no tuples => nothing to say */ 
178 182
 	
179 183
 	dstr_init(&buf, 2048);
... ...
@@ -232,18 +236,21 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst, int ignore_ns
232 236
 	n = find_node(tuple, "contact", ns);
233 237
 	if (!n) {
234 238
 		ERROR_LOG("contact not found\n");
235
-		return -1;
239
+		str_clear(&contact);
240
+		/* return -1; */
241
+	}
242
+	else {
243
+		s = get_attr_value(find_attr(n->properties, "priority"));
244
+		if (s) priority = atof(s);
245
+		s = get_node_value(n);
246
+		contact.s = (char *)s;
247
+		if (s) contact.len = strlen(s);
248
+		else contact.len = 0;
249
+		if (contact.len < 1) {
250
+			ERROR_LOG("empty contact using default\n");
251
+			/* return -1; */
252
+		}	
236 253
 	}
237
-	s = get_attr_value(find_attr(n->properties, "priority"));
238
-	if (s) priority = atof(s);
239
-	s = get_node_value(n);
240
-	contact.s = (char *)s;
241
-	if (s) contact.len = strlen(s);
242
-	else contact.len = 0;
243
-	if (contact.len < 1) {
244
-		ERROR_LOG("empty contact\n");
245
-		return -1;
246
-	}	
247 254
 	
248 255
 	/* process status (only one node) */
249 256
 	n = find_node(tuple, "status", ns);
250 257
new file mode 100644
... ...
@@ -0,0 +1,170 @@
1
+/* 
2
+ * Copyright (C) 2005 iptelorg GmbH
3
+ *
4
+ * This file is part of ser, a free SIP server.
5
+ *
6
+ * ser is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * For a license to use the ser software under conditions
12
+ * other than those described here, or to purchase support for this
13
+ * software, please contact iptel.org by e-mail at the following addresses:
14
+ *    info@iptel.org
15
+ *
16
+ * ser is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program; if not, write to the Free Software
23
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ */
25
+
26
+#include <presence/xpidf.h>
27
+#include <cds/dstring.h>
28
+#include <cds/memory.h>
29
+#include <cds/logger.h>
30
+#include <cds/list.h>
31
+#include <presence/xml_utils.h>
32
+#include <string.h>
33
+
34
+/* ------------------------------ XPIDF document creation ------------------------------ */
35
+
36
+static void doc_add_tuple_note(dstring_t *buf, presence_note_t *n)
37
+{
38
+	DEBUG_LOG("doc_add_tuple_note()\n");
39
+	
40
+	dstr_append_zt(buf, "\t\t\t<note>");
41
+	dstr_append_str(buf, &n->value);	
42
+	dstr_append_zt(buf, "</note>\r\n");
43
+}
44
+
45
+static void doc_add_note(dstring_t *buf, presentity_info_t *p, presence_note_t *n)
46
+{
47
+	DEBUG_LOG("doc_add_note()\n");
48
+	
49
+	dstr_append_zt(buf, "\t<note");
50
+	if (n->lang.len > 0) {
51
+		dstr_append_zt(buf, " lang=\"");
52
+		dstr_append_str(buf, &n->lang);
53
+		dstr_append_zt(buf, "\"");
54
+	}
55
+	dstr_append_zt(buf, ">");
56
+	dstr_append_str(buf, &n->value);	
57
+	dstr_append_zt(buf, "</note>\r\n");
58
+}
59
+
60
+static void doc_add_tuple(dstring_t *buf, presentity_info_t *p, presence_tuple_info_t *t)
61
+{
62
+	presence_note_t *n;
63
+	char tmp[32];
64
+	
65
+	DEBUG_LOG("doc_add_tuple()\n");
66
+	
67
+	dstr_append_zt(buf, "\t<atom id=\"");
68
+	dstr_append_str(buf, &t->id);
69
+	dstr_append_zt(buf, "\">\r\n");
70
+	
71
+	dstr_append_zt(buf, "\t\t<address uri=\"");
72
+	dstr_append_str(buf, &t->contact);
73
+	dstr_append_zt(buf, "\" priority=\"");
74
+/*	dstr_append_zt(buf, ";user=ip\" priority=\"");*/
75
+	sprintf(tmp, "%1.2f", t->priority);
76
+	dstr_append_zt(buf, tmp);
77
+	dstr_append_zt(buf, "\">\r\n");
78
+	if (t->status == presence_tuple_open) dstr_append_zt(buf, "\t\t\t<status status=\"open\"/>\r\n");
79
+	else dstr_append_zt(buf, "\t\t\t<status status=\"closed\"/>\r\n");
80
+	dstr_append_zt(buf, "\t\t</address>\r\n");
81
+
82
+	/* add tuple notes */
83
+	n = t->first_note;
84
+	while (n) {
85
+		doc_add_tuple_note(buf, n);
86
+		n = n->next;
87
+	}
88
+	/* --- */
89
+	
90
+	dstr_append_zt(buf, "\t</atom>\r\n");
91
+}
92
+
93
+static void doc_add_empty_tuple(dstring_t *buf, presentity_info_t *p)
94
+{
95
+	DEBUG_LOG("doc_add_empty_tuple()\n");
96
+	
97
+	dstr_append_zt(buf, "\t<atom id=\"none\">\r\n");
98
+	
99
+	dstr_append_zt(buf, "\t\t<address uri=\"");
100
+	dstr_append_str(buf, &p->presentity);
101
+	dstr_append_zt(buf, "\" priority=\"1\">\r\n");
102
+/*	dstr_append_zt(buf, ";user=ip\" priority=\"1\">\r\n");*/
103
+	dstr_append_zt(buf, "\t\t\t<status status=\"closed\"/>\r\n");
104
+	dstr_append_zt(buf, "\t\t</address>\r\n");
105
+
106
+	dstr_append_zt(buf, "\t</atom>\r\n");
107
+}
108
+
109
+static void doc_add_presentity(dstring_t *buf, presentity_info_t *p)
110
+{
111
+	presence_tuple_info_t *t;
112
+	/* presence_note_t *n; */
113
+
114
+	DEBUG_LOG("doc_add_presentity()\n");
115
+	dstr_append_zt(buf, "<presence>\r\n");
116
+	/* !!! there SHOULD be pres URI of presentity !!! */
117
+	dstr_append_zt(buf, "<presentity uri=\"");
118
+	/* dstr_put_pres_uri(buf, &p->presentity); */
119
+	dstr_append_str(buf, &p->presentity);
120
+	dstr_append_zt(buf, ";method=SUBSCRIBE\"/>\r\n");
121
+	
122
+	DEBUG_LOG("doc_add_presentity(): adding tuples\n");
123
+	t = p->first_tuple;
124
+	if (!t) doc_add_empty_tuple(buf, p);
125
+	while (t) {
126
+		doc_add_tuple(buf, p, t);
127
+		t = t->next;
128
+	}
129
+	
130
+/*	DEBUG_LOG("doc_add_presentity(): adding notes\n");
131
+	n = p->first_note;
132
+	while (n) {
133
+		doc_add_note(buf, p, n);
134
+		n = n->next;
135
+	}
136
+*/
137
+	dstr_append_zt(buf, "</presence>\r\n");
138
+}
139
+
140
+int create_xpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type)
141
+{
142
+	dstring_t buf;
143
+	
144
+	if (!dst) return -1;
145
+	
146
+	str_clear(dst);
147
+	if (dst_content_type) str_clear(dst_content_type);
148
+
149
+	if (!p) return -1;
150
+	
151
+	if (dst_content_type) 
152
+		str_dup_zt(dst_content_type, "application/xpidf+xml;charset=\"UTF-8\"");
153
+
154
+/*	if (!p->first_tuple) return 0;*/	/* no tuples => nothing to say */ 
155
+	
156
+	dstr_init(&buf, 2048);
157
+	
158
+	dstr_append_zt(&buf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
159
+	dstr_append_zt(&buf, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\r\n");
160
+	doc_add_presentity(&buf, p);
161
+	
162
+	dst->len = dstr_get_data_length(&buf);
163
+	dst->s = cds_malloc(dst->len);
164
+	if (!dst->s) dst->len = 0;
165
+	else dstr_get_data(&buf, dst->s);
166
+	dstr_destroy(&buf);
167
+	
168
+	return 0;
169
+}
170
+
0 171
new file mode 100644
... ...
@@ -0,0 +1,34 @@
1
+/* 
2
+ * Copyright (C) 2005 iptelorg GmbH
3
+ *
4
+ * This file is part of ser, a free SIP server.
5
+ *
6
+ * ser is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * For a license to use the ser software under conditions
12
+ * other than those described here, or to purchase support for this
13
+ * software, please contact iptel.org by e-mail at the following addresses:
14
+ *    info@iptel.org
15
+ *
16
+ * ser is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
+ * GNU General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program; if not, write to the Free Software
23
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ */
25
+
26
+#ifndef __PRESENCE_LPIDF_H
27
+#define __PRESENCE_LPIDF_H
28
+
29
+#include <cds/sstr.h>
30
+#include <presence/pres_doc.h>
31
+
32
+int create_xpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type);
33
+
34
+#endif
... ...
@@ -94,6 +94,9 @@ int xcap_query(xcap_query_t *query, char **buf, int *bsize)
94 94
 			curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0);
95 95
 		}
96 96
 		
97
+		/* follow redirects (needed for apache mod_speling - case insesitive names) */
98
+		curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
99
+		
97 100
 		/* Accept headers */
98 101
 		
99 102
 		res = curl_easy_perform(handle);