int onHttpStat(Socket *sock, vssHttp *req, SocketMap *map) { // Генерация статистики по серверу char buf[1024]; httpSrv *srv = sock->pool; strSetLength(&srv->buf,0); // ClearResulted sprintf(buf,"{clients:%d,connects:%d,requests:%d,mem:%d,serverTime:'%s',pps:%d}",arrLength(srv->srv.sock)-1, srv->srv.connects, srv->srv.requests, os_mem_used(), szTimeNow, (srv->readLimit.pValue+srv->readLimit.ppValue)/2); SocketPrintHttp(sock,req,"%s",buf); // Flash Results as http return 1; // OK - generated }
int onDbRequest(Socket *sock, vssHttp *req, SocketMap *map) { // Генерация статистики по серверу char buf[1024]; httpSrv *srv = (void*)sock->pool; strSetLength(&srv->buf,0); // ClearResulted vss r=req->B; strCat(&srv->buf,r.data,r.len); char *sql = srv->buf; printf("DB->REQ:<%*.*s>\n",VSS(req->B)); if (strncmp(r.data,"select",6)==0) { // get a data if (db_select(db,sql)<=0) { // error here ... SocketPrintHttp(sock,req,"-%s",db->error); return 1; } strSetLength(&srv->buf,0); dbStrFetch(db,&srv->buf); SocketSendHttp(sock,req,srv->buf,-1); return 1; } else { //exec a result if (db_exec_once(db,sql)<=0) { // error here SocketPrintHttp(sock,req,"-%s",db->error); db_rollback(db); return 1; } db_commit(db); // anyqway SocketPrintHttp(sock,req,"+1 OK"); return 1; } /* sprintf(buf,"{clients:%d,connects:%d,requests:%d,mem:%d,serverTime:'%s',pps:%d}",arrLength(srv->srv.sock)-1, srv->srv.connects, srv->srv.requests, os_mem_used(), szTimeNow, (srv->readLimit.pValue+srv->readLimit.ppValue)/2); */ SocketPrintHttp(sock,req,"%s","-not implemented yet"); // Flash Results as httpreturn 1; // OK - generated return 1; }
int onDbVarGet(Socket *sock, vssHttp *req, SocketMap *map) { // Генерация статистики по серверу char buf[1024],id[80],name[80]; httpSrv *srv = (void*)sock->pool; strSetLength(&srv->buf,0); // ClearResulted vss r=req->B; vssGetVar2Buffer(req->args,"id",id,sizeof(id)); vssGetVar2Buffer(req->args,"name",name,sizeof(name)); //strCat(&srv->buf,r.data,r.len); char *sql = srv->buf; printf("DB->REQ: get a var '%s' for id '%s'\n",name,id); if (db_compile(db, var_get_sql) && db_bind(db,"id",dbChar,0,id,strlen(id)) && db_bind(db,"name",dbChar,0,name,strlen(name)) && db_open(db) && db_exec(db) && db_fetch(db) ) { // ok - respons a data printf("Yes!\n"); char *t = db_text(db->out.cols); printf("Resp:%s\n",t); SocketSendHttp(sock,req,t,-1); // send result of first column } else { //error printf("ERR:%s\n",db->error); SocketPrintHttp(sock,req,"-%s",db->error); } return 1; }