ソースを参照

little changes (needed by presence_b2b module)

Vaclav Kubart 19 年 前
コミット
2c82fd67d8
7 ファイル変更61 行追加1 行削除
  1. 19 0
      lib/cds/hash_table.c
  2. 3 0
      lib/cds/hash_table.h
  3. 26 0
      lib/cds/sstr.c
  4. 3 0
      lib/cds/sstr.h
  5. 1 1
      lib/presence/pidf.c
  6. 8 0
      lib/presence/pres_doc.h
  7. 1 0
      lib/presence/qsa.h

+ 19 - 0
lib/cds/hash_table.c

@@ -172,3 +172,22 @@ void ht_clear_statistic(hash_table_t *ht)
 	ht->nocmp_cnt = 0;
 	ht->missed_cnt = 0;
 }
+
+/* --------- HASH functions -------- */
+
+unsigned int rshash(const char* str, unsigned int len)
+{
+	unsigned int b = 378551;
+	unsigned int a = 63689;
+	unsigned int hash = 0;
+	unsigned int i = 0;
+
+	for(i = 0; i < len; str++, i++) {
+		hash = hash * a + (*str);
+		a = a * b;
+	}
+
+	return (hash & 0x7FFFFFFF);
+}
+
+

+ 3 - 0
lib/cds/hash_table.h

@@ -74,4 +74,7 @@ ht_data_t ht_find(hash_table_t *ht, ht_key_t key);
 void ht_get_statistic(hash_table_t *ht, ht_statistic_t *s);
 void ht_clear_statistic(hash_table_t *ht);
 
+/* hash functions */
+unsigned int rshash(const char* str, unsigned int len);
+
 #endif

+ 26 - 0
lib/cds/sstr.c

@@ -197,6 +197,32 @@ char *str_strchr(const str_t *s, char c)
 	return NULL;
 }
 
+char *str_str(const str_t *s, const str_t *search_for)
+{
+	int i, j;
+	/* FIXME: reimplement using better algorithm */
+
+	if (is_str_empty(search_for)) return s->s;
+	if (is_str_empty(s)) return NULL;
+	
+	if (search_for->len > s->len) return NULL;
+
+	j = 0;
+	i = 0;
+	while (i < s->len) {
+		if (s->s[i] == search_for->s[j]) {
+			j++;
+			i++;
+			if (i == search_for->len) return s->s + i - j;
+		}
+		else {
+			i = i - j + 1;
+			j = 0;
+		}
+	}
+	return NULL;
+}
+
 /* creates new string as concatenation of a and b */
 int str_concat(str_t *dst, str_t *a, str_t *b)
 {

+ 3 - 0
lib/cds/sstr.h

@@ -102,6 +102,9 @@ void str_clear(str_t *s);
 /** locate character in string */
 char *str_strchr(const str_t *s, char c);
 
+/** locate string in string */
+char *str_str(const str_t *s, const str_t *search_for);
+
 /* creates new string as concatenation of a and b */
 int str_concat(str_t *dst, str_t *a, str_t *b);
 

+ 1 - 1
lib/presence/pidf.c

@@ -251,7 +251,7 @@ static int read_tuple(xmlNode *tuple, presence_tuple_info_t **dst, int ignore_ns
 	/* process contact (only one node) */
 	n = find_node(tuple, "contact", ns);
 	if (!n) {
-		ERROR_LOG("contact not found\n");
+		/* ERROR_LOG("contact not found\n"); */
 		str_clear(&contact);
 		/* return -1; */
 	}

+ 8 - 0
lib/presence/pres_doc.h

@@ -99,6 +99,14 @@ typedef struct {
 	char uri_data[1];
 } list_presence_info_t;
 
+typedef struct {
+	str_t list_uri; /* do not modify this !*/
+
+	str_t pres_doc;
+	str_t content_type;
+	char uri_data[1];
+} presence_info_t;
+
 presentity_info_t *create_presentity_info(const str_t *presentity);
 presence_tuple_info_t *create_tuple_info(const str_t *contact, const str_t *id, presence_tuple_status_t status);
 void add_tuple_info(presentity_info_t *p, presence_tuple_info_t *t);

+ 1 - 0
lib/presence/qsa.h

@@ -30,6 +30,7 @@
 extern "C" {
 #endif
 
+#include <cds/sstr.h>
 #include <presence/notifier_domain.h>
 	
 int qsa_initialize();