modules_k/p_usrloc/dlist.c

Go to the documentation of this file.
00001 /*
00002  * $Id: dlist.c 5160 2008-11-03 17:51:22Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * ========
00024  * 2006-11-28 added get_number_of_users() (Jeffrey Magder - SOMA Networks)
00025  * 2007-09-12 added partitioning support for fetching all ul contacts
00026  *            (bogdan)
00027  */
00028 
00037 #include "dlist.h"
00038 #include <stdlib.h>            /* abort */
00039 #include <string.h>            /* strlen, memcmp */
00040 #include <stdio.h>             /* printf */
00041 #include "../../ut.h"
00042 #include "../../lib/srdb1/db.h"
00043 #include "../../mem/shm_mem.h"
00044 #include "../../dprint.h"
00045 #include "../../ip_addr.h"
00046 #include "../../socket_info.h"
00047 #include "udomain.h"           /* new_udomain, free_udomain */
00048 #include "utime.h"
00049 #include "p_usrloc_mod.h"
00050 
00051 #include "ul_db_layer.h"
00052 
00053 static struct domain_list_item *domain_list;
00054 
00055 
00056 
00057 static inline struct domain_list_item * find_dlist (str *name) {
00058         struct domain_list_item *item;
00059 
00060         for (item = domain_list; item != NULL; item = item->next) {
00061                 if (item->name.len == name->len
00062                         && memcmp (item->name.s, name->s, name->len) == 0) {
00063                         return item;
00064                 }
00065         }
00066         return NULL;
00067 }
00068 
00069 
00070 
00071 
00072 static inline struct domain_list_item * add_to_dlist (str *name, int type) {
00073         struct domain_list_item *item;
00074         int i;
00075         item = (struct domain_list_item *)
00076                pkg_malloc (sizeof (struct domain_list_item));
00077         if (item == NULL) {
00078                 LM_ERR("Out of shared memory.\n");
00079                 return NULL;
00080         }
00081         item->name.s = (char *) pkg_malloc (name->len + 1);
00082         if (item->name.s == NULL) {
00083                 LM_ERR("Out of shared memory.\n");
00084                 return NULL;
00085         }
00086         memcpy (item->name.s, name->s, name->len);
00087         item->name.s[name->len] = '\0';
00088         item->name.len = name->len;
00089 
00090         memset (&item->domain, 0, sizeof (struct udomain));
00091         item->domain.name = &item->name;
00092         item->domain.dbt = type;
00093 
00094         item->domain.table = (hslot_t*)pkg_malloc(sizeof(hslot_t) * ul_hash_size);
00095         if (!item->domain.table) {
00096                 LM_ERR("no memory left 2\n");
00097                 return NULL;
00098         }
00099 
00100         for(i = 0; i < ul_hash_size; i++) {
00101                 init_slot(&item->domain, &(item->domain.table[i]), i);
00102         }
00103 
00104         item->domain.size = ul_hash_size;
00105         /* Everything else is not useful for now.  */
00106 
00107         item->next = domain_list;
00108         domain_list = item;
00109 
00110         return item;
00111 }
00112 
00113 
00124 int register_udomain(const char *name, udomain_t **domain) {
00125         struct domain_list_item *item;
00126         str name_str;
00127         ul_domain_db_t * d;
00128 
00129         name_str.s = (char *) name;
00130         name_str.len = strlen (name);
00131         item = find_dlist (&name_str);
00132         if (item == NULL) {
00133                 if((d = ul_find_domain(name)) == NULL){
00134                         LM_ERR("domain %s not found.\n", name);
00135                         return -1;
00136                 }
00137                 item = add_to_dlist (&name_str, d->dbt);
00138         }
00139         if (item == NULL) {
00140                 return -1;
00141         }
00142         *domain = &item->domain;
00143         LM_DBG("found domain %.*s, type: %s\n", (*domain)->name->len, (*domain)->name->s, (((*domain)->dbt) == DB_TYPE_CLUSTER ? "cluster" : "single"));
00144         return 0;
00145 }
00146 
00147 
00148 
00149 
00154 unsigned long get_number_of_users(void)
00155 {
00156         int numberOfUsers = 0;
00157         LM_INFO("not available with partitioned interface");
00158         return numberOfUsers;
00159 }
00160 
00161 
00162 int get_all_ucontacts(void *buf, int len, unsigned int flags,
00163                          unsigned int part_idx, unsigned int part_max)
00164 {
00165         LM_INFO("not available with partitioned interface");
00166         return -1;
00167 }
00172 int synchronize_all_udomains(void)
00173 {
00174         int res = 0;
00175         LM_INFO("not available with partitioned interface");
00176         return res;
00177 }
00178 
00179