xjab_base.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdio.h>
00026 #include <string.h>
00027 #include <stdlib.h>
00028 #include <sys/types.h>
00029 #include <sys/ipc.h>
00030 #include <unistd.h>
00031 #include <fcntl.h>
00032
00033 #include "../../mem/mem.h"
00034 #include "../../mem/shm_mem.h"
00035 #include "../../parser/parse_uri.h"
00036
00037 #include "xjab_base.h"
00038 #include "mdefines.h"
00039
00040
00041
00042
00043
00044 int xj_get_hash(str *x, str *y)
00045 {
00046 char* p;
00047 register unsigned v;
00048 register unsigned h;
00049
00050 if(!x && !y)
00051 return 0;
00052 h=0;
00053 if(x)
00054 {
00055 for (p=x->s; p<=(x->s+x->len-4); p+=4)
00056 {
00057 v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
00058 h+=v^(v>>3);
00059 }
00060 v=0;
00061 for (;p<(x->s+x->len); p++)
00062 {
00063 v<<=8;
00064 v+=*p;
00065 }
00066 h+=v^(v>>3);
00067 }
00068 if(y)
00069 {
00070 for (p=y->s; p<=(y->s+y->len-4); p+=4)
00071 {
00072 v=(*p<<24)+(p[1]<<16)+(p[2]<<8)+p[3];
00073 h+=v^(v>>3);
00074 }
00075
00076 v=0;
00077 for (;p<(y->s+y->len); p++)
00078 {
00079 v<<=8;
00080 v+=*p;
00081 }
00082 h+=v^(v>>3);
00083 }
00084 h=((h)+(h>>11))+((h>>13)+(h>>23));
00085
00086 return (h)?h:1;
00087 }
00088
00089
00090
00091
00092 int xj_jkey_cmp(void *x, void *y)
00093 {
00094 int n;
00095 xj_jkey a, b;
00096 a = (xj_jkey)x;
00097 b = (xj_jkey)y;
00098 if(a == NULL || a->id == NULL || a->id->s == NULL)
00099 return -1;
00100 if(b == NULL || b->id == NULL || b->id->s == NULL)
00101 return 1;
00102
00103
00104 if(a->hash != b->hash)
00105 return (a->hash < b->hash)?-1:1;
00106
00107 if(a->id->len != b->id->len)
00108 return (a->id->len < b->id->len)?-1:1;
00109
00110 n=strncmp(a->id->s,b->id->s,a->id->len);
00111
00112 if(n!=0)
00113 return (n<0)?-1:1;
00114
00115 return 0;
00116 }
00117
00118
00119
00120 void xj_jkey_free_p(void *p)
00121 {
00122 if(p == NULL)
00123 return;
00124 if(((xj_jkey)p)->id != NULL)
00125 {
00126 if(((xj_jkey)p)->id->s != NULL)
00127 _M_SHM_FREE(((xj_jkey)p)->id->s);
00128 _M_SHM_FREE(((xj_jkey)p)->id);
00129 }
00130 _M_SHM_FREE(p);
00131 }
00132
00133
00134
00135
00136
00137 void xj_sipmsg_free(xj_sipmsg jsmsg)
00138 {
00139 if(jsmsg == NULL)
00140 return;
00141 if(jsmsg->to.s != NULL)
00142 _M_SHM_FREE(jsmsg->to.s);
00143
00144
00145
00146 if(jsmsg->msg.s != NULL)
00147 _M_SHM_FREE(jsmsg->msg.s);
00148 _M_SHM_FREE(jsmsg);
00149 }
00150
00151 int xj_extract_aor(str* u, int t)
00152 {
00153 struct sip_uri puri;
00154
00155 if(!u)
00156 return -1;
00157 if (parse_uri(u->s, u->len, &puri) < 0)
00158 {
00159 LM_ERR("failed to parse URI\n");
00160 return -1;
00161 }
00162
00163 if(t == 1)
00164 u->s = puri.user.s;
00165 u->len = puri.host.s + puri.host.len - u->s;
00166 return 0;
00167 }
00168
00169