Browse code

little changes (needed by presence_b2b module)

Vaclav Kubart authored on 17/02/2006 10:14:35
Showing 7 changed files
... ...
@@ -172,3 +172,22 @@ void ht_clear_statistic(hash_table_t *ht)
172 172
 	ht->nocmp_cnt = 0;
173 173
 	ht->missed_cnt = 0;
174 174
 }
175
+
176
+/* --------- HASH functions -------- */
177
+
178
+unsigned int rshash(const char* str, unsigned int len)
179
+{
180
+	unsigned int b = 378551;
181
+	unsigned int a = 63689;
182
+	unsigned int hash = 0;
183
+	unsigned int i = 0;
184
+
185
+	for(i = 0; i < len; str++, i++) {
186
+		hash = hash * a + (*str);
187
+		a = a * b;
188
+	}
189
+
190
+	return (hash & 0x7FFFFFFF);
191
+}
192
+
193
+
... ...
@@ -74,4 +74,7 @@ ht_data_t ht_find(hash_table_t *ht, ht_key_t key);
74 74
 void ht_get_statistic(hash_table_t *ht, ht_statistic_t *s);
75 75
 void ht_clear_statistic(hash_table_t *ht);
76 76
 
77
+/* hash functions */
78
+unsigned int rshash(const char* str, unsigned int len);
79
+
77 80
 #endif
... ...
@@ -197,6 +197,32 @@ char *str_strchr(const str_t *s, char c)
197 197
 	return NULL;
198 198
 }
199 199
 
200
+char *str_str(const str_t *s, const str_t *search_for)
201
+{
202
+	int i, j;
203
+	/* FIXME: reimplement using better algorithm */
204
+
205
+	if (is_str_empty(search_for)) return s->s;
206
+	if (is_str_empty(s)) return NULL;
207
+	
208
+	if (search_for->len > s->len) return NULL;
209
+
210
+	j = 0;
211
+	i = 0;
212
+	while (i < s->len) {
213
+		if (s->s[i] == search_for->s[j]) {
214
+			j++;
215
+			i++;
216
+			if (i == search_for->len) return s->s + i - j;
217
+		}
218
+		else {
219
+			i = i - j + 1;
220
+			j = 0;
221
+		}
222
+	}
223
+	return NULL;
224
+}
225
+
200 226
 /* creates new string as concatenation of a and b */
201 227
 int str_concat(str_t *dst, str_t *a, str_t *b)
202 228
 {
... ...
@@ -102,6 +102,9 @@ void str_clear(str_t *s);
102 102
 /** locate character in string */
103 103
 char *str_strchr(const str_t *s, char c);
104 104
 
105
+/** locate string in string */
106
+char *str_str(const str_t *s, const str_t *search_for);
107
+
105 108
 /* creates new string as concatenation of a and b */
106 109
 int str_concat(str_t *dst, str_t *a, str_t *b);
107 110
 
... ...
@@ -251,7 +251,7 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst, int ignore_ns
251 251
 	/* process contact (only one node) */
252 252
 	n = find_node(tuple, "contact", ns);
253 253
 	if (!n) {
254
-		ERROR_LOG("contact not found\n");
254
+		/* ERROR_LOG("contact not found\n"); */
255 255
 		str_clear(&contact);
256 256
 		/* return -1; */
257 257
 	}
... ...
@@ -99,6 +99,14 @@ typedef struct {
99 99
 	char uri_data[1];
100 100
 } list_presence_info_t;
101 101
 
102
+typedef struct {
103
+	str_t list_uri; /* do not modify this !*/
104
+
105
+	str_t pres_doc;
106
+	str_t content_type;
107
+	char uri_data[1];
108
+} presence_info_t;
109
+
102 110
 presentity_info_t *create_presentity_info(const str_t *presentity);
103 111
 presence_tuple_info_t *create_tuple_info(const str_t *contact, const str_t *id, presence_tuple_status_t status);
104 112
 void add_tuple_info(presentity_info_t *p, presence_tuple_info_t *t);
... ...
@@ -30,6 +30,7 @@
30 30
 extern "C" {
31 31
 #endif
32 32
 
33
+#include <cds/sstr.h>
33 34
 #include <presence/notifier_domain.h>
34 35
 	
35 36
 int qsa_initialize();