void RefreshService::init(IRouter *router) { router->addRoute("/start") ->on(IRequest::GET, ROUTE(start)); router->addRoute("/stop") ->on(IRequest::GET, ROUTE(stop)); }
void PrefetchingService::init(IRouter *router) { router->addRoute("/create/") ->on(IRequest::POST, ROUTE(create) ); router->addRoute("/close/") ->on(IRequest::GET, ROUTE(close)); router->addRoute("/list/")->on(IRequest::POST, ROUTE(list)); }
bool TPinocchio::AddRouteRegist() { ROUTE(app_, "/regist/<string>") ([=](const std::string& token) { if(token.length() < 40 || token.length() > 128) return crow::response(400); /* if(sp_db_mgr_->IsMember(token) ) { ST_LOGGER.Trace("Already regist in userToken [%s]",token.c_str()); return crow::response(403); } */ if(!sp_db_mgr_->AddMember(token)) { ST_LOGGER.Error() << "Could not Add userToken [" << token << "]" ; return crow::response(404); } return crow::response(200); } ); return true; }
bool TPinocchio::AddRoute() { ROUTE(app_, "/").name("pinocchio") ( [] { return "This is pinocchio!"; } ); return true; }
static Response *staticHandler(Request *req) { ROUTE(req, "/static/"); // EXIT ON SHENANIGANS if (strstr(req->uri, "../")) return NULL; char *filename = req->uri + 1; // EXIT ON DIRS struct stat sbuff; if (stat(filename, &sbuff) < 0 || S_ISDIR(sbuff.st_mode)) return NULL; // EXIT ON NOT FOUND FILE *file = fopen(filename, "r"); if (!file) return NULL; // GET LENGTH char *buff; char lens[25]; size_t len; fseek(file, 0, SEEK_END); len = ftell(file); sprintf(lens, "%ld", (long int) len); rewind(file); // SET BODY Response *response = responseNew(); buff = malloc(sizeof(char) * len); fread(buff, sizeof(char), len, file); responseSetBody(response, bsNewLen(buff, len)); fclose(file); free(buff); // MIME TYPE char *mimeType = "text/plain"; len = bsGetLen(req->uri); if (!strncmp(req->uri + len - 4, "html", 4)) mimeType = "text/html"; else if (!strncmp(req->uri + len - 4, "json", 4)) mimeType = "application/json"; else if (!strncmp(req->uri + len - 4, "jpeg", 4)) mimeType = "image/jpeg"; else if (!strncmp(req->uri + len - 3, "jpg", 3)) mimeType = "image/jpeg"; else if (!strncmp(req->uri + len - 3, "gif", 3)) mimeType = "image/gif"; else if (!strncmp(req->uri + len - 3, "png", 3)) mimeType = "image/png"; else if (!strncmp(req->uri + len - 3, "css", 3)) mimeType = "text/css"; else if (!strncmp(req->uri + len - 2, "js", 2)) mimeType = "application/javascript"; // RESPOND responseSetStatus(response, OK); responseAddHeader(response, "Content-Type", mimeType); responseAddHeader(response, "Content-Length", lens); responseAddHeader(response, "Cache-Control", "max-age=2592000"); return response; }
RequestRouter::RequestRouter(IUidRestService *service, QObject *parent) : QObject(parent), m_service(service), m_restService(NULL), m_uidRestService(service), m_hasDefaultRoute(false) { addRoute("/") ->on(IRequest::GET, ROUTE(m_uidRestService->index)) ->on(IRequest::POST, ROUTE(m_uidRestService->create)); addRoute("/:id") ->on(IRequest::GET, ROUTE(m_uidRestService->show, STR(id) )) ->on(IRequest::PUT, ROUTE(m_uidRestService->edit, STR(id) )) ->on(IRequest::DELETE, ROUTE(m_uidRestService->del, STR(id) )); service->init(this); }
bool TPinocchio::AddRouteSend() { ROUTE(app_, "/gcm/send").methods("POST"_method) ([=](const crow::request &req) { Stopwatch<> sw; std::string server_key = req.get_header_value("Authorization"); std::vector<std::string> fields; boost::split(fields, server_key, boost::is_any_of("=")); boost::trim(fields[1]); if(!boost::equal(auth_key_, fields[1])) { ST_LOGGER.Error() << "AUTH KEY :" << auth_key_; ST_LOGGER.Error() << "FIELDS[1]:" << fields[1]; return crow::response(405); } auto x = crow::json::load(req.body); if (!x) { ST_LOGGER.Error() << "[POSTED JSON PARSE ERROR]"; ST_LOGGER.Error() << req.body ; ST_LOGGER.Error() << "[POSTED JSON END]"; return crow::response(406); } std::string token = x["to"].s(); if (token.front() == '"') { token.erase(0, 1); token.erase(token.size() - 1); } /* if(!sp_db_mgr_->IsMember(token) ) { ST_LOGGER.Trace("Token not found in userToken [%s]",token.c_str()); return crow::response(407); } */ std::string msg = std::move(crow::json::dump(x["data"])); if (!sp_db_mgr_->AddMsg(token, msg)) { ST_LOGGER.Trace() << "Could not push message[" << msg << "] to user[" << token << "]"; return crow::response(408); } ST_LOGGER.Trace() << "AddRouteSend" << "[" << msg << "] " << sw.stop() << " micro senconds"; return crow::response(200); } ); return true; }
bool TPinocchio::AddRoutePublishApiKey() { ROUTE(app_, "/gcm/publish/ServerApiKey/<string>") ([](const std::string& base_key) { if(base_key.length() < 10 || base_key.length() > 128 ) { return crow::response(400); } return crow::response(200); } ); return true; }
bool TPinocchio::AddRouteRecv() { ROUTE(app_, "/gcm/recv/<string>") ([=](const std::string& token) { Stopwatch<> sw; if (token.length() > 128) return crow::response(400); /* if (!sp_db_mgr_->IsMember(token)) { ST_LOGGER.Trace("[Could not find userToken [%s]", token.c_str()); return crow::response(407); } */ // get user's msg std::vector<RedisValue> arr; if(!sp_db_mgr_->GetMsg(token, arr)) { ST_LOGGER.Trace() << "[Get Message DB Error : " << token << "]" ; return crow::response(408); } // response msg std::stringstream oss; oss << "["; if(arr.size() > 1) std::reverse(arr.begin(),arr.end()); for(const auto & v : arr) { oss << "{data:" << v.toString() << "},"; } oss << "{data:\"\"}]"; ST_LOGGER.Trace() << "AddRouteRecv User " << token << " got msg [" << oss.str() <<"] elapsed " << sw.stop() << " micro seconds"; return crow::response(oss.str()); } ); return true; }
//update the routing now according to the currently locked rate mode, in auto modes this might change //so in that case this function must be called. //updateStdaRouting(); Happens later } #define ROUTE(srcDev,srcCh,dstDev,dstCh) (((srcDev)<<12) + ((srcCh)<<8) + ((dstDev)<<4) + (dstCh)) // // There might be many different stand alone routings and they could be selected by UI or by // persistent storage etc. // In this example there are one static const uint16 stdAloneRouting[] = { //From analog to SPDIF ROUTE(DEV_INS_RX1,0,DEV_AES_TX,6), ROUTE(DEV_INS_RX1,1,DEV_AES_TX,7), //Fron Analog to Analog ROUTE(DEV_INS_RX1,0,DEV_INS_TX1,0), ROUTE(DEV_INS_RX1,1,DEV_INS_TX1,1), }; static void updateRouter (uint16 const * pRoutes, uint16 nbRoutes) { uROUTER_SETUP setup; uROUTER_SETUP * pSetup = (uROUTER_SETUP *) mDicePtr(DICE_ROUTER1_SETUP); uROUTER_ENTRY * pEntry = (uROUTER_ENTRY *) mDicePtr(DICE_ROUTER1_ENTRY);
void GroupsService::init(IRouter *router) { router->addRoute("/approveUser")->on(IRequest::POST, ROUTE(approveUser) ); router->addRoute("/declineUser")->on(IRequest::POST, ROUTE(declineUser) ); router->addRoute("/joinGroup")->on(IRequest::POST, ROUTE(joinGroup) ); router->addRoute("/addAdmin")->on(IRequest::POST, ROUTE(addAdmin) ); router->addRoute("/my")->on(IRequest::GET, ROUTE(getUsersGroups) ); router->addRoute("/myPagesCount")->on(IRequest::GET, ROUTE(myPagesCount) ); router->addRoute("/admin")->on(IRequest::GET, ROUTE(getMyAdminGroups) ); router->addRoute("/adminPagesCount")->on(IRequest::GET, ROUTE(myAdminPagesCount) ); router->addRoute("/notMy")->on(IRequest::GET, ROUTE(getNotMyGroups) ); router->addRoute("/notMyPagesCount")->on(IRequest::GET, ROUTE(notMyPagesCount) ); router->addRoute("/awaiting")->on(IRequest::GET, ROUTE(getAwaitingGroups) ); router->addRoute("/awaitingPagesCount")->on(IRequest::GET, ROUTE(awaitingPagesCount) ); router->addRoute("/getApprovements")->on(IRequest::POST, ROUTE(getApprovements) ); router->addRoute("/getGroupUsers")->on(IRequest::GET, ROUTE(getGroupUsers) ); router->addRoute("/deleteUser")->on(IRequest::POST, ROUTE(deleteUser) ); router->addRoute("/getGroupTypes")->on(IRequest::POST, ROUTE(getGroupTypes) ); router->addRoute("/isAdmin")->on(IRequest::POST, ROUTE(getIsAdmin)); router->addRoute("/isMember")->on(IRequest::POST, ROUTE(getIsMember)); router->addRoute("/allPagesCount")->on(IRequest::GET, ROUTE(allPagesCount)); }