int BrpcCtrlInterfaceFactory::onLoad() { AmConfigReader cfg; unsigned int ct_to, rx_to, tx_to; if (cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) { WARN("failed to read/parse config file `%s' - assuming defaults\n", (AmConfig::ModConfigPath + string(MOD_NAME ".conf")).c_str()); semsUri = string(LISTEN_ADDR_DEFAULT); serUri = string(SER_ADDR_DEFAULT); } else { semsUri = cfg.getParameter(LISTEN_ADDR_PARAM, LISTEN_ADDR_DEFAULT); serUri = cfg.getParameter(SER_ADDR_PARAM, SER_ADDR_DEFAULT); if (str2i(cfg.getParameter(CT_TIMEOUT_PARAM, int2str(CT_TIMEOUT)), ct_to)) { ERROR("failed to read `%s' param from config file.\n", CT_TIMEOUT_PARAM); return -1; } else { ct_timeout = ct_to * 1000; } if (str2i(cfg.getParameter(RX_TIMEOUT_PARAM, int2str(RX_TIMEOUT)), rx_to)) { ERROR("failed to read `%s' param from config file.\n", RX_TIMEOUT_PARAM); return -1; } else { rx_timeout = rx_to * 1000; } if (str2i(cfg.getParameter(TX_TIMEOUT_PARAM, int2str(TX_TIMEOUT)), tx_to)) { ERROR("failed to read `%s' param from config file.\n", TX_TIMEOUT_PARAM); return -1; } else { tx_timeout = tx_to * 1000; } if (str2i(cfg.getParameter(RX_WORKERS_PARAM, int2str(RX_WORKERS)), rx_workers)) { ERROR("failed to read `%s' param from config file.\n", RX_WORKERS_PARAM); return -1; } if (str2i(cfg.getParameter(TX_WORKERS_PARAM, int2str(TX_WORKERS)), tx_workers)) { ERROR("failed to read `%s' param from config file.\n", TX_WORKERS_PARAM); return -1; } } INFO(LISTEN_ADDR_PARAM ": %s.\n", semsUri.c_str()); INFO(SER_ADDR_PARAM ": %s.\n", serUri.c_str()); INFO(CT_TIMEOUT_PARAM ": %uus.\n", (unsigned)ct_timeout); INFO(RX_TIMEOUT_PARAM ": %uus.\n", (unsigned)rx_timeout); INFO(TX_TIMEOUT_PARAM ": %uus.\n", (unsigned)tx_timeout); INFO(RX_WORKERS_PARAM ": %u.\n", rx_workers); INFO(TX_WORKERS_PARAM ": %u.\n", tx_workers); return 0; }
// todo: convert errors to exceptions void replyRequest(DSMSession* sc_sess, AmSession* sess, EventParamT* event_params, const string& par1, const string& par2, const AmSipRequest& req) { string code = resolveVars(par1, sess, sc_sess, event_params); string reason = resolveVars(par2, sess, sc_sess, event_params); unsigned int code_i; if (str2i(code, code_i)) { ERROR("decoding reply code '%s'\n", code.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); return; } if (!sc_sess->last_req.get()) { ERROR("no last request to reply\n"); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); sc_sess->SET_STRERROR("no last request to reply"); return; } if (sess->dlg.reply(req, code_i, reason)) { sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); sc_sess->SET_STRERROR("error sending reply"); } else sc_sess->CLR_ERRNO; }
int AmReplyHandler::handleRequest(AmCtrlInterface* ctrl) { AmSipReply reply; string tmp_str; SAFECTRLCALL1(getParam,tmp_str); DBG("response from Ser: %s\n",tmp_str.c_str()); if( parse_return_code(tmp_str.c_str(),// res_code_str, reply.code,reply.reason) == -1 ){ ERROR("while parsing return code from Ser.\n"); //cleanup(ctrl); return -1; } /* Parse complete response: * * [next_request_uri->cmd.from_uri]CRLF * [next_hop->cmd.next_hop]CRLF * [route->cmd.route]CRLF * ([headers->n_cmd.hdrs]CRLF)* * CRLF * ([body->body]CRLF)* */ SAFECTRLCALL1(getParam,reply.next_request_uri); SAFECTRLCALL1(getParam,reply.next_hop); SAFECTRLCALL1(getParam,reply.route); SAFECTRLCALL1(getLines,reply.hdrs); SAFECTRLCALL1(getLines,reply.body); if(reply.hdrs.empty()){ ERROR("reply is missing headers: <%i %s>\n", reply.code,reply.reason.c_str()); return -1; } reply.local_tag = getHeader(reply.hdrs,"From"); reply.local_tag = extract_tag(reply.local_tag); reply.remote_tag = getHeader(reply.hdrs,"To"); reply.remote_tag = extract_tag(reply.remote_tag); string cseq_str; cseq_str = getHeader(reply.hdrs,"CSeq"); if(str2i(cseq_str,reply.cseq)){ ERROR("could not parse CSeq header\n"); return -1; } AmSessionContainer::instance()->postEvent( reply.local_tag, new AmSipReplyEvent(reply)); // if(reply.code >= 200) // cleanup(ctrl); return 0; }
AmSession* CallTimerFactory::onInvite(const AmSipRequest& req) { DBG(" *** creating new call timer session ***\n"); AmDynInvoke* user_timer = user_timer_fact->getInstance(); if(!user_timer) { ERROR("could not get a user timer reference\n"); throw AmSession::Exception(500,"could not get a user timer reference"); } string app_param = getHeader(req.hdrs, PARAM_HDR); unsigned int call_time = CallTimerFactory::DefaultCallTimer; if (CallTimerFactory::UseAppParam) { if (!app_param.length()) { INFO("call_time: no call timer parameters found. " "Using default value of %d seconds\n", CallTimerFactory::DefaultCallTimer); } else { string call_time_s = get_header_keyvalue(app_param,"t", "Timer"); if (str2i(call_time_s, call_time)) { WARN("Error decoding call time value '%s'. Using default time of %d\n", call_time_s.c_str(), call_time); } } } DBG("using call timer %d seconds\n", call_time); return new CallTimerDialog(user_timer, call_time); }
unsigned int AmConfigReader::getParameterInt(const string& param, unsigned int defval) const { unsigned int result=0; if(!hasParameter(param) || str2i(getParameter(param),result)) return defval; else return result; }
void EarlyAnnounceDialog::process(AmEvent* event) { AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event); if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)) { DBG("AmAudioEvent::cleared\n"); unsigned int code_i = 404; string reason = "Not Found"; string iptel_app_param = getHeader(localreq.hdrs, PARAM_HDR); if (iptel_app_param.length()) { string code = get_header_keyvalue(iptel_app_param,"Final-Reply-Code"); if (code.length() && str2i(code, code_i)) { ERROR("while parsing Final-Reply-Code parameter\n"); } reason = get_header_keyvalue(iptel_app_param,"Final-Reply-Reason"); } else { string code = getHeader(localreq.hdrs,"P-Final-Reply-Code"); if (code.length() && str2i(code, code_i)) { ERROR("while parsing P-Final-Reply-Code\n"); } string h_reason = getHeader(localreq.hdrs,"P-Final-Reply-Reason"); if (h_reason.length()) { INFO("Use of P-Final-Reply-Code/P-Final-Reply-Reason is deprecated. "); INFO("Use '%s: Final-Reply-Code=<code>;" "Final-Reply-Reason=<rs>' instead.\n",PARAM_HDR); reason = h_reason; } } DBG("Replying with code %d %s\n", code_i, reason.c_str()); dlg.reply(localreq, code_i, reason); setStopped(); return; } AmSession::process(event); }
bool SCSetTimerAction::execute(AmSession* sess, DSMCondition::EventType event, map<string,string>* event_params) { GET_SCSESSION(); unsigned int timerid; if (str2i(resolveVars(par1, sess, sc_sess, event_params), timerid)) { ERROR("timer id '%s' not decipherable\n", resolveVars(par1, sess, sc_sess, event_params).c_str()); return false; } unsigned int timeout; if (str2i(resolveVars(par2, sess, sc_sess, event_params), timeout)) { ERROR("timeout value '%s' not decipherable\n", resolveVars(par2, sess, sc_sess, event_params).c_str()); return false; } DBG("setting timer %u with timeout %u\n", timerid, timeout); AmDynInvokeFactory* user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer"); if(!user_timer_fact) { ERROR("load sess_timer module for timers.\n"); return false; } AmDynInvoke* user_timer = user_timer_fact->getInstance(); if(!user_timer) { ERROR("load sess_timer module for timers.\n"); return false; } AmArg di_args,ret; di_args.push((int)timerid); di_args.push((int)timeout); // in seconds di_args.push(sess->getLocalTag().c_str()); user_timer->invoke("setTimer", di_args, ret); return false; }
bool XMLDocument::GetInteger(const TiXmlElement& parent, const string& szName, int& nValue) const { const TiXmlElement* item = parent.FirstChildElement(szName.c_str()); if(item) { string s; GetElementText(*item, s); nValue = str2i(s); return true; } return false; }
int XMLRPC2DI::load() { if (configured) // load only once return 0; configured = true; AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) return -1; ServerRetryAfter = cfg.getParameterInt("server_retry_after", 10); DBG("retrying failed server after %u seconds\n", ServerRetryAfter); string run_server = cfg.getParameter("run_server","yes"); if (run_server != "yes") { DBG("XMLRPC server will not be started.\n"); return 0; } string conf_xmlrpc_port = cfg.getParameter("xmlrpc_port",XMLRPC_PORT); if (conf_xmlrpc_port.empty()) { ERROR("configuration: xmlrpc_port must be defined!\n"); return -1; } if (str2i(conf_xmlrpc_port, XMLRPCPort)) { ERROR("configuration: unable to decode xmlrpc_port value '%s'!\n", conf_xmlrpc_port.c_str()); return -1; } bool export_di = false; string direct_export = cfg.getParameter("direct_export",""); if (direct_export.length()) { DBG("direct_export interfaces: %s\n", direct_export.c_str()); } else { DBG("No direct_export interfaces.\n"); } string export_di_s = cfg.getParameter("export_di","yes"); if (export_di_s == "yes") { export_di = true; } DBG("XMLRPC Server: %snabling builtin method 'di'.\n", export_di?"E":"Not e"); server = new XMLRPC2DIServer(XMLRPCPort, export_di, direct_export); server->start(); return 0; }
bool SCLogAction::execute(AmSession* sess, DSMCondition::EventType event, map<string,string>* event_params) { GET_SCSESSION(); unsigned int lvl; if (str2i(resolveVars(par1, sess, sc_sess, event_params), lvl)) { ERROR("unknown log level '%s'\n", par1.c_str()); return false; } string l_line = resolveVars(par2, sess, sc_sess, event_params).c_str(); _LOG((int)lvl, "FSM: %s %s\n", (par2 != l_line)?par2.c_str():"", l_line.c_str()); return false; }
void log_vars(const string& l_arg, AmSession* sess, DSMSession* sc_sess, map<string,string>* event_params) { unsigned int lvl; if (str2i(resolveVars(l_arg, sess, sc_sess, event_params), lvl)) { ERROR("unknown log level '%s'\n", l_arg.c_str()); return; } _LOG((int)lvl, "FSM: variables set ---\n"); for (map<string, string>::iterator it = sc_sess->var.begin(); it != sc_sess->var.end(); it++) { _LOG((int)lvl, "FSM: $%s='%s'\n", it->first.c_str(), it->second.c_str()); } _LOG((int)lvl, "FSM: variables end ---\n"); }
void DSMCall::addSeparator(const string& name, bool front) { unsigned int id = 0; if (str2i(name, id)) { SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); SET_STRERROR("separator id '"+name+"' not a number"); return; } AmPlaylistSeparator* sep = new AmPlaylistSeparator(this, id); if (front) playlist.addToPlayListFront(new AmPlaylistItem(sep, sep)); else playlist.addToPlaylist(new AmPlaylistItem(sep, sep)); // for garbage collector audiofiles.push_back(sep); CLR_ERRNO; }
inline bool parse_codec_list(char*& s, vector<SdpPayload>& payloads) { unsigned int payload; while(*s != '\0'){ if(!str2i(s,payload)){ payloads.push_back(SdpPayload(payload)); } else { ERROR("invalid payload number found in media line\n"); return true; } } return false; }
static bool parse_sdp_media(AmSdp* sdp_msg, char*& s, char*& next_line) { SdpMedia m; m.dir = SdpMedia::DirBoth; char* old_s = s; bool ret = parse_media_type(s,m.type) || str2i(s,m.port) || parse_transport_prot(s,m.transport); if(ret){ ERROR("while parsing 'm=%s' line.\n",old_s); return true; } if(!ret && (m.transport == TP_RTPAVP)) ret = ret || parse_codec_list(s,m.payloads); sdp_msg->media.push_back(m); s = next_line; DBG("next_line=<%s>\n",next_line); ret = ret // Media title || parse_sdp_line(sdp_msg,s,'i',true,NULL) // connection information - optional if included at session-level || parse_sdp_line(sdp_msg,s,'c',true,parse_sdp_connection) // bandwidth information || parse_sdp_line(sdp_msg,s,'b',true,NULL,false) // encryption key || parse_sdp_line(sdp_msg,s,'k',true,NULL) // zero or more media attribute lines || parse_sdp_line(sdp_msg,s,'a',true,parse_sdp_attribute,false); if(ret){ ERROR("while parsing media attributes.\n"); return true; } next_line = get_next_line(s); DBG("ret=%i; next_line=<%s>\n",ret,next_line); return ret; }
void AmSipSubscription::onSipReply(const AmSipReply& reply, AmSipDialog::Status old_dlg_status) { if ((seh!=NULL) && seh->onSipReply(reply, old_dlg_status)) return; AmSipTransaction* sip_trans = dlg.getUACTrans(reply.cseq); if (!sip_trans) { WARN("No UAC transaction found for reply '%s', ignoring (%s)\n", reply.print().c_str(), getDescription().c_str()); return; } if (reply.code < 200) { DBG("Provisional reply received for subscription '%s'\n", getDescription().c_str()); return; } if ((reply.code>=200)&&(reply.code<300)) { DBG("Positive reply to SUBSCRIBE\n"); unsigned int expires_i = 0; string expires = getHeader(reply.hdrs, SIP_HDR_EXPIRES); if (expires.length()) { str2i(trim(expires, " \t"), expires_i); } AmSessionContainer::instance()-> postEvent(sess_link, new SIPSubscriptionEvent(SIPSubscriptionEvent::SubscribeActive, req.from_tag, expires_i, reply.code, reply.reason)); } else if (reply.code >= 300) { DBG("Subscription '%s' failed\n", getDescription().c_str()); if (sess_link.length()) { AmSessionContainer::instance()-> postEvent(sess_link, new SIPSubscriptionEvent(SIPSubscriptionEvent::SubscribeFailed, req.from_tag, 0, reply.code, reply.reason)); } sub_state = SipSubStateTerminated; } }
/** * check if UAC requests too low Session-Expires * (<locally configured Min-SE) * Throws SessionIntervalTooSmallException if too low */ bool SessionTimerFactory::checkSessionExpires(const AmSipRequest& req) { //if (session_timer_conf.getEnableSessionTimer()) { string session_expires = getHeader(req.hdrs, "Session-Expires", "x"); if (session_expires.length()) { unsigned int i_se; if (!str2i(strip_header_params(session_expires), i_se)) { //if (i_se < session_timer_conf.getMinimumTimer()) { //TODO: reply_error... //throw SessionTimerException(session_timer_conf.getMinimumTimer()); //} } else throw AmSession::Exception(500,"internal error"); // malformed request? } //} return true; }
void SessionTimer::updateTimer(AmSession* s, const AmSipReply& reply) { if (!session_timer_conf.getEnableSessionTimer()) return; // only update timer on positive reply if ((reply.code < 200) || (reply.code >= 300)) return; // determine session interval string sess_expires_hdr = getHeader(reply.hdrs, "Session-Expires"); if (sess_expires_hdr.empty()) sess_expires_hdr = getHeader(reply.hdrs, "x"); // compact form session_interval = session_timer_conf.getSessionExpires(); session_refresher = refresh_local; session_refresher_role = UAC; if (!sess_expires_hdr.empty()) { //session_interval = get_session_interval_from(req); unsigned int sess_i_tmp = 0; if (str2i(strip_header_params(sess_expires_hdr), sess_i_tmp)) { WARN("error while parsing Session-Expires header value '%s'\n", strip_header_params(sess_expires_hdr).c_str()); // exception? } else { // this is forbidden by rfc, but to be sure against 'rogue' proxy/uas if (sess_i_tmp < session_timer_conf.getMinimumTimer()) { session_interval = session_timer_conf.getMinimumTimer(); } else { session_interval = sess_i_tmp; } } if (get_header_param(sess_expires_hdr, "refresher") == "uas") { session_refresher = refresh_remote; session_refresher_role = UAS; } } removeTimers(s); setTimers(s); }
int XMLRPC2DI::onLoad() { AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) return -1; string conf_xmlrpc_port = cfg.getParameter("xmlrpc_port",XMLRPC_PORT); if (conf_xmlrpc_port.empty()) { ERROR("configuration: xmlrpc_port must be defined!\n"); return -1; } if (str2i(conf_xmlrpc_port, XMLRPCPort)) { ERROR("configuration: unable to decode xmlrpc_port value '%s'!\n", conf_xmlrpc_port.c_str()); return -1; } bool export_di = false; string direct_export = cfg.getParameter("direct_export",""); if (direct_export.length()) { DBG("direct_export interfaces: %s\n", direct_export.c_str()); } else { DBG("No direct_export interfaces.\n"); } string export_di_s = cfg.getParameter("export_di","yes"); if (export_di_s == "yes") { export_di = true; } DBG("XMLRPC Server: %snabling builtin method 'di'.\n", export_di?"E":"Not e"); server = new XMLRPC2DIServer(XMLRPCPort, export_di, direct_export); server->start(); return 0; }
void log_selects(const string& l_arg, AmSession* sess, DSMSession* sc_sess, map<string,string>* event_params) { unsigned int lvl; if (str2i(resolveVars(l_arg, sess, sc_sess, event_params), lvl)) { ERROR("unknown log level '%s'\n", l_arg.c_str()); return; } _LOG((int)lvl, "FSM: selects set ---\n"); #define SELECT_LOG(select_name) \ _LOG((int)lvl, "FSM: @%s='%s'\n", select_name, \ resolveVars("@" select_name, sess, sc_sess, event_params).c_str()); SELECT_LOG("local_tag"); SELECT_LOG("user"); SELECT_LOG("domain"); SELECT_LOG("remote_tag"); SELECT_LOG("callid"); SELECT_LOG("local_uri"); SELECT_LOG("remote_uri"); #undef SELECT_LOG _LOG((int)lvl, "FSM: selects end ---\n"); }
bool UnixSocketAdapter::receive(AmSipReply &reply) { string tmp_str; string cseq_str; #ifdef OpenSER unsigned int mi_res_code; string mi_res_msg; #endif if (cacheMsg() < 0) goto failure; #ifdef OpenSER SAFECTRLCALL1(getParam,tmp_str); DBG("MI response from OpenSER: %s\n",tmp_str.c_str()); if( parse_return_code(tmp_str.c_str(),// res_code_str, mi_res_code, mi_res_msg) == -1 ){ ERROR("while parsing MI return code from OpenSER.\n"); goto failure; } if (mi_res_code != 200) { ERROR("MI response from OpenSER\n"); goto failure; } SAFECTRLCALL1(getParam,tmp_str); DBG("SIP response from OpenSER: %s\n",tmp_str.c_str()); if( parse_return_code(tmp_str.c_str(),// res_code_str, reply.code, reply.reason) == -1 ){ ERROR("while parsing return code from Ser.\n"); goto failure; } #else SAFECTRLCALL1(getParam,tmp_str); DBG("response from Ser: %s\n",tmp_str.c_str()); if( parse_return_code(tmp_str.c_str(),// res_code_str, reply.code,reply.reason) == -1 ){ ERROR("while parsing return code from Ser.\n"); goto failure; } #endif /* Parse complete response: * * [next_request_uri->cmd.from_uri]CRLF * [next_hop->cmd.next_hop]CRLF * [route->cmd.route]CRLF * ([headers->n_cmd.hdrs]CRLF)* * CRLF * ([body->body]CRLF)* */ SAFECTRLCALL1(getParam,reply.next_request_uri); SAFECTRLCALL1(getParam,reply.next_hop); SAFECTRLCALL1(getParam,reply.route); SAFECTRLCALL1(getLines,reply.hdrs); SAFECTRLCALL1(getLines,reply.body); if(reply.hdrs.empty()){ ERROR("reply is missing headers: <%i %s>\n", reply.code,reply.reason.c_str()); goto failure; } reply.local_tag = getHeader(reply.hdrs,"From"); reply.local_tag = extract_tag(reply.local_tag); reply.remote_tag = getHeader(reply.hdrs,"To"); reply.remote_tag = extract_tag(reply.remote_tag); cseq_str = getHeader(reply.hdrs,"CSeq"); if(str2i(cseq_str,reply.cseq)){ ERROR("could not parse CSeq header\n"); goto failure; } reply.content_type = getHeader(reply.hdrs,"Content-Type"); return true; failure: //cleanup(ctrl); return false; }
static bool parse_sdp_attribute(AmSdp* sdp_msg, char*& s, char*& next_line) { DBG("parse_sdp_attribute: s=%s\n",s); if(sdp_msg->media.empty()){ ERROR("While parsing media options: no actual media !\n"); return true; } SdpMedia& media = sdp_msg->media.back(); char* sep=0; for( sep=s; *sep!='\0' && *sep!=':'; sep++ ); if( *sep == ':' ){ // attribute definition: 'attribute:value' string attr_name(s,int(sep-s)); char* old_s = s; s = sep + 1; if(attr_name == "rtpmap"){ //fmt: "<payload type> <encoding name>/<clock rate>[/<encoding parameters>]" unsigned int payload_type=0,clock_rate=0; string encoding_name, params; bool ret = str2i(s,payload_type) || parse_string_tok(s,encoding_name,'/') || str2i(s,clock_rate,'/'); if(ret){ ERROR("while parsing 'a=%s'\n",old_s); return true; } parse_string_tok(s,params,'\0'); DBG("sdp attribute: pt=%u; enc=%s; cr=%u\n", payload_type,encoding_name.c_str(),clock_rate); vector<SdpPayload>::iterator pl_it; for( pl_it=media.payloads.begin(); (pl_it != media.payloads.end()) && (pl_it->payload_type != int(payload_type)); ++pl_it); if(pl_it != media.payloads.end()){ *pl_it = SdpPayload( int(payload_type), encoding_name, int(clock_rate)); } return ret; } else if (attr_name == "fmtp") { // fmt: "<payload type> parameters" (?) // z.b. a=fmtp:101 0-15 unsigned int payload_type=0; string params; bool ret = str2i(s, payload_type) || parse_string_tok(s, params, '\0'); vector<SdpPayload>::iterator pl_it; for( pl_it=media.payloads.begin(); (pl_it != media.payloads.end()) && (pl_it->payload_type != int(payload_type)); ++pl_it); if(pl_it != media.payloads.end()) pl_it->sdp_format_parameters = params; return ret; } else if(attr_name == "direction"){ if(!strncmp(s,"active",6/*sizeof("active")*/)) media.dir = SdpMedia::DirActive; else if(!strncmp(s,"passive",7/*sizeof("passive")*/)) media.dir = SdpMedia::DirPassive; else if(!strncmp(s,"both",4/*sizeof("both")*/)) media.dir = SdpMedia::DirBoth; else DBG("unknown value for a=direction:%s",s); } else { DBG("unknown attribute definition '%s'\n",old_s); } } else { // flag: 'flag_name' DBG("flag definition is not yet supported (%s)\n",s); } return false; }
bool str2i(const string& str, unsigned int& result) { char* s = (char*)str.c_str(); return str2i(s,result); }
void EarlyAnnounceDialog::process(AmEvent* event) { AmAudioEvent* audio_event = dynamic_cast<AmAudioEvent*>(event); if(audio_event && (audio_event->event_id == AmAudioEvent::cleared)) { DBG("AmAudioEvent::cleared\n"); bool continue_b2b = false; if (EarlyAnnounceFactory::ContinueB2B == EarlyAnnounceFactory::Always) { continue_b2b = true; } else if (EarlyAnnounceFactory::ContinueB2B == EarlyAnnounceFactory::AppParam) { string iptel_app_param = getHeader(invite_req.hdrs, PARAM_HDR); if (iptel_app_param.length()) { continue_b2b = get_header_keyvalue(iptel_app_param,"B2B")=="yes"; } else { continue_b2b = getHeader(invite_req.hdrs,"P-B2B")=="yes"; } } DBG("determined: continue_b2b = %s\n", continue_b2b?"true":"false"); if (!continue_b2b) { unsigned int code_i = 404; string reason = "Not Found"; string iptel_app_param = getHeader(invite_req.hdrs, PARAM_HDR); if (iptel_app_param.length()) { string code = get_header_keyvalue(iptel_app_param,"Final-Reply-Code"); if (code.length() && str2i(code, code_i)) { ERROR("while parsing Final-Reply-Code parameter\n"); } reason = get_header_keyvalue(iptel_app_param,"Final-Reply-Reason"); if (!reason.length()) reason = "Not Found"; } else { string code = getHeader(invite_req.hdrs,"P-Final-Reply-Code"); if (code.length() && str2i(code, code_i)) { ERROR("while parsing P-Final-Reply-Code\n"); } string h_reason = getHeader(invite_req.hdrs,"P-Final-Reply-Reason"); if (h_reason.length()) { INFO("Use of P-Final-Reply-Code/P-Final-Reply-Reason is deprecated. "); INFO("Use '%s: Final-Reply-Code=<code>;" "Final-Reply-Reason=<rs>' instead.\n",PARAM_HDR); reason = h_reason; } } DBG("Replying with code %d %s\n", code_i, reason.c_str()); dlg.reply(invite_req, code_i, reason); setStopped(); } else { set_sip_relay_only(true); recvd_req.insert(std::make_pair(invite_req.cseq,invite_req)); relayEvent(new B2BSipRequestEvent(invite_req,true)); } return; } AmB2BCallerSession::process(event); }
int web_client_api_old_data_request(RRDHOST *host, struct web_client *w, char *url, int datasource_type) { if(!url || !*url) { buffer_flush(w->response.data); buffer_sprintf(w->response.data, "Incomplete request."); return 400; } RRDSET *st = NULL; char *args = strchr(url, '?'); if(args) { *args='\0'; args = &args[1]; } // get the name of the data to show char *tok = mystrsep(&url, "/"); if(!tok) tok = ""; // do we have such a data set? if(*tok) { debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok); st = rrdset_find_byname(host, tok); if(!st) st = rrdset_find(host, tok); } if(!st) { // we don't have it // try to send a file with that name buffer_flush(w->response.data); return(mysendfile(w, tok)); } // we have it debug(D_WEB_CLIENT, "%llu: Found RRD data with name '%s'.", w->id, tok); // how many entries does the client want? int lines = (int)st->entries; int group_count = 1; time_t after = 0, before = 0; int group_method = GROUP_AVERAGE; int nonzero = 0; if(url) { // parse the lines required tok = mystrsep(&url, "/"); if(tok) lines = str2i(tok); if(lines < 1) lines = 1; } if(url) { // parse the group count required tok = mystrsep(&url, "/"); if(tok && *tok) group_count = str2i(tok); if(group_count < 1) group_count = 1; //if(group_count > save_history / 20) group_count = save_history / 20; } if(url) { // parse the grouping method required tok = mystrsep(&url, "/"); if(tok && *tok) { if(strcmp(tok, "max") == 0) group_method = GROUP_MAX; else if(strcmp(tok, "average") == 0) group_method = GROUP_AVERAGE; else if(strcmp(tok, "sum") == 0) group_method = GROUP_SUM; else debug(D_WEB_CLIENT, "%llu: Unknown group method '%s'", w->id, tok); } } if(url) { // parse after time tok = mystrsep(&url, "/"); if(tok && *tok) after = str2ul(tok); if(after < 0) after = 0; } if(url) { // parse before time tok = mystrsep(&url, "/"); if(tok && *tok) before = str2ul(tok); if(before < 0) before = 0; } if(url) { // parse nonzero tok = mystrsep(&url, "/"); if(tok && *tok && strcmp(tok, "nonzero") == 0) nonzero = 1; } w->response.data->contenttype = CT_APPLICATION_JSON; buffer_flush(w->response.data); char *google_version = "0.6"; char *google_reqId = "0"; char *google_sig = "0"; char *google_out = "json"; char *google_responseHandler = "google.visualization.Query.setResponse"; char *google_outFileName = NULL; time_t last_timestamp_in_data = 0; if(datasource_type == DATASOURCE_DATATABLE_JSON || datasource_type == DATASOURCE_DATATABLE_JSONP) { w->response.data->contenttype = CT_APPLICATION_X_JAVASCRIPT; while(args) { tok = mystrsep(&args, "&"); if(tok && *tok) { char *name = mystrsep(&tok, "="); if(name && *name && strcmp(name, "tqx") == 0) { char *key = mystrsep(&tok, ":"); char *value = mystrsep(&tok, ";"); if(key && value && *key && *value) { if(strcmp(key, "version") == 0) google_version = value; else if(strcmp(key, "reqId") == 0) google_reqId = value; else if(strcmp(key, "sig") == 0) google_sig = value; else if(strcmp(key, "out") == 0) google_out = value; else if(strcmp(key, "responseHandler") == 0) google_responseHandler = value; else if(strcmp(key, "outFileName") == 0) google_outFileName = value; } } } } debug(D_WEB_CLIENT_ACCESS, "%llu: GOOGLE JSONP: version = '%s', reqId = '%s', sig = '%s', out = '%s', responseHandler = '%s', outFileName = '%s'", w->id, google_version, google_reqId, google_sig, google_out, google_responseHandler, google_outFileName ); if(datasource_type == DATASOURCE_DATATABLE_JSONP) { last_timestamp_in_data = strtoul(google_sig, NULL, 0); // check the client wants json if(strcmp(google_out, "json") != 0) { buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'invalid_query',message:'output format is not supported',detailed_message:'the format %s requested is not supported by netdata.'}]});", google_responseHandler, google_version, google_reqId, google_out); return 200; } } } if(datasource_type == DATASOURCE_DATATABLE_JSONP) { buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'ok',sig:'%ld',table:", google_responseHandler, google_version, google_reqId, st->last_updated.tv_sec); } debug(D_WEB_CLIENT_ACCESS, "%llu: Sending RRD data '%s' (id %s, %d lines, %d group, %d group_method, %ld after, %ld before).", w->id, st->name, st->id, lines, group_count, group_method, after, before); time_t timestamp_in_data = rrdset2json_api_old(datasource_type, st, w->response.data, lines, group_count , group_method, (unsigned long) after, (unsigned long) before , nonzero); if(datasource_type == DATASOURCE_DATATABLE_JSONP) { if(timestamp_in_data > last_timestamp_in_data) buffer_strcat(w->response.data, "});"); else { // the client already has the latest data buffer_flush(w->response.data); buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'not_modified',message:'Data not modified'}]});", google_responseHandler, google_version, google_reqId); } } return 200; }
bool curl_run_post(DSMSession* sc_sess, const string& par1, const string& par2, bool get_result) { CURL* m_curl_handle = curl_easy_init(); if (!m_curl_handle) { ERROR("getting curl handle\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); return false; } if (curl_easy_setopt(m_curl_handle, CURLOPT_URL, par1.c_str()) != CURLE_OK) { ERROR("setting URL '%s'\n", par1.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); return false; } if (!sc_sess->var["curl.timeout"].empty()) { unsigned int curl_timeout = 0; if (str2i(sc_sess->var["curl.timeout"], curl_timeout)) { WARN("curl.timeout '%s' not understood\n", sc_sess->var["curl.timeout"].c_str()); } else { if ((curl_easy_setopt(m_curl_handle, CURLOPT_TIMEOUT, curl_timeout) != CURLE_OK) || (curl_easy_setopt(m_curl_handle, CURLOPT_NOSIGNAL, 1L) != CURLE_OK)) { ERROR("setting timeout '%u'\n", curl_timeout); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); return false; } } } if (!get_result) { if (curl_easy_setopt(m_curl_handle, CURLOPT_WRITEFUNCTION, debug_output_func) != CURLE_OK) { ERROR("setting curl write function\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); curl_easy_cleanup(m_curl_handle); return false; } } else { if ((curl_easy_setopt(m_curl_handle, CURLOPT_WRITEFUNCTION, var_output_func) != CURLE_OK)|| (curl_easy_setopt(m_curl_handle, CURLOPT_WRITEDATA, sc_sess) != CURLE_OK)) { ERROR("setting curl write function\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); curl_easy_cleanup(m_curl_handle); return false; } } char curl_err[CURL_ERROR_SIZE]; curl_err[0]='\0'; if (curl_easy_setopt(m_curl_handle, CURLOPT_ERRORBUFFER, curl_err) != CURLE_OK) { ERROR("setting curl error buffer\n"); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); curl_easy_cleanup(m_curl_handle); return false; } if (curl_easy_setopt(m_curl_handle, CURLOPT_POST, 1L) != CURLE_OK) { ERROR("setting curl post option\n"); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); curl_easy_cleanup(m_curl_handle); return false; } struct curl_httppost *post=NULL; struct curl_httppost *last=NULL; string post_vars; vector<string> p_vars=explode(par2, ";"); for (vector<string>::iterator it= p_vars.begin();it != p_vars.end();it++) { string varname = (it->size() && ((*it)[0]=='$')) ? (it->substr(1)) : (*it); DBG("adding '%s' = '%s'\n", varname.c_str(), sc_sess->var[varname].c_str()); curl_formadd(&post, &last, CURLFORM_COPYNAME, varname.c_str(), CURLFORM_COPYCONTENTS, sc_sess->var[varname].c_str(), CURLFORM_END); } curl_easy_setopt(m_curl_handle, CURLOPT_HTTPPOST, post); CURLcode rescode = curl_easy_perform(m_curl_handle); bool res = false; if (rescode) { DBG("Error while trying to POST to '%s': '%s'\n", par1.c_str(), curl_err); sc_sess->var["curl.err"] = string(curl_err); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); } else { sc_sess->SET_ERRNO(DSM_ERRNO_OK); res = true; } curl_formfree(post); curl_easy_cleanup(m_curl_handle); return false; }
void curl_run_getfile(DSMSession* sc_sess, const string& url, const string& outfile) { CURL* m_curl_handle = curl_easy_init(); if (!m_curl_handle) { ERROR("getting curl handle\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); return; } if (curl_easy_setopt(m_curl_handle, CURLOPT_URL, url.c_str()) != CURLE_OK) { ERROR("setting URL '%s'\n", url.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); return; } if (!sc_sess->var["curl.timeout"].empty()) { unsigned int curl_timeout = 0; if (str2i(sc_sess->var["curl.timeout"], curl_timeout)) { WARN("curl.timeout '%s' not understood\n", sc_sess->var["curl.timeout"].c_str()); } else { if ((curl_easy_setopt(m_curl_handle, CURLOPT_TIMEOUT, curl_timeout) != CURLE_OK) || (curl_easy_setopt(m_curl_handle, CURLOPT_NOSIGNAL, 1L) != CURLE_OK)) { ERROR("setting timeout '%u'\n", curl_timeout); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); return; } } } FILE* f = fopen(outfile.c_str(), "wb"); if (NULL == f) { DBG("Error opening file '%s' for writing\n", outfile.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); return; } if (curl_easy_setopt(m_curl_handle, CURLOPT_WRITEDATA, f) != CURLE_OK) { ERROR("setting curl data file\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); fclose(f); return; } char curl_err[CURL_ERROR_SIZE]; curl_err[0]='\0'; if (curl_easy_setopt(m_curl_handle, CURLOPT_ERRORBUFFER, curl_err) != CURLE_OK) { ERROR("setting URL '%s'\n", url.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); fclose(f); return; } CURLcode rescode = curl_easy_perform(m_curl_handle); if (rescode) { DBG("Error while trying to retrieve '%s' to '%s': '%s'\n", url.c_str(), outfile.c_str(), curl_err); sc_sess->var["curl.err"] = string(curl_err); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); }else { sc_sess->SET_ERRNO(DSM_ERRNO_OK); } fclose(f); curl_easy_cleanup(m_curl_handle); }
bool curl_run_get(DSMSession* sc_sess, const string& url, bool get_result) { CURL* m_curl_handle = curl_easy_init(); if (!m_curl_handle) { ERROR("getting curl handle\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); return false; } char* enc_url = curl_easy_escape(m_curl_handle, url.c_str(), url.length()); if (NULL == enc_url) { ERROR("URL-encoding url '%s'\n", url.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); return false; } if (curl_easy_setopt(m_curl_handle, CURLOPT_URL, url.c_str()) != CURLE_OK) { ERROR("setting URL '%s'\n", url.c_str()); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); free(enc_url); return false; } if (!sc_sess->var["curl.timeout"].empty()) { unsigned int curl_timeout = 0; if (str2i(sc_sess->var["curl.timeout"], curl_timeout)) { WARN("curl.timeout '%s' not understood\n", sc_sess->var["curl.timeout"].c_str()); } else { if ((curl_easy_setopt(m_curl_handle, CURLOPT_TIMEOUT, curl_timeout) != CURLE_OK) || (curl_easy_setopt(m_curl_handle, CURLOPT_NOSIGNAL, 1L) != CURLE_OK)) { ERROR("setting timeout '%u'\n", curl_timeout); sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); curl_easy_cleanup(m_curl_handle); free(enc_url); return false; } } } if (!get_result) { if (curl_easy_setopt(m_curl_handle, CURLOPT_WRITEFUNCTION, debug_output_func) != CURLE_OK) { ERROR("setting curl write function\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); curl_easy_cleanup(m_curl_handle); free(enc_url); return false; } } else { if ((curl_easy_setopt(m_curl_handle, CURLOPT_WRITEFUNCTION, var_output_func) != CURLE_OK)|| (curl_easy_setopt(m_curl_handle, CURLOPT_WRITEDATA, sc_sess) != CURLE_OK)) { ERROR("setting curl write function\n"); sc_sess->SET_ERRNO(DSM_ERRNO_FILE); curl_easy_cleanup(m_curl_handle); free(enc_url); return false; } } char curl_err[CURL_ERROR_SIZE]; curl_err[0]='\0'; if (curl_easy_setopt(m_curl_handle, CURLOPT_ERRORBUFFER, curl_err) != CURLE_OK) { ERROR("setting curl error buffer\n"); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); curl_easy_cleanup(m_curl_handle); free(enc_url); return false; } CURLcode rescode = curl_easy_perform(m_curl_handle); if (rescode) { DBG("Error while trying to retrieve '%s': '%s'\n", url.c_str(), curl_err); sc_sess->var["curl.err"] = string(curl_err); sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); } else { sc_sess->SET_ERRNO(DSM_ERRNO_OK); } curl_easy_cleanup(m_curl_handle); free(enc_url); return false; }
void AmSipSubscription::onSipRequest(const AmSipRequest& req) { DBG("SIP Request received: '%s'\n", req.print().c_str()); if (req.method != SIP_METH_NOTIFY) { WARN("received %s Request in subscription???\n", req.method.c_str()); dlg.reply(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR); // todo: other err code? sub_state = SipSubStateTerminated; return; } string h_subscription_state = getHeader(req.hdrs, SIP_HDR_SUBSCRIPTION_STATE); if (h_subscription_state.empty()) { WARN("received NOTIFY without Subscription-State (hdrs='%s')\n", req.hdrs.c_str()); dlg.reply(req, 500, SIP_REPLY_SERVER_INTERNAL_ERROR); // todo: other err code? sub_state = SipSubStateTerminated; return; } size_t pos = h_subscription_state.find(";"); string subscription_state = h_subscription_state; string subscription_state_params; unsigned int expires = 0; string reason; if (pos != string::npos) { subscription_state = h_subscription_state.substr(0, pos); subscription_state_params = h_subscription_state.substr(pos+1); } vector<string> params = explode(subscription_state_params, ";"); for (vector<string>::iterator it=params.begin(); it != params.end(); it++) { vector<string> pv = explode(trim(*it, " \t"), "="); if (pv.size()) { if (trim(pv[0], " \t")=="expires") { if (pv.size()>1) str2i(trim(pv[1], " \t"), expires); } else if (trim(pv[0], " \t")=="reason") { if (pv.size()>1) reason = trim(pv[1], " \t"); } } } DBG("subscription state: '%s', expires: %u, reason: '%s'\n", subscription_state.c_str(), expires, reason.c_str()); SIPSubscriptionEvent* sub_ev = new SIPSubscriptionEvent(SIPSubscriptionEvent::SubscribeFailed, req.from_tag); if (subscription_state == "active") { sub_begin = time(0); sub_ev->expires = sub_expires = expires; sub_state = SipSubStateSubscribed; sub_ev->status = SIPSubscriptionEvent::SubscribeActive; } else if (subscription_state == "pending") { sub_begin = time(0); sub_expires = expires; sub_state = SipSubStatePending; sub_ev->status = SIPSubscriptionEvent::SubscribePending; } else if (subscription_state == "terminated") { sub_expires = 0; sub_state = SipSubStateTerminated; sub_ev->status = SIPSubscriptionEvent::SubscribeTerminated; } else { ERROR("unknown subscription_state '%s'\n", subscription_state.c_str()); } if (!req.body.empty()) sub_ev->notify_body.reset(new AmMimeBody(req.body)); DBG("posting event to session '%s'\n", sess_link.c_str()); AmSessionContainer::instance()->postEvent(sess_link, sub_ev); dlg.reply(req, 200, "OK"); }
// returns the HTTP code inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, char *url) { debug(D_WEB_CLIENT, "%llu: API v1 data with URL '%s'", w->id, url); int ret = 400; BUFFER *dimensions = NULL; buffer_flush(w->response.data); char *google_version = "0.6", *google_reqId = "0", *google_sig = "0", *google_out = "json", *responseHandler = NULL, *outFileName = NULL; time_t last_timestamp_in_data = 0, google_timestamp = 0; char *chart = NULL , *before_str = NULL , *after_str = NULL , *group_time_str = NULL , *points_str = NULL; int group = RRDR_GROUPING_AVERAGE; uint32_t format = DATASOURCE_JSON; uint32_t options = 0x00000000; while(url) { char *value = mystrsep(&url, "?&"); if(!value || !*value) continue; char *name = mystrsep(&value, "="); if(!name || !*name) continue; if(!value || !*value) continue; debug(D_WEB_CLIENT, "%llu: API v1 data query param '%s' with value '%s'", w->id, name, value); // name and value are now the parameters // they are not null and not empty if(!strcmp(name, "chart")) chart = value; else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) { if(!dimensions) dimensions = buffer_create(100); buffer_strcat(dimensions, "|"); buffer_strcat(dimensions, value); } else if(!strcmp(name, "after")) after_str = value; else if(!strcmp(name, "before")) before_str = value; else if(!strcmp(name, "points")) points_str = value; else if(!strcmp(name, "gtime")) group_time_str = value; else if(!strcmp(name, "group")) { group = web_client_api_request_v1_data_group(value, RRDR_GROUPING_AVERAGE); } else if(!strcmp(name, "format")) { format = web_client_api_request_v1_data_format(value); } else if(!strcmp(name, "options")) { options |= web_client_api_request_v1_data_options(value); } else if(!strcmp(name, "callback")) { responseHandler = value; } else if(!strcmp(name, "filename")) { outFileName = value; } else if(!strcmp(name, "tqx")) { // parse Google Visualization API options // https://developers.google.com/chart/interactive/docs/dev/implementing_data_source char *tqx_name, *tqx_value; while(value) { tqx_value = mystrsep(&value, ";"); if(!tqx_value || !*tqx_value) continue; tqx_name = mystrsep(&tqx_value, ":"); if(!tqx_name || !*tqx_name) continue; if(!tqx_value || !*tqx_value) continue; if(!strcmp(tqx_name, "version")) google_version = tqx_value; else if(!strcmp(tqx_name, "reqId")) google_reqId = tqx_value; else if(!strcmp(tqx_name, "sig")) { google_sig = tqx_value; google_timestamp = strtoul(google_sig, NULL, 0); } else if(!strcmp(tqx_name, "out")) { google_out = tqx_value; format = web_client_api_request_v1_data_google_format(google_out); } else if(!strcmp(tqx_name, "responseHandler")) responseHandler = tqx_value; else if(!strcmp(tqx_name, "outFileName")) outFileName = tqx_value; } } } if(!chart || !*chart) { buffer_sprintf(w->response.data, "No chart id is given at the request."); goto cleanup; } RRDSET *st = rrdset_find(host, chart); if(!st) st = rrdset_find_byname(host, chart); if(!st) { buffer_strcat(w->response.data, "Chart is not found: "); buffer_strcat_htmlescape(w->response.data, chart); ret = 404; goto cleanup; } st->last_accessed_time = now_realtime_sec(); long long before = (before_str && *before_str)?str2l(before_str):0; long long after = (after_str && *after_str) ?str2l(after_str):0; int points = (points_str && *points_str)?str2i(points_str):0; long group_time = (group_time_str && *group_time_str)?str2l(group_time_str):0; debug(D_WEB_CLIENT, "%llu: API command 'data' for chart '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%d', format '%u', options '0x%08x'" , w->id , chart , (dimensions)?buffer_tostring(dimensions):"" , after , before , points , group , format , options ); if(outFileName && *outFileName) { buffer_sprintf(w->response.header, "Content-Disposition: attachment; filename=\"%s\"\r\n", outFileName); debug(D_WEB_CLIENT, "%llu: generating outfilename header: '%s'", w->id, outFileName); } if(format == DATASOURCE_DATATABLE_JSONP) { if(responseHandler == NULL) responseHandler = "google.visualization.Query.setResponse"; debug(D_WEB_CLIENT_ACCESS, "%llu: GOOGLE JSON/JSONP: version = '%s', reqId = '%s', sig = '%s', out = '%s', responseHandler = '%s', outFileName = '%s'", w->id, google_version, google_reqId, google_sig, google_out, responseHandler, outFileName ); buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'ok',sig:'%ld',table:", responseHandler, google_version, google_reqId, st->last_updated.tv_sec); } else if(format == DATASOURCE_JSONP) { if(responseHandler == NULL) responseHandler = "callback"; buffer_strcat(w->response.data, responseHandler); buffer_strcat(w->response.data, "("); } ret = rrdset2anything_api_v1(st, w->response.data, dimensions, format, points, after, before, group, group_time , options, &last_timestamp_in_data); if(format == DATASOURCE_DATATABLE_JSONP) { if(google_timestamp < last_timestamp_in_data) buffer_strcat(w->response.data, "});"); else { // the client already has the latest data buffer_flush(w->response.data); buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'not_modified',message:'Data not modified'}]});", responseHandler, google_version, google_reqId); } } else if(format == DATASOURCE_JSONP) buffer_strcat(w->response.data, ");"); cleanup: buffer_free(dimensions); return ret; }
int ConferenceFactory::onLoad() { AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(APP_NAME)+ ".conf")) return -1; // get application specific global parameters configureModule(cfg); #ifdef USE_MYSQL /* Get default audio from MySQL */ string mysql_server, mysql_user, mysql_passwd, mysql_db; mysql_server = cfg.getParameter("mysql_server"); if (mysql_server.empty()) { mysql_server = "localhost"; } mysql_user = cfg.getParameter("mysql_user"); if (mysql_user.empty()) { ERROR("conference.conf parameter 'mysql_user' is missing.\n"); return -1; } mysql_passwd = cfg.getParameter("mysql_passwd"); if (mysql_passwd.empty()) { ERROR("conference.conf parameter 'mysql_passwd' is missing.\n"); return -1; } mysql_db = cfg.getParameter("mysql_db"); if (mysql_db.empty()) { mysql_db = "sems"; } try { #ifdef VERSION2 Connection.set_option(Connection.opt_reconnect, true); #else Connection.set_option(new mysqlpp::ReconnectOption(true)); #endif Connection.connect(mysql_db.c_str(), mysql_server.c_str(), mysql_user.c_str(), mysql_passwd.c_str()); if (!Connection) { ERROR("Database connection failed: %s\n", Connection.error()); return -1; } } catch (const mysqlpp::BadOption& er) { ERROR("MySQL++ set_option error: %s\n", er.what()); return -1; } catch (const mysqlpp::Exception& er) { // Catch-all for any MySQL++ exceptions ERROR("MySQL++ error: %s\n", er.what()); return -1; } if (!get_audio_file(LONELY_USER_MSG, "", "", LonelyUserFile)) { return -1; } if (LonelyUserFile.empty()) { ERROR("default announce 'first_participant_msg'\n"); ERROR("for module conference does not exist.\n"); return -1; } if (!get_audio_file(JOIN_SOUND, "", "", JoinSound)) { return -1; } if (!get_audio_file(DROP_SOUND, "", "", DropSound)) { return -1; } #else /* Get default audio from file system */ AudioPath = cfg.getParameter("audio_path", ANNOUNCE_PATH); LonelyUserFile = cfg.getParameter("default_announce"); if (LonelyUserFile.empty()) { LonelyUserFile = AudioPath + "/" ANNOUNCE_FILE; } else { if (LonelyUserFile[0] != '/') { LonelyUserFile = AudioPath + "/" + LonelyUserFile; } } if(!file_exists(LonelyUserFile)){ ERROR("default announce '%s' \n",LonelyUserFile.c_str()); ERROR("for module conference does not exist.\n"); return -1; } JoinSound = cfg.getParameter("join_sound"); if (!JoinSound.empty()) { if (JoinSound[0] != '/') { JoinSound = AudioPath + "/" + JoinSound; } } DropSound = cfg.getParameter("drop_sound"); if (!DropSound.empty()) { if (DropSound[0] != '/') { DropSound = AudioPath + "/" + DropSound; } } #endif DialoutSuffix = cfg.getParameter("dialout_suffix"); if(DialoutSuffix.empty()){ WARN("No dialout_suffix has been configured in the conference plug-in:\n"); WARN("\t -> dial out will not be available unless P-Dialout-Suffix\n"); WARN("\t -> header parameter is passed to conference plug-in\n"); } string playout_type = cfg.getParameter("playout_type"); if (playout_type == "simple") { m_PlayoutType = SIMPLE_PLAYOUT; DBG("Using simple (fifo) buffer as playout technique.\n"); } else if (playout_type == "adaptive_jb") { m_PlayoutType = JB_PLAYOUT; DBG("Using adaptive jitter buffer as playout technique.\n"); } else { DBG("Using adaptive playout buffer as playout technique.\n"); } MaxParticipants = 0; string max_participants = cfg.getParameter("max_participants"); if (max_participants.length() && str2i(max_participants, MaxParticipants)) { ERROR("while parsing max_participants parameter\n"); } UseRFC4240Rooms = cfg.getParameter("use_rfc4240_rooms")=="yes"; DBG("%ssing RFC4240 room naming.\n", UseRFC4240Rooms?"U":"Not u"); return 0; }