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

Function ql_init

db/db_insertq.c:329–406  ·  view source on GitHub ↗

initializez a new query entry */

Source from the content-addressed store, hash-verified

327
328/* initializez a new query entry */
329query_list_t *ql_init(db_con_t *con,db_key_t *cols,int col_no)
330{
331 int key_size,row_q_size,size,i;
332 char *pos;
333 query_list_t *entry;
334
335 key_size = col_no * sizeof(db_key_t) + col_no * sizeof(str);
336 for (i=0;i<col_no;i++)
337 key_size += cols[i]->len;
338
339 row_q_size = sizeof(db_val_t *) * query_buffer_size;
340 size = sizeof(query_list_t) +
341 counted_max_processes * sizeof(db_con_t *) +
342 con->table->len + key_size + row_q_size + con->url.len;
343
344 entry = shm_malloc(size);
345 if (entry == NULL)
346 {
347 LM_ERR("no more shm\n");
348 return NULL;
349 }
350
351 memset(entry,0,size);
352 LM_DBG("alloced %p for %d bytes\n",entry,size);
353
354 entry->lock = lock_alloc();
355 if (entry->lock == 0)
356 {
357 LM_ERR("failed to alloc lock\n");
358 shm_free(entry);
359 return NULL;
360 }
361
362 if (lock_init(entry->lock) == 0)
363 {
364 LM_ERR("failed to init lock\n");
365 lock_dealloc(entry->lock);
366 shm_free(entry);
367 return NULL;
368 }
369
370 /* deal with the table name */
371 entry->table.s = (char *)entry+sizeof(query_list_t);
372 entry->table.len = con->table->len;
373 memcpy(entry->table.s,con->table->s,con->table->len);
374
375 /* deal with the columns */
376 entry->cols = (db_key_t *)(void *)((char *)entry+sizeof(query_list_t)+
377 con->table->len);
378 entry->col_no = col_no;
379
380 pos = (char *)(entry->cols + col_no) + col_no * sizeof(str);
381 for (i=0;i<col_no;i++)
382 {
383 entry->cols[i] = (str *)(entry->cols + col_no) + i;
384 entry->cols[i]->len = cols[i]->len;
385 entry->cols[i]->s = pos;
386 memcpy(pos,cols[i]->s,cols[i]->len);

Callers 1

con_set_inslistFunction · 0.85

Calls 3

shm_mallocFunction · 0.85
shm_freeFunction · 0.85
lock_initFunction · 0.85

Tested by

no test coverage detected