! \brief * Create a new domain structure * _n is pointer to str representing * name of the domain, the string is * not copied, it should point to str * structure stored in domain list * _s is hash table size */
| 55 | * _s is hash table size |
| 56 | */ |
| 57 | int new_udomain(str* _n, int _s, udomain_t** _d) |
| 58 | { |
| 59 | int i; |
| 60 | #ifdef STATISTICS |
| 61 | char *name; |
| 62 | #endif |
| 63 | |
| 64 | /* Must be always in shared memory, since |
| 65 | * the cache is accessed from timer which |
| 66 | * lives in a separate process |
| 67 | */ |
| 68 | |
| 69 | *_d = (udomain_t*)shm_malloc(sizeof(udomain_t)); |
| 70 | if (!(*_d)) { |
| 71 | LM_ERR("new_udomain(): No memory left\n"); |
| 72 | goto error0; |
| 73 | } |
| 74 | memset(*_d, 0, sizeof(udomain_t)); |
| 75 | |
| 76 | (*_d)->table = (hslot_t*)shm_malloc(sizeof(hslot_t) * _s); |
| 77 | if (!(*_d)->table) { |
| 78 | LM_ERR("no memory left 2\n"); |
| 79 | goto error1; |
| 80 | } |
| 81 | |
| 82 | (*_d)->name = _n; |
| 83 | |
| 84 | for(i = 0; i < _s; i++) { |
| 85 | if (init_slot(*_d, &((*_d)->table[i]), i) < 0) { |
| 86 | LM_ERR("initializing hash table failed\n"); |
| 87 | goto error2; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | (*_d)->size = _s; |
| 92 | |
| 93 | #ifdef STATISTICS |
| 94 | /* register the statistics */ |
| 95 | if ( (name=build_stat_name(_n,"users"))==0 || register_stat("usrloc", |
| 96 | name, &(*_d)->users, STAT_NO_RESET|STAT_SHM_NAME)!=0 ) { |
| 97 | LM_ERR("failed to add stat variable\n"); |
| 98 | goto error2; |
| 99 | } |
| 100 | if ( (name=build_stat_name(_n,"contacts"))==0 || register_stat("usrloc", |
| 101 | name, &(*_d)->contacts, STAT_NO_RESET|STAT_SHM_NAME)!=0 ) { |
| 102 | LM_ERR("failed to add stat variable\n"); |
| 103 | goto error2; |
| 104 | } |
| 105 | if ( (name=build_stat_name(_n,"expires"))==0 || register_stat("usrloc", |
| 106 | name, &(*_d)->expires, STAT_SHM_NAME)!=0 ) { |
| 107 | LM_ERR("failed to add stat variable\n"); |
| 108 | goto error2; |
| 109 | } |
| 110 | #endif |
| 111 | |
| 112 | return 0; |
| 113 | error2: |
| 114 | shm_free((*_d)->table); |
no test coverage detected