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

Function mq_head_add

modules/mqueue/mqueue_api.c:100–152  ·  view source on GitHub ↗

* */

Source from the content-addressed store, hash-verified

98 *
99 */
100int mq_head_add(str *name, int msize, int addmode)
101{
102 mq_head_t *mh = NULL;
103 mq_pv_t *mp = NULL;
104 int len;
105
106 mh = _mq_head_list;
107 while(mh != NULL) {
108 if(name->len == mh->name.len
109 && strncmp(mh->name.s, name->s, name->len) == 0) {
110 LM_ERR("mqueue redefined: %.*s\n", name->len, name->s);
111 return -1;
112 }
113 mh = mh->next;
114 }
115
116 mp = (mq_pv_t *)pkg_malloc(sizeof(mq_pv_t));
117 if(mp == NULL) {
118 LM_ERR("no more pkg for: %.*s\n", name->len, name->s);
119 return -1;
120 }
121 memset(mp, 0, sizeof(mq_pv_t));
122
123 len = sizeof(mq_head_t) + name->len + 1;
124 mh = (mq_head_t *)shm_malloc(len);
125 if(mh == NULL) {
126 LM_ERR("no more shm for: %.*s\n", name->len, name->s);
127 pkg_free(mp);
128 return -1;
129 }
130 memset(mh, 0, len);
131 if(lock_init(&mh->lock) == 0) {
132 LM_CRIT("failed to init lock\n");
133 pkg_free(mp);
134 shm_free(mh);
135 return -1;
136 }
137
138 mh->name.s = (char *)mh + sizeof(mq_head_t);
139 memcpy(mh->name.s, name->s, name->len);
140 mh->name.len = name->len;
141 mh->name.s[name->len] = '\0';
142 mh->msize = msize;
143 mh->addmode = addmode;
144 mh->next = _mq_head_list;
145 _mq_head_list = mh;
146
147 mp->name = &mh->name;
148 mp->next = _mq_pv_list;
149 _mq_pv_list = mp;
150
151 return 0;
152}
153
154/**
155 *

Callers 1

mq_paramFunction · 0.85

Calls 3

shm_mallocFunction · 0.85
lock_initFunction · 0.85
shm_freeFunction · 0.85

Tested by

no test coverage detected