static int channelList_callback(void *pArg, int argc, char **argv, char **columnNames) { chan_entry_t *entry; netsnmp_tdata_row *row; switch_zmalloc(entry, sizeof(chan_entry_t)); row = netsnmp_tdata_create_row(); if (!row) { switch_safe_free(entry); return 0; } row->data = entry; entry->idx = idx++; strncpy(entry->uuid, switch_str_nil(argv[0]), sizeof(entry->uuid)); strncpy(entry->direction, switch_str_nil(argv[1]), sizeof(entry->direction)); entry->created_epoch = atoi(argv[3]); strncpy(entry->name, switch_str_nil(argv[4]), sizeof(entry->name)); strncpy(entry->state, switch_str_nil(argv[5]), sizeof(entry->state)); strncpy(entry->cid_name, switch_str_nil(argv[6]), sizeof(entry->cid_name)); strncpy(entry->cid_num, switch_str_nil(argv[7]), sizeof(entry->cid_num)); strncpy(entry->dest, switch_str_nil(argv[9]), sizeof(entry->dest)); strncpy(entry->application, switch_str_nil(argv[10]), sizeof(entry->application)); strncpy(entry->application_data, switch_str_nil(argv[11]), sizeof(entry->application_data)); strncpy(entry->dialplan, switch_str_nil(argv[12]), sizeof(entry->dialplan)); strncpy(entry->context, switch_str_nil(argv[13]), sizeof(entry->context)); strncpy(entry->read_codec, switch_str_nil(argv[14]), sizeof(entry->read_codec)); entry->read_rate = atoi(switch_str_nil(argv[15])); entry->read_bitrate = atoi(switch_str_nil(argv[16])); strncpy(entry->write_codec, switch_str_nil(argv[17]), sizeof(entry->write_codec)); entry->write_rate = atoi(switch_str_nil(argv[18])); entry->write_bitrate = atoi(switch_str_nil(argv[19])); memset(&entry->ip_addr, 0, sizeof(entry->ip_addr)); if (strchr(switch_str_nil(argv[8]), ':')) { switch_inet_pton(AF_INET6, switch_str_nil(argv[8]), &entry->ip_addr); entry->addr_family = AF_INET6; } else { switch_inet_pton(AF_INET, switch_str_nil(argv[8]), &entry->ip_addr); entry->addr_family = AF_INET; } netsnmp_tdata_row_add_index(row, ASN_INTEGER, &entry->idx, sizeof(entry->idx)); netsnmp_tdata_add_row(ch_table, row); return 0; }
switch_status_t initialise_ei(struct ei_cnode_s *ec) { switch_status_t rv; struct sockaddr_in server_addr; struct hostent *nodehost; char thishostname[EI_MAXHOSTNAMELEN + 1] = ""; char thisnodename[MAXNODELEN + 1]; /* zero out the struct before we use it */ memset(&server_addr, 0, sizeof(server_addr)); /* convert the configured IP to network byte order, handing errors */ rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr); if (rv == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip); return SWITCH_STATUS_FALSE; } else if (rv == -1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error when parsing ip address %s : %s\n", prefs.ip, strerror(errno)); return SWITCH_STATUS_FALSE; } /* set the address family and port */ server_addr.sin_family = AF_INET; server_addr.sin_port = htons(prefs.port); #ifdef WIN32 if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET))) #else if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET))) #endif memcpy(thishostname, nodehost->h_name, EI_MAXHOSTNAMELEN); if (zstr_buf(thishostname)) { gethostname(thishostname, EI_MAXHOSTNAMELEN); } if (prefs.shortname) { char *off; if ((off = strchr(thishostname, '.'))) { *off = '\0'; } } snprintf(thisnodename, MAXNODELEN + 1, "%s@%s", prefs.nodename, thishostname); /* init the ei stuff */ if (ei_connect_xinit(ec, thishostname, prefs.nodename, thisnodename, (Erl_IpAddr) (&server_addr.sin_addr.s_addr), prefs.cookie, 0) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to init ei connection\n"); return SWITCH_STATUS_FALSE; } return SWITCH_STATUS_SUCCESS; }
switch_status_t perform_send_srvreq_response(listener_t *listener, const char *file, const char *func, int line, char *ip, uint32_t port) { skinny_message_t *message; skinny_create_message(message, SERVER_RESPONSE_MESSAGE, serv_res_mess); message->data.serv_res_mess.serverListenPort[0] = port; switch_inet_pton(AF_INET,ip, &message->data.serv_res_mess.serverIpAddr[0]); switch_copy_string(message->data.serv_res_mess.server[0].serverName,ip,sizeof(message->data.serv_res_mess.server[0].serverName)); skinny_log_l_ffl(listener, file, func, line, SWITCH_LOG_DEBUG, "Sending Server Request Response with IP (%s) and Port (%d)\n", ip, port); return skinny_send_reply(listener, message, SWITCH_TRUE); }
static int sangoma_parse_config(void) { switch_xml_t cfg, settings, param, xml; struct in_addr rtpaddr; char localip[255]; int mask = 0; int rc = 0; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Reading sangoma codec configuration\n"); if (!(xml = switch_xml_open_cfg(SANGOMA_TRANSCODE_CONFIG, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to open sangoma codec configuration %s\n", SANGOMA_TRANSCODE_CONFIG); return -1; } memset(&g_init_cfg, 0, sizeof(g_init_cfg)); if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *)switch_xml_attr_soft(param, "name"); char *val = (char *)switch_xml_attr_soft(param, "value"); /* this parameter overrides the default list of codecs to load */ if (!strcasecmp(var, "register")) { strncpy(g_codec_register_list, val, sizeof(g_codec_register_list)-1); g_codec_register_list[sizeof(g_codec_register_list)-1] = 0; } else if (!strcasecmp(var, "noregister")) { strncpy(g_codec_noregister_list, val, sizeof(g_codec_noregister_list)-1); g_codec_noregister_list[sizeof(g_codec_noregister_list)-1] = 0; } else if (!strcasecmp(var, "soapserver")) { strncpy(g_soap_url, val, sizeof(g_soap_url)-1); g_soap_url[sizeof(g_soap_url)-1] = 0; } else if (!strcasecmp(var, "rtpip")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found Sangoma RTP IP %s\n", val); if (switch_inet_pton(AF_INET, val, &rtpaddr) <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Sangoma RTP IP %s\n", val); break; } g_rtpip = ntohl(rtpaddr.s_addr); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma codec setting %s\n", var); } } } if (!g_rtpip) { if (SWITCH_STATUS_SUCCESS != switch_find_local_ip(localip, sizeof(localip), &mask, AF_INET)) { rc = -1; goto done; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "No RTP IP specified, using %s\n", localip); switch_inet_pton(AF_INET, localip, &rtpaddr); g_rtpip = ntohl(rtpaddr.s_addr); } done: switch_xml_free(xml); g_init_cfg.host_nic_vocallo_sz = 0; return rc; }
static int sangoma_parse_config(void) { switch_xml_t cfg, settings, param, vocallos, xml, vocallo; struct in_addr vocallo_base_ip; char ipbuff[50]; char netbuff[50]; int host_ipaddr = 0; int host_netmaskaddr = 0; int vidx = 0; int baseudp = 0; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Reading sangoma codec configuration\n"); if (!(xml = switch_xml_open_cfg(SANGOMA_TRANSCODE_CONFIG, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failed to open sangoma codec configuration %s\n", SANGOMA_TRANSCODE_CONFIG); return -1; } memset(&g_init_cfg, 0, sizeof(g_init_cfg)); if ((settings = switch_xml_child(cfg, "settings"))) { /* nothing here yet */ for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *)switch_xml_attr_soft(param, "name"); char *val = (char *)switch_xml_attr_soft(param, "value"); /* this parameter overrides the default list of codecs to load */ if (!strcasecmp(var, "register")) { strncpy(g_codec_register_list, val, sizeof(g_codec_register_list)-1); g_codec_register_list[sizeof(g_codec_register_list)-1] = 0; } else if (!strcasecmp(var, "noregister")) { strncpy(g_codec_noregister_list, val, sizeof(g_codec_noregister_list)-1); g_codec_noregister_list[sizeof(g_codec_noregister_list)-1] = 0; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma codec setting %s\n", var); } } } if ((vocallos = switch_xml_child(cfg, "vocallos"))) { for (vocallo = switch_xml_child(vocallos, "vocallo"); vocallo; vocallo = vocallo->next) { const char *name = switch_xml_attr(vocallo, "name"); if (!name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Sangoma vocallo found with no name= attribute, ignoring!\n"); continue; } if (load_nic_network_information(name, &g_init_cfg.host_nic_vocallo_cfg[vidx])) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring vocallo %s, failed to retrieve its network configuration\n", name); continue; } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Configuring vocallo %s\n", name); g_init_cfg.host_nic_vocallo_cfg[vidx].vocallo_base_udp_port = SANGOMA_DEFAULT_UDP_PORT; g_init_cfg.host_nic_vocallo_cfg[vidx].silence_suppression = 0; for (param = switch_xml_child(vocallo, "param"); param; param = param->next) { char *var = (char *)switch_xml_attr_soft(param, "name"); char *val = (char *)switch_xml_attr_soft(param, "value"); /* starting UDP port to be used by the vocallo modules */ if (!strcasecmp(var, "baseudp")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found Sangoma codec base udp port %s\n", val); baseudp = atoi(val); if (baseudp < SANGOMA_MIN_UDP_PORT || baseudp > SANGOMA_MAX_UDP_PORT) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Sangoma codec base udp port %s, using default %d\n", val, SANGOMA_DEFAULT_UDP_PORT); break; } g_init_cfg.host_nic_vocallo_cfg[vidx].vocallo_base_udp_port = baseudp; } else if (!strcasecmp(var, "vocalloaddr")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found Sangoma codec vocallo addr %s\n", val); if (switch_inet_pton(AF_INET, val, &vocallo_base_ip) <= 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Sangoma codec vocallo addr %s\n", val); break; } g_init_cfg.host_nic_vocallo_cfg[vidx].vocallo_ip = ntohl(vocallo_base_ip.s_addr); } else if (!strcasecmp(var, "silence")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found Sangoma codec silence setting %s\n", val); g_init_cfg.host_nic_vocallo_cfg[vidx].silence_suppression = switch_true(val) ? 1 : 0; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignored unknown Sangoma vocallo setting %s\n", var); } } if (!g_init_cfg.host_nic_vocallo_cfg[vidx].vocallo_ip) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring vocallo %s, no valid address was configured\n", name); continue; } host_ipaddr = htonl(g_init_cfg.host_nic_vocallo_cfg[vidx].host_ip); host_netmaskaddr = htonl(g_init_cfg.host_nic_vocallo_cfg[vidx].host_ip_netmask); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Configured Sangoma transcoding interface %s, IP address %s, netmask %s\n", name, switch_inet_ntop(AF_INET, &host_ipaddr, ipbuff, sizeof(ipbuff)), switch_inet_ntop(AF_INET, &host_netmaskaddr, netbuff, sizeof(netbuff))); strncpy(g_vocallo_names[vidx], name, sizeof(g_vocallo_names[vidx])-1); g_vocallo_names[vidx][sizeof(g_vocallo_names[vidx])-1] = 0; vidx++; } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No <vocallos> section found in configuration file %s\n", SANGOMA_TRANSCODE_CONFIG); } switch_xml_free(xml); if (!vidx) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No vocallos were configured, make sure there is at least one <vocallo> in %s.\n", SANGOMA_TRANSCODE_CONFIG); } g_init_cfg.host_nic_vocallo_sz = vidx; return 0; }
switch_status_t initialise_ei(struct ei_cnode_s *ec) { switch_status_t rv; struct sockaddr_in server_addr; struct hostent *nodehost; char thishostname[EI_MAXHOSTNAMELEN + 1] = ""; char thisnodename[MAXNODELEN + 1]; char thisalivename[MAXNODELEN + 1]; char *atsign; /* zero out the struct before we use it */ memset(&server_addr, 0, sizeof(server_addr)); /* convert the configured IP to network byte order, handing errors */ rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr); if (rv == 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip); return SWITCH_STATUS_FALSE; } else if (rv == -1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error when parsing ip address %s : %s\n", prefs.ip, strerror(errno)); return SWITCH_STATUS_FALSE; } /* set the address family and port */ server_addr.sin_family = AF_INET; server_addr.sin_port = htons(prefs.port); /* copy the prefs.nodename into something we can modify */ strncpy(thisalivename, prefs.nodename, MAXNODELEN); if ((atsign = strchr(thisalivename, '@'))) { /* we got a qualified node name, don't guess the host/domain */ snprintf(thisnodename, MAXNODELEN + 1, "%s", prefs.nodename); /* truncate the alivename at the @ */ *atsign = '\0'; } else { #ifdef WIN32 if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET))) #else if ((nodehost = gethostbyaddr((const char *) &server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET))) #endif memcpy(thishostname, nodehost->h_name, EI_MAXHOSTNAMELEN); if (zstr_buf(thishostname) || !strncasecmp(prefs.ip, "0.0.0.0", 7)) { gethostname(thishostname, EI_MAXHOSTNAMELEN); } if (prefs.shortname) { char *off; if ((off = strchr(thishostname, '.'))) { *off = '\0'; } } else { if (!(_res.options & RES_INIT)) { // init the resolver res_init(); } if (_res.dnsrch[0] && !zstr_buf(_res.dnsrch[0])) { strncat(thishostname, ".", 1); strncat(thishostname, _res.dnsrch[0], EI_MAXHOSTNAMELEN - strlen(thishostname)); } } snprintf(thisnodename, MAXNODELEN + 1, "%s@%s", prefs.nodename, thishostname); } /* init the ei stuff */ if (ei_connect_xinit(ec, thishostname, thisalivename, thisnodename, (Erl_IpAddr) (&server_addr.sin_addr.s_addr), prefs.cookie, 0) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to init ei connection\n"); return SWITCH_STATUS_FALSE; } return SWITCH_STATUS_SUCCESS; }