void DIDial::invoke(const string& method, const AmArg& args, AmArg& ret) { if(method == "dial"){ ret.push(dialout(args.get(0).asCStr(), args.get(1).asCStr(), args.get(2).asCStr(), args.get(3).asCStr()).c_str()); } else if(method == "dial_auth"){ ret.push(dialout_auth(args.get(0).asCStr(), args.get(1).asCStr(), args.get(2).asCStr(), args.get(3).asCStr(), args.get(4).asCStr(), args.get(5).asCStr(), args.get(6).asCStr() ).c_str()); } else if(method == "dial_pin"){ ret.push(dialout_pin(args.get(0).asCStr(), args.get(1).asCStr(), args.get(2).asCStr(), args.get(3).asCStr() ).c_str()); } else if(method == "help"){ ret.push("dial <application> <user> <from> <to>"); ret.push("dial_auth <application> <user> <from> <to> <realm> <auth_user> <auth_pwd>"); ret.push("dial_pin <application> <dialout pin> <local_user> <to_user>"); } else if(method == "_list"){ ret.push(AmArg("dial")); ret.push(AmArg("dial_auth")); ret.push(AmArg("dial_pin")); ret.push(AmArg("help")); } else throw AmDynInvoke::NotImplemented(method); }
void WebConferenceFactory::listRooms(const AmArg& args, AmArg& ret) { string pwd = args.get(0).asCStr(); if ((!MasterPassword.length()) || pwd != MasterPassword) { ret.push(407); AmArg res; res.push("Wrong Master Password.\n"); ret.push(res); return; } AmArg room_list; rooms_mut.lock(); for (map<string, ConferenceRoom>::iterator it = rooms.begin(); it != rooms.end(); it++) { room_list.push(it->first.c_str()); } rooms_mut.unlock(); ret.push(200); ret.push(room_list); }
void SBCFactory::reloadProfiles(const AmArg& args, AmArg& ret) { std::map<string, SBCCallProfile> new_call_profiles; bool failed = false; string res = "OK"; AmArg profile_list; profiles_mut.lock(); for (std::map<string, SBCCallProfile>::iterator it= call_profiles.begin(); it != call_profiles.end(); it++) { new_call_profiles[it->first] = SBCCallProfile(); if (!new_call_profiles[it->first].readFromConfiguration(it->first, it->second.profile_file)) { ERROR("reading call profile file '%s'\n", it->second.profile_file.c_str()); res = "Error reading call profile for "+it->first+" from "+it->second.profile_file+ +"; no profiles reloaded"; failed = true; break; } AmArg p; p["name"] = it->first; p["md5"] = it->second.md5hash; p["path"] = it->second.profile_file; profile_list.push(p); } if (!failed) { call_profiles = new_call_profiles; ret.push(200); } else { ret.push(500); } ret.push(res); ret.push(profile_list); profiles_mut.unlock(); }
void WebConferenceFactory::roomCreate(const AmArg& args, AmArg& ret) { assertArgCStr(args.get(0)); string room = args.get(0).asCStr(); rooms_mut.lock(); // sweep rooms (if necessary) sweepRooms(); map<string, ConferenceRoom>::iterator it = rooms.find(room); if (it == rooms.end()) { rooms[room] = ConferenceRoom(); rooms[room].adminpin = getRandomPin(); ret.push(0); ret.push("OK"); ret.push(rooms[room].adminpin.c_str()); } else { if (rooms[room].adminpin.empty()) { rooms[room].adminpin = getRandomPin(); ret.push(0); ret.push("OK"); ret.push(rooms[room].adminpin.c_str()); } else { ret.push(1); ret.push("room already opened"); ret.push(""); } } rooms_mut.unlock(); }
void SBCFactory::getRegexMapNames(const AmArg& args, AmArg& ret) { AmArg p; vector<string> reg_names = regex_mappings.getNames(); for (vector<string>::iterator it=reg_names.begin(); it != reg_names.end(); it++) { p["regex_maps"].push(*it); } ret.push(200); ret.push("OK"); ret.push(p); }
void SBCFactory::getActiveProfile(const AmArg& args, AmArg& ret) { profiles_mut.lock(); AmArg p; for (vector<string>::iterator it=active_profile.begin(); it != active_profile.end(); it++) { p["active_profile"].push(*it); } profiles_mut.unlock(); ret.push(200); ret.push("OK"); ret.push(p); }
// DI interface function void DSMFactory::loadConfig(const AmArg& args, AmArg& ret) { string file_name = args.get(0).asCStr(); string diag_name = args.get(1).asCStr(); if (loadConfig(file_name, diag_name, true, NULL)) { ret.push(200); ret.push("OK"); } else { ret.push(500); ret.push("reload config failed"); } }
void DILog::invoke(const string& method, const AmArg& args, AmArg& ret) { if(method == "dumplog") { ret.push(dumpLog().c_str()); } else if(method == "dumplogtodisk") { dumpLog(args.get(0).asCStr()); ret.push("dumped to disk.\n"); } else if(method == "help") { ret.push("dumplog\n" "dumplogtodisk <path>\n" ); } else throw AmDynInvoke::NotImplemented(method); }
void XMLRPC2DIServer::xmlrpcval2amarg(XmlRpcValue& v, AmArg& a, unsigned int start_index) { if (v.valid()) { for (int i=start_index; i<v.size();i++) { switch (v[i].getType()) { case XmlRpcValue::TypeInt: { a.push(AmArg((int)v[i])); } break; case XmlRpcValue::TypeDouble:{ a.push(AmArg((double)v[i])); } break; case XmlRpcValue::TypeString:{ a.push(AmArg(((string)v[i]).c_str())); } break; // TODO: support more types (datetime, struct, ...) default: throw XmlRpcException("unsupported parameter type", 400); }; } } }
void SBCFactory::setActiveProfile(const AmArg& args, AmArg& ret) { if (!args[0].hasMember("active_profile")) { ret.push(400); ret.push("Parameters error: expected ['active_profile': <active_profile list>] "); return; } profiles_mut.lock(); active_profile = explode(args[0]["active_profile"].asCStr(), ","); profiles_mut.unlock(); ret.push(200); ret.push("OK"); AmArg p; p["active_profile"] = args[0]["active_profile"]; ret.push(p); }
void SBCFactory::postControlCmd(const AmArg& args, AmArg& ret) { SBCControlEvent* evt; if (args.size()<3) { evt = new SBCControlEvent(args[1].asCStr()); } else { evt = new SBCControlEvent(args[1].asCStr(), args[2]); } if (!AmSessionContainer::instance()->postEvent(args[0].asCStr(), evt)) { ret.push(404); ret.push("Not found"); } else { ret.push(202); ret.push("Accepted"); } }
void MsgStorage::msg_get(string domain, string user, string msg_name, AmArg& ret) { string fname = msg_dir + "/" + domain + "/" + user + "/"+ msg_name; DBG("looking for '%s'\n", fname.c_str()); FILE* fp = fopen(fname.c_str(), "r"); if (!fp) ret.push(MSG_EMSGNOTFOUND); else ret.push(MSG_OK); AmArg af; af.setBorrowedPointer(new MessageDataFile(fp)); ret.push(af); }
void WebConferenceFactory::dialout(const AmArg& args, AmArg& ret) { for (int i=0;i<6;i++) assertArgCStr(args.get(1)); string room = args.get(0).asCStr(); string adminpin = args.get(1).asCStr(); string callee = args.get(2).asCStr(); string from_user = args.get(3).asCStr(); string domain = args.get(4).asCStr(); string auth_user = args.get(5).asCStr(); string auth_pwd = args.get(6).asCStr(); string from = "sip:" + from_user + "@" + domain; string to = "sip:" + callee + "@" + domain; // check adminpin rooms_mut.lock(); ConferenceRoom* r = getRoom(room, adminpin); rooms_mut.unlock(); if (NULL == r) { ret.push(1); ret.push("wrong adminpin"); ret.push(""); return; } DBG("dialout webconference room '%s', from '%s', to '%s'", room.c_str(), from.c_str(), to.c_str()); AmArg* a = new AmArg(); a->setBorrowedPointer(new UACAuthCred("", auth_user, auth_pwd)); AmSession* s = AmUAC::dialout(room.c_str(), APP_NAME, to, "<" + from + ">", from, "<" + to + ">", string(""), // local tag string(""), // hdrs a); if (s) { string localtag = s->getLocalTag(); ret.push(0); ret.push("OK"); ret.push(localtag.c_str()); newParticipant(room, localtag, to); updateStatus(room, localtag, ConferenceRoomParticipant::Connecting, "INVITE"); } else { ret.push(1); ret.push("internal error"); ret.push(""); } }
void XMLRPC2DI::invoke(const string& method, const AmArg& args, AmArg& ret) { if(method == "newConnection"){ args.assertArrayFmt("ssis"); // app, server, port, uri newConnection(args, ret); } else if(method == "sendRequest"){ args.assertArrayFmt("ssa"); // app, method, args sendRequest(args, ret); } else if(method == "_list"){ ret.push(AmArg("newConnection")); ret.push(AmArg("sendRequest")); } else throw AmDynInvoke::NotImplemented(method); }
void UACAuthFactory::invoke(const string& method, const AmArg& args, AmArg& ret) { if (method == "getHandler") { CredentialHolder* c = dynamic_cast<CredentialHolder*>(args.get(0).asObject()); DialogControl* cc = dynamic_cast<DialogControl*>(args.get(1).asObject()); if ((c!=NULL)&&(cc!=NULL)) { AmArg handler; handler.setBorrowedPointer(getHandler(cc->getDlg(), c)); ret.push(handler); } else { ERROR("wrong types in call to getHandler. (c=%ld, cc= %ld)\n", (unsigned long)c, (unsigned long)cc); } } else if (method == "checkAuth") { // params: Request realm user pwd if (args.size() < 4) { ERROR("missing arguments to uac_auth checkAuth function, expected Request realm user pwd\n"); throw AmArg::TypeMismatchException(); } AmSipRequest* req = dynamic_cast<AmSipRequest*>(args.get(0).asObject()); if (NULL == req) throw AmArg::TypeMismatchException(); UACAuth::checkAuthentication(req, args.get(1).asCStr(), args.get(2).asCStr(), args.get(3).asCStr(), ret); } else throw AmDynInvoke::NotImplemented(method); }
void CCRegistrar::route(const string& cc_name, SBCCallProfile* call_profile, const AmSipRequest* ood_req, const AmArg& values, AmArg& res) { DBG("CCRegistrar: route '%s %s'\n", ood_req->method.c_str(), ood_req->r_uri.c_str()); if (ood_req->method == "REGISTER"){ RegisterCacheCtx reg_cache_ctx; // reply 200 if possible, else continue bool replied = RegisterCache::instance()->saveSingleContact(reg_cache_ctx, *ood_req); if(replied) { DBG("replied!"); res.push(AmArg()); AmArg& res_cmd = res.back(); res_cmd[SBC_CC_ACTION] = SBC_CC_DROP_ACTION; } } else { if (retarget(ood_req->r_uri, values, call_profile)){ return; } REFUSE_WITH_404; return; } }
void WebConferenceFactory::vqRoomFeedback(const AmArg& args, AmArg& ret) { assertArgCStr(args.get(0)); assertArgCStr(args.get(1)); assertArgInt(args.get(2)); string room = args.get(0).asCStr(); string adminpin = args.get(1).asCStr(); int opinion = args.get(2).asInt(); saveFeedback(string("RO "+ room + "|||" + adminpin + "|||" + int2str(opinion) + "|||" + int2str(time(NULL)) + "|||\n")); ret.push(0); ret.push("OK"); }
void DSMFactory::listDSMs(const AmArg& args, AmArg& ret) { vector<string> names; ScriptConfigs_mut.lock(); try { if (isArgUndef(args) || !args.size()) names = MainScriptConfig.diags->getDiagramNames(); else { if (isArgCStr(args.get(0))) { map<string, DSMScriptConfig>::iterator i= ScriptConfigs.find(args.get(0).asCStr()); if (i!= ScriptConfigs.end()) names = i->second.diags->getDiagramNames(); } } } catch (...) { ScriptConfigs_mut.unlock(); throw; } ScriptConfigs_mut.unlock(); for (vector<string>::iterator it= names.begin(); it != names.end(); it++) { ret.push(*it); } }
void CCBLRedis::invoke(const string& method, const AmArg& args, AmArg& ret) { DBG("CCBLRedis: %s(%s)\n", method.c_str(), AmArg::print(args).c_str()); if(method == "start"){ SBCCallProfile* call_profile = dynamic_cast<SBCCallProfile*>(args[CC_API_PARAMS_CALL_PROFILE].asObject()); start(args[CC_API_PARAMS_CC_NAMESPACE].asCStr(), args[CC_API_PARAMS_LTAG].asCStr(), call_profile, args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_START_SEC].asInt(), args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_START_USEC].asInt(), args[CC_API_PARAMS_CFGVALUES], args[CC_API_PARAMS_TIMERID].asInt(), ret); } else if(method == "connect"){ // SBCCallProfile* call_profile = // dynamic_cast<SBCCallProfile*>(args[CC_API_PARAMS_CALL_PROFILE].asObject()); // connect(args[CC_API_PARAMS_CC_NAMESPACE].asCStr(), // args[CC_API_PARAMS_LTAG].asCStr(), // call_profile, // args[CC_API_PARAMS_OTHERID].asCStr(), // args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_CONNECT_SEC].asInt(), // args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_CONNECT_USEC].asInt()); } else if(method == "end"){ // SBCCallProfile* call_profile = // dynamic_cast<SBCCallProfile*>(args[CC_API_PARAMS_CALL_PROFILE].asObject()); // end(args[CC_API_PARAMS_CC_NAMESPACE].asCStr(), // args[CC_API_PARAMS_LTAG].asCStr(), // call_profile, // args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_END_SEC].asInt(), // args[CC_API_PARAMS_TIMESTAMPS][CC_API_TS_END_USEC].asInt() // ); } else if(method == "_list"){ ret.push("start"); ret.push("connect"); ret.push("end"); } else throw AmDynInvoke::NotImplemented(method); }
void SBCFactory::loadCallcontrolModules(const AmArg& args, AmArg& ret) { string load_cc_plugins = args[0].asCStr(); if (!load_cc_plugins.empty()) { INFO("loading call control plugins '%s' from '%s'\n", load_cc_plugins.c_str(), AmConfig::PlugInPath.c_str()); if (AmPlugIn::instance()->load(AmConfig::PlugInPath, load_cc_plugins) < 0) { ERROR("loading call control plugins '%s' from '%s'\n", load_cc_plugins.c_str(), AmConfig::PlugInPath.c_str()); ret.push(500); ret.push("Failed - please see server logs\n"); return; } } ret.push(200); ret.push("OK"); }
void CCAcc::invoke(const string& method, const AmArg& args, AmArg& ret) { if(method == "getCredit"){ assertArgCStr(args.get(0)); ret.push(getCredit(args.get(0).asCStr())); } else if(method == "subtractCredit"){ assertArgCStr(args.get(0)); assertArgInt(args.get(1)); ret.push(subtractCredit(args.get(0).asCStr(), args.get(1).asInt())); } else if(method == "addCredit"){ assertArgCStr(args.get(0)); assertArgInt(args.get(1)); ret.push(addCredit(args.get(0).asCStr(), args.get(1).asInt())); } else if(method == "setCredit"){ assertArgCStr(args.get(0)); assertArgInt(args.get(1)); ret.push(setCredit(args.get(0).asCStr(), args.get(1).asInt())); } else if(method == "_list"){ ret.push("getCredit"); ret.push("subtractCredit"); ret.push("setCredit"); ret.push("addCredit"); } else throw AmDynInvoke::NotImplemented(method); }
void SIPRegistrarClient::invoke(const string& method, const AmArg& args, AmArg& ret) { if(method == "createRegistration"){ ret.push(createRegistration(args.get(0).asCStr(), args.get(1).asCStr(), args.get(2).asCStr(), args.get(3).asCStr(), args.get(4).asCStr(), args.get(5).asCStr() ).c_str()); } else if(method == "removeRegistration"){ removeRegistration(args.get(0).asCStr()); } else if(method == "getRegistrationState"){ unsigned int state; unsigned int expires; if (instance()->getRegistrationState(args.get(0).asCStr(), state, expires)){ ret.push(1); ret.push((int)state); ret.push((int)expires); } else { ret.push(AmArg((int)0)); } } else if(method == "_list"){ ret.push(AmArg("createRegistration")); ret.push(AmArg("removeRegistration")); ret.push(AmArg("getRegistrationState")); } else throw AmDynInvoke::NotImplemented(method); }
void SBCFactory::loadProfile(const AmArg& args, AmArg& ret) { if (!args[0].hasMember("name") || !args[0].hasMember("path")) { ret.push(400); ret.push("Parameters error: expected ['name': profile_name] " "and ['path': profile_path]"); return; } SBCCallProfile cp; if (!cp.readFromConfiguration(args[0]["name"].asCStr(), args[0]["path"].asCStr())) { ret.push(500); ret.push("Error reading sbc call profile for "+string(args[0]["name"].asCStr())+ " from file "+string(args[0]["path"].asCStr())); return; } profiles_mut.lock(); call_profiles[args[0]["name"].asCStr()] = cp; profiles_mut.unlock(); ret.push(200); ret.push("OK"); AmArg p; p["name"] = args[0]["name"]; p["md5"] = cp.md5hash; p["path"] = args[0]["path"]; ret.push(p); }
void WebConferenceFactory::vqConferenceFeedback(const AmArg& args, AmArg& ret) { assertArgCStr(args.get(0)); assertArgCStr(args.get(1)); assertArgCStr(args.get(2)); assertArgCStr(args.get(3)); assertArgInt(args.get(4)); string room = args.get(0).asCStr(); string adminpin = args.get(1).asCStr(); string sender = args.get(2).asCStr(); string comment = args.get(3).asCStr(); int opinion = args.get(4).asInt(); saveFeedback("CO|||"+ room + "|||" + adminpin + "|||" + int2str(opinion) + "|||" + sender + "|||" + comment +"|||" + int2str(time(NULL)) + "|||\n"); ret.push(0); ret.push("OK"); }
void DSMFactory::preloadModules(const AmArg& args, AmArg& ret) { AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) { ret.push(500); ret.push("loading config file " +AmConfig::ModConfigPath + string(MOD_NAME ".conf")); return ; } string err; string ModPath = cfg.getParameter("mod_path"); int res = preloadModules(cfg, err, ModPath); if (res<0) { ret.push(500); ret.push(err); } else { ret.push(200); ret.push("modules preloaded"); } }
AmArg ConferenceRoom::asArgArray() { cleanExpired(); AmArg res; res.assertArray(0); // make array from it for (list<ConferenceRoomParticipant>::iterator it=participants.begin(); it != participants.end(); it++) { res.push(it->asArgArray()); } return res; }
void MsgStorage::userdir_open(string domain, string user, AmArg& ret) { // TODO: block the directory from delete (increase lock) string path = msg_dir + "/" + domain + "/" + user + "/"; DBG("trying to list '%s'\n", path.c_str()); DIR* dir = opendir(path.c_str()); if (!dir) { ret.push(MSG_EUSRNOTFOUND); ret.push(AmArg()); // empty list return; } int err=0; struct dirent* entry; AmArg msglist; msglist.assertArray(0); // make it an array while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ string msgname(entry->d_name); if(!msgname.length() || msgname[0] == '.'){ continue; } struct stat e_stat; if (stat((path+msgname).c_str(), &e_stat)) { ERROR("cannot stat '%s': %s\n", (path+msgname).c_str(),strerror(errno)); continue; } AmArg msg; msg.push(msgname.c_str()); // TODO: change the system here, st_atime/mtime/... // is not really safe for saving read status! if (e_stat.st_atime != e_stat.st_mtime) { msg.push(0); } else { msg.push(1); } msg.push((int)e_stat.st_size); msglist.push(msg); } closedir(dir); // uh, this is really inefficient... ret.push(MSG_OK); ret.push(msglist); }
void SBCFactory::invoke(const string& method, const AmArg& args, AmArg& ret) { if (method == "listProfiles"){ listProfiles(args, ret); } else if (method == "reloadProfiles"){ reloadProfiles(args,ret); } else if (method == "loadProfile"){ args.assertArrayFmt("u"); loadProfile(args,ret); } else if (method == "reloadProfile"){ args.assertArrayFmt("u"); reloadProfile(args,ret); } else if (method == "getActiveProfile"){ getActiveProfile(args,ret); } else if (method == "setActiveProfile"){ args.assertArrayFmt("u"); setActiveProfile(args,ret); } else if (method == "getRegexMapNames"){ getRegexMapNames(args,ret); } else if (method == "setRegexMap"){ args.assertArrayFmt("u"); setRegexMap(args,ret); } else if (method == "loadCallcontrolModules"){ args.assertArrayFmt("s"); loadCallcontrolModules(args,ret); } else if (method == "postControlCmd"){ args.assertArrayFmt("ss"); // at least call-ltag, cmd postControlCmd(args,ret); } else if(method == "_list"){ ret.push(AmArg("listProfiles")); ret.push(AmArg("reloadProfiles")); ret.push(AmArg("reloadProfile")); ret.push(AmArg("loadProfile")); ret.push(AmArg("getActiveProfile")); ret.push(AmArg("setActiveProfile")); ret.push(AmArg("getRegexMapNames")); ret.push(AmArg("setRegexMap")); ret.push(AmArg("loadCallcontrolModules")); ret.push(AmArg("postControlCmd")); ret.push(AmArg("printCallStats")); } else if(method == "printCallStats"){ B2BMediaStatistics::instance()->getReport(args, ret); } else throw AmDynInvoke::NotImplemented(method); }
void JsonRPCServerModule::invoke(const string& method, const AmArg& args, AmArg& ret) { if (method == "execRpc"){ // todo: add connection id args.assertArrayFmt("sssisis"); // evq_link, notificationReceiver, requestReceiver, // flags(i), host, port (i), method, [params] if (args.size() > 7) { if (!isArgArray(args.get(7)) && !isArgStruct(args.get(7))) { ERROR("internal error: params to JSON-RPC must be struct or array\n"); throw AmArg::TypeMismatchException(); } } execRpc(args, ret); // sendRequestList(args, ret); } else if (method == "sendMessage"){ args.assertArrayFmt("sisss"); // conn_id, type, method, id, reply_sink, [params] if (args.size() > 5) { if (!isArgArray(args.get(5)) && !isArgStruct(args.get(5))) { ERROR("internal error: params to JSON-RPC must be struct or array\n"); throw AmArg::TypeMismatchException(); } } sendMessage(args, ret); } else if (method == "execServerFunction"){ args.assertArrayFmt("ss"); // method, id, params JsonRpcServer::execRpc(args.get(0).asCStr(), args.get(1).asCStr(), args.get(2), ret); // JsonRpcServer::execRpc(args, ret); } else if (method == "getServerPort"){ ret.push(port); } else if(method == "_list"){ ret.push(AmArg("execRpc")); ret.push(AmArg("sendMessage")); ret.push(AmArg("getServerPort")); ret.push(AmArg("execServerFunction")); // ret.push(AmArg("newConnection")); // ret.push(AmArg("sendRequest")); // ret.push(AmArg("sendRequestList")); } else throw AmDynInvoke::NotImplemented(method); }
void DSMFactory::hasDSM(const AmArg& args, AmArg& ret) { string conf_name; if (args.size()>1 && isArgCStr(args.get(1))) conf_name = args.get(1).asCStr(); bool res; ScriptConfigs_mut.lock(); try { res = hasDSM(args.get(0).asCStr(), conf_name); } catch(...) { ScriptConfigs_mut.unlock(); throw; } ScriptConfigs_mut.unlock(); if (res) ret.push("1"); else ret.push("0"); }