MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / create_bl_head

Function create_bl_head

blacklists.c:134–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132 CONTEXT_GLOBAL, current_processing_ctx, bl_ctx_idx, value))
133
134struct bl_head *create_bl_head(const str *owner, int flags, struct bl_rule *head,
135 struct bl_rule *tail, str *name)
136{
137 unsigned int i;
138
139 if (!blst_heads) {
140 blst_heads = shm_malloc(max_heads * sizeof *blst_heads);
141 if (!blst_heads) {
142 LM_ERR("no more shared memory!\n");
143 return NULL;
144 }
145 memset(blst_heads, 0, max_heads * sizeof *blst_heads);
146 }
147 i = used_heads;
148 if (i == max_heads) {
149 LM_ERR("too many lists\n");
150 return NULL;
151 }
152
153 if (get_bl_head_by_name(name)) {
154 LM_CRIT("duplicated name!\n");
155 return NULL;
156 }
157
158 if (flags & BL_READONLY_LIST && flags & BL_DO_EXPIRE) {
159 LM_CRIT("RO lists cannot accept EXPIRES!\n");
160 return NULL;
161 }
162
163 /* copy list name */
164 blst_heads[i].name.s = shm_malloc(name->len + 1);
165 if (!blst_heads[i].name.s) {
166 LM_ERR("no more shm memory!\n");
167 return NULL;
168 }
169 memcpy(blst_heads[i].name.s, name->s, name->len);
170 blst_heads[i].name.s[name->len] = '\0';
171 blst_heads[i].name.len = name->len;
172
173 /* build lock? */
174 if (!(flags & BL_READONLY_LIST)) {
175 if (!(blst_heads[i].lock = lock_init_rw())) {
176 LM_ERR("failed to create lock!\n");
177 shm_free(blst_heads[i].name.s);
178 return NULL;
179 }
180 }
181
182 used_heads++;
183
184 blst_heads[i].owner = *owner;
185 blst_heads[i].flags = flags;
186 blst_heads[i].first = head;
187 blst_heads[i].last = tail;
188
189 if (flags & BL_BY_DEFAULT)
190 bl_default_marker |= (1 << i);
191

Callers 4

resolv_blacklist_initFunction · 0.85
init_ds_blsFunction · 0.85
init_lb_blsFunction · 0.85
init_dr_blsFunction · 0.85

Calls 4

shm_mallocFunction · 0.85
get_bl_head_by_nameFunction · 0.85
lock_init_rwFunction · 0.85
shm_freeFunction · 0.85

Tested by

no test coverage detected