FILE* AnswerMachineFactory::getMsgStoreGreeting(string msgname, string user, string domain) { if (!msg_storage) return NULL; msgname +=".wav"; domain += DOMAIN_PROMPT_SUFFIX; DBG("trying to get message '%s' for user '%s' domain '%s'\n", msgname.c_str(), user.c_str(), domain.c_str()); AmArg di_args,ret; di_args.push(domain.c_str()); // domain di_args.push(user.c_str()); // user di_args.push(msgname.c_str()); // msg name msg_storage->invoke("msg_get",di_args,ret); if (!ret.size() || !isArgInt(ret.get(0))) { ERROR("msg_get for user '%s' domain '%s' msg '%s'" " returned no (valid) result.\n", user.c_str(), domain.c_str(), msgname.c_str() ); return NULL; } int ecode = ret.get(0).asInt(); if (MSG_OK != ecode) { DBG("msg_get for user '%s' domain '%s' message '%s': %s\n", user.c_str(), domain.c_str(), msgname.c_str(), MsgStrError(ret.get(0).asInt())); if ((ret.size() > 1) && isArgAObject(ret.get(1))) { MessageDataFile* f = dynamic_cast<MessageDataFile*>(ret.get(1).asObject()); if (NULL != f) delete f; } return NULL; } if ((ret.size() < 2) || (!isArgAObject(ret.get(1)))) { ERROR("msg_get for user '%s' domain '%s' message '%s': " "invalid return value\n", user.c_str(), domain.c_str(), msgname.c_str()); return NULL; } MessageDataFile* f = dynamic_cast<MessageDataFile*>(ret.get(1).asObject()); if (NULL == f) return NULL; FILE* fp = f->fp; delete f; return fp; }
void MWI::publish(const string& user, const string& domain) { int new_msgs = 0; int all_msgs = 0; string headers, body; AmArg di_args, ret; di_args.push(domain.c_str()); di_args.push(user.c_str()); MessageStorage->invoke("userdir_open",di_args,ret); if (!ret.size() || !isArgInt(ret.get(0))) { ERROR("userdir_open for user '%s' domain '%s' returned no (valid) result.\n", user.c_str(), domain.c_str()); return; }; all_msgs = ret.get(1).size(); for (size_t i = 0; i < ret.get(1).size(); i++) { AmArg& elem = ret.get(1).get(i); if (elem.get(2).asInt()) // skip empty messages new_msgs += elem.get(1).asInt(); else all_msgs--; }; DBG("Found %d new and %d old messages\n", new_msgs, all_msgs - new_msgs); string vm_buf = int2str(new_msgs) + "/" + int2str(all_msgs - new_msgs); headers = "Event: message-summary\r\n"; headers += "Subscription-State: active\r\n"; if (new_msgs > 0) body = "Messages-Waiting: yes\r\n"; else body = "Messages-Waiting: no\r\n"; body += "Message-Account: sip:" + user + "@" + domain + "\r\n"; body += "Voice-Message: " + vm_buf + " (" + vm_buf + ")\r\n"; AmMimeBody sms_body; sms_body.addPart("application/simple-message-summary"); sms_body.setPayload((const unsigned char*)body.c_str(),body.length()); AmSipDialog tmp_d(NULL); tmp_d.local_party = string("<sip:mwi-publisher@") + presence_server + ">"; tmp_d.remote_party = domain.c_str(); tmp_d.route = "sip:" + presence_server; tmp_d.remote_uri = "sip:" + user + "@" + domain; tmp_d.callid = AmSession::getNewId() + "@" + presence_server; tmp_d.local_tag = AmSession::getNewId(); tmp_d.sendRequest(SIP_METH_NOTIFY, &sms_body, headers); };
FILE* VoiceboxDialog::getCurrentMessage() { string msgname = cur_msg->name; DBG("trying to get message '%s' for user '%s' domain '%s'\n", msgname.c_str(), user.c_str(), domain.c_str()); AmArg di_args,ret; di_args.push(domain.c_str()); // domain di_args.push(user.c_str()); // user di_args.push(msgname.c_str()); // msg name msg_storage->invoke("msg_get",di_args,ret); if (!ret.size() || !isArgInt(ret.get(0))) { ERROR("msg_get for user '%s' domain '%s' msg '%s'" " returned no (valid) result.\n", user.c_str(), domain.c_str(), msgname.c_str() ); return NULL; } int ecode = ret.get(0).asInt(); if (MSG_OK != ecode) { ERROR("msg_get for user '%s' domain '%s' message '%s': %s", user.c_str(), domain.c_str(), msgname.c_str(), MsgStrError(ret.get(0).asInt())); return NULL; } if ((ret.size() < 2) || (!isArgAObject(ret.get(1)))) { ERROR("msg_get for user '%s' domain '%s' message '%s': invalid return value\n", user.c_str(), domain.c_str(), msgname.c_str()); return NULL; } MessageDataFile* f = dynamic_cast<MessageDataFile*>(ret.get(1).asObject()); if (NULL == f) return NULL; FILE* fp = f->fp; delete f; return fp; }
void VoiceboxDialog::closeMailbox() { if (!userdir_open) return; AmArg di_args,ret; di_args.push(domain.c_str()); // domain di_args.push(user.c_str()); // user msg_storage->invoke("userdir_close",di_args,ret); if (ret.size() && isArgInt(ret.get(0)) && ret.get(0).asInt() != MSG_OK ) { ERROR("userdir_close for user '%s' domain '%s': %s\n", user.c_str(), domain.c_str(), MsgStrError(ret.get(0).asInt())); } userdir_open = false; }
void VoiceboxDialog::curMsgOP(const char* op) { if (!isAtEnd()) { string msgname = cur_msg->name; AmArg di_args,ret; di_args.push(domain.c_str()); // domain di_args.push(user.c_str()); // user di_args.push(msgname.c_str()); // msg name msg_storage->invoke(op,di_args,ret); if ((ret.size() < 1) || !isArgInt(ret.get(0))) { ERROR("%s returned wrong result type\n", op); return; } int errcode = ret.get(0).asInt(); if (errcode != MSG_OK) { ERROR("%s error: %s\n", op, MsgStrError(errcode)); } } }
int tarch::argument::Argument::getArgumentAsInt() const { assertion(_argument!=NULL); assertion(isArgInt(_argument)); return atoi(_argument); }
void VoiceboxDialog::openMailbox() { cur_msg = new_msgs.begin(); AmArg di_args,ret; di_args.push(domain.c_str()); // domain di_args.push(user.c_str()); // user msg_storage->invoke("userdir_open",di_args,ret); if (!ret.size() || !isArgInt(ret.get(0))) { ERROR("userdir_open for user '%s' domain '%s'" " returned no (valid) result.\n", user.c_str(), domain.c_str() ); return; } userdir_open = true; int ecode = ret.get(0).asInt(); if (MSG_EUSRNOTFOUND == ecode) { DBG("empty mailbox for user '%s' domain '%s'.\n", user.c_str(), domain.c_str() ); closeMailbox(); return; } if (MSG_OK != ecode) { ERROR("userdir_open for user '%s' domain '%s': %s\n", user.c_str(), domain.c_str(), MsgStrError(ret.get(0).asInt())); closeMailbox(); return; } if ((ret.size() < 2) || (!isArgArray(ret.get(1)))) { ERROR("userdir_open for user '%s' domain '%s'" " returned too few parameters.\n", user.c_str(), domain.c_str() ); closeMailbox(); return; } for (size_t i=0;i<ret.get(1).size();i++) { AmArg& elem = ret.get(1).get(i); if (!isArgArray(elem) || elem.size() != 3) { ERROR("wrong element in userdir list.\n"); continue; } string msg_name = elem.get(0).asCStr(); int msg_unread = elem.get(1).asInt(); int size = elem.get(2).asInt(); if (size) { // TODO: treat empty messages as well! if (msg_unread) { new_msgs.push_back(Message(msg_name, size)); } else { saved_msgs.push_back(Message(msg_name, size)); } } } new_msgs.sort(); new_msgs.reverse(); saved_msgs.sort(); saved_msgs.reverse(); DBG("Got %zd new and %zd saved messages for user '%s' domain '%s'\n", new_msgs.size(), saved_msgs.size(), user.c_str(), domain.c_str()); if (new_msgs.size()) { cur_msg = new_msgs.begin(); in_saved_msgs = false; } else { if (saved_msgs.size()) cur_msg = saved_msgs.begin(); in_saved_msgs = true; } }
bool SCDIAction::execute(AmSession* sess, DSMCondition::EventType event, map<string,string>* event_params) { GET_SCSESSION(); if (params.size() < 2) { ERROR("DI needs at least: mod_name, " "function_name (in '%s'\n", name.c_str()); return false; } vector<string>::iterator p_it=params.begin(); string fact_name = trim(*p_it, " \""); AmDynInvokeFactory* fact = AmPlugIn::instance()->getFactory4Di(fact_name); if(!fact) { ERROR("load module for factory '%s'.\n", fact_name.c_str()); return false; } AmDynInvoke* di_inst = fact->getInstance(); if(!di_inst) { ERROR("load module for factory '%s'\n", fact_name.c_str()); return false; } p_it++; string func_name = trim(*p_it, " \""); p_it++; AmArg di_args; while (p_it != params.end()) { string p = trim(*p_it, " \t"); if (p.length() && p[0] == '"') { di_args.push(trim(p,"\"").c_str()); } else if (p.length() > 5 && p.substr(0, 5) =="(int)") { p = resolveVars(p.substr(5), sess, sc_sess, event_params); char* endptr = NULL; long p_i = strtol(p.c_str(), &endptr, 10); if (endptr && *endptr == '\0') { di_args.push((int)p_i); } else { ERROR("converting value '%s' to int\n", p.c_str()); return false; } } else { di_args.push(resolveVars(p, sess, sc_sess, event_params).c_str()); } p_it++; } sc_sess->di_res.clear(); DBG("executing DI function '%s'\n", func_name.c_str()); try { di_inst->invoke(func_name, di_args, sc_sess->di_res); } catch (const AmDynInvoke::NotImplemented& ni) { ERROR("not implemented DI function '%s'\n", ni.what.c_str()); return false; } catch (const AmArg::OutOfBoundsException& oob) { ERROR("out of bounds in DI call '%s'\n", name.c_str()); return false; } catch (const AmArg::TypeMismatchException& oob) { ERROR("type mismatch in DI call '%s'\n", name.c_str()); return false; } catch (...) { ERROR("unexpected Exception in DI call '%s'\n", name.c_str()); return false; } if (get_res) { // rudimentary variables conversion... if (isArgCStr(sc_sess->di_res)) sc_sess->var["DI_res"] = sc_sess->di_res.asCStr(); else if (isArgInt(sc_sess->di_res)) sc_sess->var["DI_res"] = int2str(sc_sess->di_res.asInt()); else if (isArgArray(sc_sess->di_res)) { // copy results to $DI_res0..$DI_resn for (size_t i=0;i<sc_sess->di_res.size();i++) { switch (sc_sess->di_res.get(i).getType()) { case AmArg::CStr: { sc_sess->var["DI_res"+int2str(i)] = sc_sess->di_res.get(i).asCStr(); } break; case AmArg::Int: { sc_sess->var["DI_res"+int2str(i)] = int2str(sc_sess->di_res.get(i).asInt()); } break; default: { ERROR("unsupported AmArg return type!"); } } } } else { ERROR("unsupported AmArg return type!"); } } return false; }