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 WebConferenceFactory::roomInfo(const AmArg& args, AmArg& ret) { assertArgCStr(args.get(0)); assertArgCStr(args.get(1)); string room = args.get(0).asCStr(); string adminpin = args.get(1).asCStr();; rooms_mut.lock(); ConferenceRoom* r = getRoom(room, adminpin); if (NULL == r) { ret.push(1); ret.push("wrong adminpin"); // for consistency, add an empty array AmArg a; a.assertArray(0); ret.push(a); } else { ret.push(0); ret.push("OK"); ret.push(r->asArgArray()); } rooms_mut.unlock(); }
void XMLRPC2DI::sendRequest(const AmArg& args, AmArg& ret) { string app_name = args.get(0).asCStr(); string method = args.get(1).asCStr(); AmArg& params = args.get(2); while (true) { XMLRPCServerEntry* srv = getServer(app_name); if (NULL == srv) { ret.push(-1); ret.push("no active connections"); return; } XmlRpcClient c((const char*)srv->server.c_str(), (int)srv->port, (const char*)srv->uri.empty()?NULL:srv->uri.c_str() #ifdef HAVE_XMLRPCPP_SSL , false #endif ); XmlRpcValue x_args, x_result; XMLRPC2DIServer::amarg2xmlrpcval(params, x_args); if (c.execute(method.c_str(), x_args, x_result) && !c.isFault()) { DBG("successfully executed method %s on server %s:%d\n", method.c_str(), srv->server.c_str(), srv->port); ret.push(0); ret.push("OK"); ret.assertArray(3); XMLRPC2DIServer::xmlrpcval2amarg(x_result, ret[2]); return; } else { DBG("executing method %s failed on server %s:%d\n", method.c_str(), srv->server.c_str(), srv->port); srv->set_failed(); } } }