void misdn_cfg_update_ptp (void) { char misdn_init[BUFFERSIZE]; char line[BUFFERSIZE]; FILE *fp; char *tok, *p, *end; int port; misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init)); if (misdn_init) { fp = fopen(misdn_init, "r"); if (fp) { while(fgets(line, sizeof(line), fp)) { if (!strncmp(line, "nt_ptp", 6)) { for (tok = strtok_r(line,",=", &p); tok; tok = strtok_r(NULL,",=", &p)) { port = strtol(tok, &end, 10); if (end != tok && misdn_cfg_is_port_valid(port)) { misdn_cfg_lock(); ptp[port] = 1; misdn_cfg_unlock(); } } } } fclose(fp); } else { cw_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno)); } } }
void misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize) { int place; if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { memset(buf, 0, bufsize); cw_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port); return; } misdn_cfg_lock(); if (elem == MISDN_CFG_PTP) { if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize)) memset(buf, 0, bufsize); } else { if ((place = map[elem]) < 0) { memset (buf, 0, bufsize); cw_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem); } else { if (elem < MISDN_CFG_LAST) { switch (port_spec[place].type) { case MISDN_CTYPE_STR: if (port_cfg[port][place].str) { if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize)) memset(buf, 0, 1); } else if (port_cfg[0][place].str) { if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize)) memset(buf, 0, 1); } break; default: if (port_cfg[port][place].any) memcpy(buf, port_cfg[port][place].any, bufsize); else if (port_cfg[0][place].any) memcpy(buf, port_cfg[0][place].any, bufsize); else memset(buf, 0, bufsize); } } else { switch (gen_spec[place].type) { case MISDN_CTYPE_STR: if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize)) memset(buf, 0, 1); break; default: if (general_cfg[place].any) memcpy(buf, general_cfg[place].any, bufsize); else memset(buf, 0, bufsize); } } } } misdn_cfg_unlock(); }
void misdn_cfg_update_ptp (void) { #ifndef MISDN_1_2 char misdn_init[BUFFERSIZE]; char line[BUFFERSIZE]; FILE *fp; char *tok, *p, *end; int port; misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init)); if (misdn_init) { fp = fopen(misdn_init, "r"); if (fp) { while(fgets(line, sizeof(line), fp)) { if (!strncmp(line, "nt_ptp", 6)) { for (tok = strtok_r(line,",=", &p); tok; tok = strtok_r(NULL,",=", &p)) { port = strtol(tok, &end, 10); if (end != tok && misdn_cfg_is_port_valid(port)) { misdn_cfg_lock(); ptp[port] = 1; misdn_cfg_unlock(); } } } } fclose(fp); } else { ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno)); } } #else int i; int proto; char filename[128]; FILE *fp; for (i = 1; i <= max_ports; ++i) { snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8); fp = fopen(filename, "r"); if (!fp) { ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno)); continue; } if (fscanf(fp, "0x%08x", &proto) != 1) ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename); else ptp[i] = proto & 1<<5 ? 1 : 0; fclose(fp); } #endif }
int misdn_cfg_is_msn_valid (int port, char* msn) { int re = 0; struct msn_list *iter; if (!misdn_cfg_is_port_valid(port)) { cw_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port); return 0; } misdn_cfg_lock(); if (port_cfg[port][map[MISDN_CFG_MSNS]].ml) iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml; else iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml; for ( ; iter; iter = iter->next) { if (*(iter->msn) == '*') { re = 1; } else { switch (cw_extension_pattern_match(msn, iter->msn)) { case EXTENSION_MATCH_EXACT: case EXTENSION_MATCH_STRETCHABLE: case EXTENSION_MATCH_POSSIBLE: re = 1; break; } } if (re) break; } misdn_cfg_unlock(); return re; }
int misdn_cfg_is_msn_valid (int port, char* msn) { int re = 0; struct msn_list *iter; if (!misdn_cfg_is_port_valid(port)) { ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port); return 0; } misdn_cfg_lock(); if (port_cfg[port][map[MISDN_CFG_MSNS]].ml) iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml; else iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml; for (; iter; iter = iter->next) if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) { re = 1; break; } misdn_cfg_unlock(); return re; }
void misdn_cfg_get_config_string (int port, enum misdn_cfg_elements elem, char* buf, int bufsize) { int place; char tempbuf[BUFFERSIZE] = ""; struct msn_list *iter; if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { *buf = 0; cw_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port); return; } place = map[elem]; misdn_cfg_lock(); if (elem == MISDN_CFG_PTP) { snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no"); } else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) { switch (port_spec[place].type) { case MISDN_CTYPE_INT: case MISDN_CTYPE_BOOLINT: if (port_cfg[port][place].num) snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num); else if (port_cfg[0][place].num) snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num); else snprintf(buf, bufsize, " -> %s:", port_spec[place].name); break; case MISDN_CTYPE_BOOL: if (port_cfg[port][place].num) snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no"); else if (port_cfg[0][place].num) snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no"); else snprintf(buf, bufsize, " -> %s:", port_spec[place].name); break; case MISDN_CTYPE_ASTGROUP: if (port_cfg[port][place].grp) snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, cw_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp)); else if (port_cfg[0][place].grp) snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, cw_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp)); else snprintf(buf, bufsize, " -> %s:", port_spec[place].name); break; case MISDN_CTYPE_MSNLIST: if (port_cfg[port][place].ml) iter = port_cfg[port][place].ml; else iter = port_cfg[0][place].ml; if (iter) { for (; iter; iter = iter->next) sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn); tempbuf[strlen(tempbuf)-2] = 0; } snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none"); break; case MISDN_CTYPE_STR: if ( port_cfg[port][place].str) { snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str); } else if (port_cfg[0][place].str) { snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str); } else { snprintf(buf, bufsize, " -> %s:", port_spec[place].name); } break; } } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) { switch (gen_spec[place].type) { case MISDN_CTYPE_INT: case MISDN_CTYPE_BOOLINT: if (general_cfg[place].num) snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num); else snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); break; case MISDN_CTYPE_BOOL: if (general_cfg[place].num) snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no"); else snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); break; case MISDN_CTYPE_STR: if ( general_cfg[place].str) { snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str); } else { snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); } break; default: snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name); break; } } else { *buf = 0; cw_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem); } misdn_cfg_unlock(); }
void misdn_cfg_get(int port, enum misdn_cfg_elements elem, void *buf, int bufsize) { int place; if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { memset(buf, 0, bufsize); ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port); return; } misdn_cfg_lock(); if (elem == MISDN_CFG_PTP) { if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize)) memset(buf, 0, bufsize); } else { if ((place = map[elem]) < 0) { memset(buf, 0, bufsize); ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem); } else { if (elem < MISDN_CFG_LAST) { switch (port_spec[place].type) { case MISDN_CTYPE_STR: if (port_cfg[port][place].str) { ast_copy_string(buf, port_cfg[port][place].str, bufsize); } else if (port_cfg[0][place].str) { ast_copy_string(buf, port_cfg[0][place].str, bufsize); } else memset(buf, 0, bufsize); break; case MISDN_CTYPE_ASTNAMEDGROUP: if (bufsize >= sizeof(struct ast_namedgroups *)) { if (port_cfg[port][place].namgrp) { *(struct ast_namedgroups **)buf = port_cfg[port][place].namgrp; } else if (port_cfg[0][place].namgrp) { *(struct ast_namedgroups **)buf = port_cfg[0][place].namgrp; } else { *(struct ast_namedgroups **)buf = NULL; } } break; default: if (port_cfg[port][place].any) memcpy(buf, port_cfg[port][place].any, bufsize); else if (port_cfg[0][place].any) memcpy(buf, port_cfg[0][place].any, bufsize); else memset(buf, 0, bufsize); } } else { switch (gen_spec[place].type) { case MISDN_CTYPE_STR: ast_copy_string(buf, S_OR(general_cfg[place].str, ""), bufsize); break; default: if (general_cfg[place].any) memcpy(buf, general_cfg[place].any, bufsize); else memset(buf, 0, bufsize); } } } } misdn_cfg_unlock(); }