~ubuntu-branches/debian/sid/kamailio/sid

« back to all changes in this revision

Viewing changes to .pc/spelling_errors.patch/modules/presence/hash.c

  • Committer: Package Import Robot
  • Author(s): Victor Seva
  • Date: 2014-01-06 11:47:13 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140106114713-t8xidp4arzrnyeya
Tags: 4.1.1-1
* New upstream release
* debian/patches:
  - add upstream fixes
* Added tls outbound websocket autheph dnssec modules
  - openssl exception added to their license
* removing sparc and ia64 from supported archs
  for mono module (Closes: #728915)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: hash.c 2583 2007-08-08 11:33:25Z anca_vamanu $
3
 
 *
4
 
 * presence module - presence server implementation
5
 
 *
6
 
 * Copyright (C) 2007 Voice Sistem S.R.L.
7
 
 *
8
 
 * This file is part of Kamailio, a free SIP server.
9
 
 *
10
 
 * Kamailio is free software; you can redistribute it and/or modify
11
 
 * it under the terms of the GNU General Public License as published by
12
 
 * the Free Software Foundation; either version 2 of the License, or
13
 
 * (at your option) any later version
14
 
 *
15
 
 * Kamailio is distributed in the hope that it will be useful,
16
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 * GNU General Public License for more details.
19
 
 *
20
 
 * You should have received a copy of the GNU General Public License 
21
 
 * along with this program; if not, write to the Free Software 
22
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
 
 *
24
 
 * History:
25
 
 * --------
26
 
 *  2007-08-20  initial version (Anca Vamanu)
27
 
 */
28
 
 
29
 
/*! \file
30
 
 * \brief Kamailio presence module
31
 
 * \ingroup presence 
32
 
 */
33
 
 
34
 
#include <stdio.h>
35
 
#include <stdlib.h>
36
 
#include "../../mem/shm_mem.h"
37
 
#include "../../hashes.h"
38
 
#include "../../dprint.h"
39
 
#include "../../str.h"
40
 
#include "../pua/hash.h"
41
 
#include "presence.h"
42
 
#include "hash.h"
43
 
#include "notify.h"
44
 
 
45
 
shtable_t new_shtable(int hash_size)
46
 
{
47
 
        shtable_t htable= NULL;
48
 
        int i, j;
49
 
 
50
 
        i = 0;
51
 
        htable= (subs_entry_t*)shm_malloc(hash_size* sizeof(subs_entry_t));
52
 
        if(htable== NULL)
53
 
        {
54
 
                ERR_MEM(SHARE_MEM);
55
 
        }
56
 
        memset(htable, 0, hash_size* sizeof(subs_entry_t));
57
 
        for(i= 0; i< hash_size; i++)
58
 
        {
59
 
                if(lock_init(&htable[i].lock)== 0)
60
 
                {
61
 
                        LM_ERR("initializing lock [%d]\n", i);
62
 
                        goto error;
63
 
                }
64
 
                htable[i].entries= (subs_t*)shm_malloc(sizeof(subs_t));
65
 
                if(htable[i].entries== NULL)
66
 
                {
67
 
                        lock_destroy(&htable[i].lock);
68
 
                        ERR_MEM(SHARE_MEM);
69
 
                }
70
 
                memset(htable[i].entries, 0, sizeof(subs_t));
71
 
                htable[i].entries->next= NULL;
72
 
        }
73
 
 
74
 
        return htable;
75
 
 
76
 
error:
77
 
        if(htable)
78
 
        {
79
 
                for(j=0; j< i; j++)
80
 
                {
81
 
                        lock_destroy(&htable[j].lock);
82
 
                        shm_free(htable[j].entries);
83
 
                }
84
 
                shm_free(htable);
85
 
        }
86
 
        return NULL;
87
 
 
88
 
}
89
 
 
90
 
void destroy_shtable(shtable_t htable, int hash_size)
91
 
{
92
 
        int i;
93
 
 
94
 
        if(htable== NULL)
95
 
                return;
96
 
 
97
 
        for(i= 0; i< hash_size; i++)
98
 
        {
99
 
                lock_destroy(&htable[i].lock);
100
 
                free_subs_list(htable[i].entries->next, SHM_MEM_TYPE, 1);
101
 
                shm_free(htable[i].entries);
102
 
        }
103
 
        shm_free(htable);
104
 
        htable= NULL;
105
 
}
106
 
 
107
 
subs_t* search_shtable(shtable_t htable,str callid,str to_tag,
108
 
                str from_tag,unsigned int hash_code)
109
 
{
110
 
        subs_t* s;
111
 
 
112
 
        s= htable[hash_code].entries->next;
113
 
 
114
 
        while(s)
115
 
        {
116
 
                if(s->callid.len==callid.len &&
117
 
                                strncmp(s->callid.s, callid.s, callid.len)==0 &&
118
 
                        s->to_tag.len== to_tag.len &&
119
 
                                strncmp(s->to_tag.s, to_tag.s, to_tag.len)==0 &&
120
 
                        s->from_tag.len== from_tag.len &&
121
 
                                strncmp(s->from_tag.s, from_tag.s, from_tag.len)== 0)
122
 
                        return s;
123
 
                s= s->next;
124
 
        }
125
 
 
126
 
        return NULL;
127
 
}
128
 
 
129
 
subs_t* mem_copy_subs(subs_t* s, int mem_type)
130
 
{
131
 
        int size;
132
 
        subs_t* dest;
133
 
 
134
 
        size= sizeof(subs_t)+ (s->pres_uri.len+ s->to_user.len
135
 
                + s->to_domain.len+ s->from_user.len+ s->from_domain.len+ s->callid.len
136
 
                + s->to_tag.len+ s->from_tag.len+s->sockinfo_str.len+s->event_id.len
137
 
                + s->local_contact.len+ s->contact.len+ s->record_route.len
138
 
                + s->reason.len+ s->watcher_user.len+ s->watcher_domain.len
139
 
                + 1)*sizeof(char);
140
 
 
141
 
        if(mem_type & PKG_MEM_TYPE)
142
 
                dest= (subs_t*)pkg_malloc(size);
143
 
        else
144
 
                dest= (subs_t*)shm_malloc(size);
145
 
 
146
 
        if(dest== NULL)
147
 
        {
148
 
                ERR_MEM((mem_type==PKG_MEM_TYPE)?PKG_MEM_STR:SHARE_MEM);
149
 
        }
150
 
        memset(dest, 0, size);
151
 
        size= sizeof(subs_t);
152
 
 
153
 
        CONT_COPY(dest, dest->pres_uri, s->pres_uri)
154
 
        CONT_COPY(dest, dest->to_user, s->to_user)
155
 
        CONT_COPY(dest, dest->to_domain, s->to_domain)
156
 
        CONT_COPY(dest, dest->from_user, s->from_user)
157
 
        CONT_COPY(dest, dest->from_domain, s->from_domain)
158
 
        CONT_COPY(dest, dest->watcher_user, s->watcher_user)
159
 
        CONT_COPY(dest, dest->watcher_domain, s->watcher_domain)
160
 
        CONT_COPY(dest, dest->to_tag, s->to_tag)
161
 
        CONT_COPY(dest, dest->from_tag, s->from_tag)
162
 
        CONT_COPY(dest, dest->callid, s->callid)
163
 
        CONT_COPY(dest, dest->sockinfo_str, s->sockinfo_str)
164
 
        CONT_COPY(dest, dest->local_contact, s->local_contact)
165
 
        CONT_COPY(dest, dest->contact, s->contact)
166
 
        CONT_COPY(dest, dest->record_route, s->record_route)
167
 
        if(s->event_id.s)
168
 
                CONT_COPY(dest, dest->event_id, s->event_id)
169
 
        if(s->reason.s)
170
 
                CONT_COPY(dest, dest->reason, s->reason)
171
 
 
172
 
        dest->event= s->event;
173
 
        dest->local_cseq= s->local_cseq;
174
 
        dest->remote_cseq= s->remote_cseq;
175
 
        dest->status= s->status;
176
 
        dest->version= s->version;
177
 
        dest->send_on_cback= s->send_on_cback;
178
 
        dest->expires= s->expires;
179
 
        dest->db_flag= s->db_flag;
180
 
 
181
 
        return dest;
182
 
 
183
 
error:
184
 
        if(dest)
185
 
        {
186
 
                if(mem_type & PKG_MEM_TYPE)
187
 
                        pkg_free(dest);
188
 
                else
189
 
                        shm_free(dest);
190
 
        }
191
 
        return NULL;
192
 
}
193
 
 
194
 
 
195
 
subs_t* mem_copy_subs_noc(subs_t* s)
196
 
{
197
 
        int size;
198
 
        subs_t* dest;
199
 
 
200
 
        size= sizeof(subs_t)+ (s->pres_uri.len+ s->to_user.len
201
 
                + s->to_domain.len+ s->from_user.len+ s->from_domain.len+ s->callid.len
202
 
                + s->to_tag.len+ s->from_tag.len+s->sockinfo_str.len+s->event_id.len
203
 
                + s->local_contact.len + s->record_route.len+
204
 
                + s->reason.len+ s->watcher_user.len+ s->watcher_domain.len
205
 
                + 1)*sizeof(char);
206
 
 
207
 
        dest= (subs_t*)shm_malloc(size);
208
 
        if(dest== NULL)
209
 
        {
210
 
                ERR_MEM(SHARE_MEM);
211
 
        }
212
 
        memset(dest, 0, size);
213
 
        size= sizeof(subs_t);
214
 
 
215
 
        CONT_COPY(dest, dest->pres_uri, s->pres_uri)
216
 
        CONT_COPY(dest, dest->to_user, s->to_user)
217
 
        CONT_COPY(dest, dest->to_domain, s->to_domain)
218
 
        CONT_COPY(dest, dest->from_user, s->from_user)
219
 
        CONT_COPY(dest, dest->from_domain, s->from_domain)
220
 
        CONT_COPY(dest, dest->watcher_user, s->watcher_user)
221
 
        CONT_COPY(dest, dest->watcher_domain, s->watcher_domain)
222
 
        CONT_COPY(dest, dest->to_tag, s->to_tag)
223
 
        CONT_COPY(dest, dest->from_tag, s->from_tag)
224
 
        CONT_COPY(dest, dest->callid, s->callid)
225
 
        CONT_COPY(dest, dest->sockinfo_str, s->sockinfo_str)
226
 
        CONT_COPY(dest, dest->local_contact, s->local_contact)
227
 
        CONT_COPY(dest, dest->record_route, s->record_route)
228
 
        if(s->event_id.s)
229
 
                CONT_COPY(dest, dest->event_id, s->event_id)
230
 
        if(s->reason.s)
231
 
                CONT_COPY(dest, dest->reason, s->reason)
232
 
 
233
 
        dest->event= s->event;
234
 
        dest->local_cseq= s->local_cseq;
235
 
        dest->remote_cseq= s->remote_cseq;
236
 
        dest->status= s->status;
237
 
        dest->version= s->version;
238
 
        dest->send_on_cback= s->send_on_cback;
239
 
        dest->expires= s->expires;
240
 
        dest->db_flag= s->db_flag;
241
 
 
242
 
        dest->contact.s= (char*)shm_malloc(s->contact.len* sizeof(char));
243
 
        if(dest->contact.s== NULL)
244
 
        {
245
 
                ERR_MEM(SHARE_MEM);
246
 
        }
247
 
        memcpy(dest->contact.s, s->contact.s, s->contact.len);
248
 
        dest->contact.len= s->contact.len;
249
 
 
250
 
        return dest;
251
 
 
252
 
error:
253
 
        if(dest)
254
 
                        shm_free(dest);
255
 
        return NULL;
256
 
}
257
 
 
258
 
int insert_shtable(shtable_t htable,unsigned int hash_code, subs_t* subs)
259
 
{
260
 
        subs_t* new_rec= NULL;
261
 
 
262
 
        new_rec= mem_copy_subs_noc(subs);
263
 
        if(new_rec== NULL)
264
 
        {
265
 
                LM_ERR("copying in share memory a subs_t structure\n");
266
 
                return -1;
267
 
        }
268
 
        new_rec->expires+= (int)time(NULL);
269
 
 
270
 
        lock_get(&htable[hash_code].lock);
271
 
        new_rec->next= htable[hash_code].entries->next;
272
 
        htable[hash_code].entries->next= new_rec;
273
 
        lock_release(&htable[hash_code].lock);
274
 
 
275
 
        return 0;
276
 
}
277
 
 
278
 
int delete_shtable(shtable_t htable,unsigned int hash_code,str to_tag)
279
 
{
280
 
        subs_t* s= NULL, *ps= NULL;
281
 
        int found= -1;
282
 
 
283
 
        lock_get(&htable[hash_code].lock);
284
 
        
285
 
        ps= htable[hash_code].entries;
286
 
        s= ps->next;
287
 
                
288
 
        while(s)
289
 
        {
290
 
                if(s->to_tag.len== to_tag.len &&
291
 
                                strncmp(s->to_tag.s, to_tag.s, to_tag.len)== 0)
292
 
                {
293
 
                        found= s->local_cseq +1;
294
 
                        ps->next= s->next;
295
 
                        if(s->contact.s!=NULL)
296
 
                                shm_free(s->contact.s);
297
 
                        shm_free(s);
298
 
                        break;
299
 
                }
300
 
                ps= s;
301
 
                s= s->next;
302
 
        }
303
 
        lock_release(&htable[hash_code].lock);
304
 
        return found;
305
 
}
306
 
 
307
 
void free_subs_list(subs_t* s_array, int mem_type, int ic)
308
 
{
309
 
        subs_t* s;
310
 
 
311
 
        while(s_array)
312
 
        {
313
 
                s= s_array;
314
 
                s_array= s_array->next;
315
 
                if(mem_type & PKG_MEM_TYPE)
316
 
                {
317
 
                        if(ic)
318
 
                                pkg_free(s->contact.s);
319
 
                        pkg_free(s);
320
 
                }
321
 
                else
322
 
                {
323
 
                        if(ic)
324
 
                                shm_free(s->contact.s);
325
 
                        shm_free(s);
326
 
                }
327
 
        }
328
 
        
329
 
}
330
 
 
331
 
int update_shtable(shtable_t htable,unsigned int hash_code, 
332
 
                subs_t* subs, int type)
333
 
{
334
 
        subs_t* s;
335
 
 
336
 
        lock_get(&htable[hash_code].lock);
337
 
 
338
 
        s= search_shtable(htable,subs->callid, subs->to_tag, subs->from_tag,
339
 
                        hash_code);
340
 
        if(s== NULL)
341
 
        {
342
 
                LM_DBG("record not found in hash table\n");
343
 
                lock_release(&htable[hash_code].lock);
344
 
                return -1;
345
 
        }
346
 
 
347
 
        if(type & REMOTE_TYPE)
348
 
        {
349
 
                s->expires= subs->expires+ (int)time(NULL);
350
 
                s->remote_cseq= subs->remote_cseq;
351
 
        }
352
 
        else
353
 
        {
354
 
                subs->local_cseq = ++s->local_cseq;
355
 
                subs->version = ++s->version;
356
 
        }
357
 
        
358
 
        if(strncmp(s->contact.s, subs->contact.s, subs->contact.len))
359
 
        {
360
 
                shm_free(s->contact.s);
361
 
                s->contact.s= (char*)shm_malloc(subs->contact.len* sizeof(char));
362
 
                if(s->contact.s== NULL)
363
 
                {
364
 
                        lock_release(&htable[hash_code].lock);
365
 
                        LM_ERR("no more shared memory\n");
366
 
                        return -1;
367
 
                }
368
 
                memcpy(s->contact.s, subs->contact.s, subs->contact.len);
369
 
                s->contact.len= subs->contact.len;
370
 
        }
371
 
 
372
 
        s->status= subs->status;
373
 
        s->event= subs->event;
374
 
        subs->db_flag= s->db_flag;
375
 
 
376
 
        if(s->db_flag & NO_UPDATEDB_FLAG)
377
 
                s->db_flag= UPDATEDB_FLAG;
378
 
 
379
 
        lock_release(&htable[hash_code].lock);
380
 
        
381
 
        return 0;
382
 
}
383
 
 
384
 
phtable_t* new_phtable(void)
385
 
{
386
 
        phtable_t* htable= NULL;
387
 
        int i, j;
388
 
 
389
 
        i = 0;
390
 
        htable= (phtable_t*)shm_malloc(phtable_size* sizeof(phtable_t));
391
 
        if(htable== NULL)
392
 
        {
393
 
                ERR_MEM(SHARE_MEM);
394
 
        }
395
 
        memset(htable, 0, phtable_size* sizeof(phtable_t));
396
 
 
397
 
        for(i= 0; i< phtable_size; i++)
398
 
        {
399
 
                if(lock_init(&htable[i].lock)== 0)
400
 
                {
401
 
                        LM_ERR("initializing lock [%d]\n", i);
402
 
                        goto error;
403
 
                }
404
 
                htable[i].entries= (pres_entry_t*)shm_malloc(sizeof(pres_entry_t));
405
 
                if(htable[i].entries== NULL)
406
 
                {
407
 
                        ERR_MEM(SHARE_MEM);
408
 
                }
409
 
                memset(htable[i].entries, 0, sizeof(pres_entry_t));
410
 
                htable[i].entries->next= NULL;
411
 
        }
412
 
 
413
 
        return htable;
414
 
 
415
 
error:
416
 
        if(htable)
417
 
        {
418
 
                for(j=0; j< i; j++)
419
 
                {
420
 
                        if(htable[i].entries)
421
 
                                shm_free(htable[i].entries);
422
 
                        else 
423
 
                                break;
424
 
                        lock_destroy(&htable[i].lock);
425
 
                }
426
 
                shm_free(htable);
427
 
        }
428
 
        return NULL;
429
 
 
430
 
}
431
 
 
432
 
void destroy_phtable(void)
433
 
{
434
 
        int i;
435
 
        pres_entry_t* p, *prev_p;
436
 
 
437
 
        if(pres_htable== NULL)
438
 
                return;
439
 
 
440
 
        for(i= 0; i< phtable_size; i++)
441
 
        {
442
 
                lock_destroy(&pres_htable[i].lock);
443
 
                p= pres_htable[i].entries;
444
 
                while(p)
445
 
                {
446
 
                        prev_p= p;
447
 
                        p= p->next;
448
 
                        if(prev_p->sphere)
449
 
                                shm_free(prev_p->sphere);
450
 
                        shm_free(prev_p);
451
 
                }
452
 
        }
453
 
        shm_free(pres_htable);
454
 
}
455
 
/* entry must be locked before calling this function */
456
 
 
457
 
pres_entry_t* search_phtable(str* pres_uri,int event, unsigned int hash_code)
458
 
{
459
 
        pres_entry_t* p;
460
 
 
461
 
        LM_DBG("pres_uri= %.*s\n", pres_uri->len,  pres_uri->s);
462
 
        p= pres_htable[hash_code].entries->next;
463
 
        while(p)
464
 
        {
465
 
                if(p->event== event && p->pres_uri.len== pres_uri->len &&
466
 
                                strncmp(p->pres_uri.s, pres_uri->s, pres_uri->len)== 0 )
467
 
                        return p;
468
 
                p= p->next;
469
 
        }
470
 
        return NULL;
471
 
}
472
 
 
473
 
int insert_phtable(str* pres_uri, int event, char* sphere)
474
 
{
475
 
        unsigned int hash_code;
476
 
        pres_entry_t* p= NULL;
477
 
        int size;
478
 
 
479
 
        hash_code= core_hash(pres_uri, NULL, phtable_size);
480
 
 
481
 
        lock_get(&pres_htable[hash_code].lock);
482
 
        
483
 
        p= search_phtable(pres_uri, event, hash_code);
484
 
        if(p)
485
 
        {
486
 
                p->publ_count++;
487
 
                lock_release(&pres_htable[hash_code].lock);
488
 
                return 0;
489
 
        }
490
 
        size= sizeof(pres_entry_t)+ pres_uri->len* sizeof(char);
491
 
 
492
 
        p= (pres_entry_t*)shm_malloc(size);
493
 
        if(p== NULL)
494
 
        {
495
 
                lock_release(&pres_htable[hash_code].lock);
496
 
                ERR_MEM(SHARE_MEM);
497
 
        }
498
 
        memset(p, 0, size);
499
 
 
500
 
        size= sizeof(pres_entry_t);
501
 
        p->pres_uri.s= (char*)p+ size;
502
 
        memcpy(p->pres_uri.s, pres_uri->s, pres_uri->len);
503
 
        p->pres_uri.len= pres_uri->len;
504
 
        
505
 
        if(sphere)
506
 
        {
507
 
                p->sphere= (char*)shm_malloc((strlen(sphere)+ 1)*sizeof(char));
508
 
                if(p->sphere== NULL)
509
 
                {
510
 
                        lock_release(&pres_htable[hash_code].lock);
511
 
                        ERR_MEM(SHARE_MEM);
512
 
                }
513
 
                strcpy(p->sphere, sphere);
514
 
        }
515
 
 
516
 
        p->event= event;
517
 
        
518
 
 
519
 
        p->next= pres_htable[hash_code].entries->next;
520
 
        pres_htable[hash_code].entries->next= p;
521
 
 
522
 
        lock_release(&pres_htable[hash_code].lock);
523
 
        
524
 
        return 0;
525
 
 
526
 
error:
527
 
        return -1;
528
 
}
529
 
 
530
 
int delete_phtable(str* pres_uri, int event)
531
 
{
532
 
        unsigned int hash_code;
533
 
        pres_entry_t* p= NULL, *prev_p= NULL;
534
 
 
535
 
        hash_code= core_hash(pres_uri, NULL, phtable_size);
536
 
 
537
 
        lock_get(&pres_htable[hash_code].lock);
538
 
        
539
 
        p= search_phtable(pres_uri, event, hash_code);
540
 
        if(p== NULL)
541
 
        {
542
 
                LM_DBG("record not found\n");
543
 
                lock_release(&pres_htable[hash_code].lock);
544
 
                return 0;
545
 
        }
546
 
        
547
 
        p->publ_count--;
548
 
        if(p->publ_count== 0)
549
 
        {
550
 
                /* delete record */     
551
 
                prev_p= pres_htable[hash_code].entries;
552
 
                while(prev_p->next)
553
 
                {
554
 
                        if(prev_p->next== p)
555
 
                                break;
556
 
                        prev_p= prev_p->next;
557
 
                }
558
 
                if(prev_p->next== NULL)
559
 
                {
560
 
                        LM_ERR("record not found\n");
561
 
                        lock_release(&pres_htable[hash_code].lock);
562
 
                        return -1;
563
 
                }
564
 
                prev_p->next= p->next;
565
 
                if(p->sphere)
566
 
                        shm_free(p->sphere);
567
 
 
568
 
                shm_free(p);
569
 
        }
570
 
        lock_release(&pres_htable[hash_code].lock);
571
 
 
572
 
        return 0;       
573
 
}
574
 
 
575
 
int update_phtable(presentity_t* presentity, str pres_uri, str body)
576
 
{
577
 
        char* sphere= NULL;
578
 
        unsigned int hash_code;
579
 
        pres_entry_t* p;
580
 
        int ret= 0;
581
 
        str* xcap_doc= NULL;
582
 
 
583
 
        /* get new sphere */
584
 
        sphere= extract_sphere(body);
585
 
        if(sphere==NULL)
586
 
        {
587
 
                LM_DBG("no sphere defined in new body\n");
588
 
                return 0;
589
 
        }
590
 
 
591
 
        /* search for record in hash table */
592
 
        hash_code= core_hash(&pres_uri, NULL, phtable_size);
593
 
        
594
 
        lock_get(&pres_htable[hash_code].lock);
595
 
 
596
 
        p= search_phtable(&pres_uri, presentity->event->evp->type, hash_code);
597
 
        if(p== NULL)
598
 
        {
599
 
                lock_release(&pres_htable[hash_code].lock);
600
 
                goto done;
601
 
        }
602
 
        
603
 
        if(p->sphere)
604
 
        {
605
 
                if(strcmp(p->sphere, sphere)!= 0)
606
 
                {
607
 
                        /* new sphere definition */
608
 
                        shm_free(p->sphere);
609
 
                }
610
 
                else
611
 
                {
612
 
                        /* no change in sphere definition */
613
 
                        lock_release(&pres_htable[hash_code].lock);
614
 
                        pkg_free(sphere);
615
 
                        return 0;
616
 
                }
617
 
        
618
 
        }
619
 
 
620
 
 
621
 
        p->sphere= (char*)shm_malloc((strlen(sphere)+ 1)*sizeof(char));
622
 
        if(p->sphere== NULL)
623
 
        {
624
 
                lock_release(&pres_htable[hash_code].lock);
625
 
                ret= -1;
626
 
                goto done;
627
 
        }
628
 
        strcpy(p->sphere, sphere);
629
 
                
630
 
        lock_release(&pres_htable[hash_code].lock);
631
 
 
632
 
        /* call for watchers status update */
633
 
 
634
 
        if(presentity->event->get_rules_doc(&presentity->user, &presentity->domain,
635
 
                                &xcap_doc)< 0)
636
 
        {
637
 
                LM_ERR("failed to retreive xcap document\n");
638
 
                ret= -1;
639
 
                goto done;
640
 
        }
641
 
 
642
 
        update_watchers_status(pres_uri, presentity->event, xcap_doc);
643
 
 
644
 
 
645
 
done:
646
 
 
647
 
        if(xcap_doc)
648
 
        {
649
 
                if(xcap_doc->s)
650
 
                        pkg_free(xcap_doc->s);
651
 
                pkg_free(xcap_doc);
652
 
        }
653
 
 
654
 
        if(sphere)
655
 
                pkg_free(sphere);
656
 
        return ret;
657
 
}