* The function MUST be called only in the pre-forking phases of OpenSIPS * (mod_init() or in function fixups) */
| 170 | * (mod_init() or in function fixups) |
| 171 | */ |
| 172 | int get_flag_id_by_name(int flag_type, char *flag_name, int flag_name_len) |
| 173 | { |
| 174 | struct flag_entry *it, **flag_list; |
| 175 | str fn; |
| 176 | |
| 177 | if (!flag_name) { |
| 178 | LM_DBG("Flag name is null!\n"); |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | fn.s = flag_name; |
| 183 | fn.len = (flag_name_len<=0)?strlen(flag_name):flag_name_len; |
| 184 | |
| 185 | if (fn.len == 0) { |
| 186 | LM_WARN("found empty string flag modparam! possible scripting error?\n"); |
| 187 | return -1; |
| 188 | } |
| 189 | |
| 190 | if (flag_type < 0 || flag_type >= FLAG_LIST_COUNT) { |
| 191 | LM_ERR("Invalid flag list: %d\n", flag_type); |
| 192 | return -2; |
| 193 | } |
| 194 | |
| 195 | flag_list = flag_lists + flag_type; |
| 196 | |
| 197 | if (*flag_list && (*flag_list)->bit == MAX_FLAG) { |
| 198 | LM_CRIT("Maximum number of message flags reached! (32 flags)\n"); |
| 199 | return E_CFG; |
| 200 | } |
| 201 | |
| 202 | /* Check if flag has been already defined */ |
| 203 | for (it = *flag_list; it; it = it->next) { |
| 204 | if (str_strcmp(&it->name, &fn) == 0) { |
| 205 | |
| 206 | return it->bit; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (!(it = pkg_malloc(sizeof(*it) + fn.len))) { |
| 211 | LM_CRIT("Out of memory!\n"); |
| 212 | return E_OUT_OF_MEM; |
| 213 | } |
| 214 | |
| 215 | it->name.s = (char *)(it + 1); |
| 216 | it->name.len = fn.len; |
| 217 | memcpy(it->name.s, fn.s, fn.len); |
| 218 | |
| 219 | it->bit = (*flag_list ? (*flag_list)->bit + 1 : 0); |
| 220 | |
| 221 | it->next = *flag_list; |
| 222 | *flag_list = it; |
| 223 | |
| 224 | LM_DBG("New flag: [ %.*s : %d ][%d]\n", fn.len, fn.s, it->bit, flag_type); |
| 225 | return it->bit; |
| 226 | } |
| 227 | |
| 228 | unsigned int fixup_flag(int flag_type, const str *flag_name) |
| 229 | { |
no outgoing calls
no test coverage detected