int main(int argc, char **argv) { WORD buffer[IOCDataMax/sizeof(word)], result; Object *drive; int i; printf(" Size(Kb) Used(Kb) Available(Kb)\n"); if (argc == 1) { if ((result = ServerInfo(cdobj(), (BYTE *) buffer)) < 0) { printf("ServerInfo failed : %lx\n", result); exit(1); } printf(" %10ld %10ld %10ld\n", buffer[1] / 1024, (buffer[1] - buffer[2]) / 1024, buffer[2] / 1024); } for (i = 1; i < argc; i++) { if ((drive = Locate(cdobj(), argv[i])) == (Object *) NULL) { printf("Unable to locate %s.\n", argv[i]); continue; } if ((result = ServerInfo(drive, (BYTE *) buffer)) < 0) { printf("ServerInfo failed : %lx\n", result); continue; } printf(" %10ld %10ld %10ld\n", buffer[1] / 1024, (buffer[1] - buffer[2]) / 1024, buffer[2] / 1024); } return 0; }
void UpdateServersList() { serverList.clear(); const DataStructures::Table *games = phpDirectoryServer2->GetLastDownloadedTable(); //char str[256]; //games->PrintColumnHeaders(str, 255, ':'); std::cout << str << std::endl; //__GAME_PORT:__GAME_NAME:__SYSTEM_ADDRESS:__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE int gamePortIndex = games->ColumnIndex("__GAME_PORT"); int gameNameIndex = games->ColumnIndex("__GAME_NAME"); int gameSystemAdressIndex = games->ColumnIndex("__SYSTEM_ADDRESS"); int gameTimestampIndex = games->ColumnIndex("__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"); int gameGUIDIndex = games->ColumnIndex("GUID"); for (unsigned i = 0; i < games->GetRowCount(); ++i) { //80:Foo:192.168.1.8:1284635693 //TODO: Data validation. Or should we trust the phpDirectServer2 to dp it for us? DataStructures::Table::Row* row = games->GetRowByIndex(i,NULL); RakNet::SystemAddress address = RakNet::SystemAddress(row->cells[gameSystemAdressIndex]->c,(unsigned short)row->cells[gamePortIndex]->i); RakNet::RakNetGUID guid; if(!guid.FromString(row->cells[gameGUIDIndex]->c)) std::cout << "Invalid GUID: " << row->cells[gameGUIDIndex]->c << std::endl; ServerInfo serverInfo = ServerInfo(row->cells[gameNameIndex]->c,address,guid); //games->PrintRow(str, 255, ':', false, row); std::cout << str << std::endl; serverList.push_back(serverInfo); } //std::cout << "Updated server list" << std::endl; }
void AddServer( const std::string& gameName, unsigned short gamePort, RakNet::RakNetGUID guid) { //Currently only one server per application ia supported //PHPDirectoryServer2 fetches the public ip address automatically. RakNet::SystemAddress address = RakNet::SystemAddress("localhost",gamePort); myServers.push_back(ServerInfo(gameName,address,guid)); }
void MPDConnection::disconnectFromMPD(const QString &reason) { Q_ASSERT(d); d->connected = false; if (d->connection) mpd_closeConnection(d->connection); d->connection = 0; d->server = ServerInfo(); emit disconnected(reason); }
/* ServerInfo call. */ int Util_CountLinks(Object *processor) { Object *procman = Locate(processor, "tasks"); BYTE buffer[IOCDataMax]; word rc; if (procman == Null(Object)) return(-1); rc = ServerInfo(procman, buffer); Close(procman); if (rc < Err_Null) return(-1); return (int)(((ProcStats *) buffer)->NLinks); }
common::Error CommandsApi::Info(internal::CommandHandler* handler, commands_args_t argv, FastoObject* out) { DBConnection* mdb = static_cast<DBConnection*>(handler); ServerInfo::Stats statsout; common::Error err = mdb->Info(argv.size() == 1 ? argv[0] : std::string(), &statsout); if (err) { return err; } common::StringValue* val = common::Value::CreateStringValue(ServerInfo(statsout).ToString()); FastoObject* child = new FastoObject(out, val, mdb->GetDelimiter()); out->AddChildren(child); return common::Error(); }
void ServerDialog::keyPressed(KeyEvent &event) { switch (event.getActionId()) { case InputAction::GUI_CANCEL: event.consume(); client->setState(STATE_EXIT); return; case InputAction::GUI_SELECT: case InputAction::GUI_SELECT2: event.consume(); action(ActionEvent(nullptr, mConnectButton->getActionEventId())); return; case InputAction::GUI_INSERT: (new EditServerDialog(this, ServerInfo(), -1))->postInit(); return; case InputAction::GUI_DELETE: { const int index = mServersList->getSelected(); if (index >= 0) { mServersList->setSelected(0); mServers.erase(mServers.begin() + index); saveCustomServers(); } return; } case InputAction::GUI_BACKSPACE: { const int index = mServersList->getSelected(); if (index >= 0) { (new EditServerDialog(this, mServers.at(index), index))->postInit(); } return; } default: break; } if (!event.isConsumed()) mServersList->keyPressed(event); }
common::Error CommandsApi::Info(internal::CommandHandler* handler, int argc, const char** argv, FastoObject* out) { DBConnection* mdb = static_cast<DBConnection*>(handler); ServerInfo::Stats statsout; common::Error err = mdb->Info(argc == 1 ? argv[0] : nullptr, &statsout); if (err && err->isError()) { return err; } common::StringValue* val = common::Value::createStringValue(ServerInfo(statsout).ToString()); FastoObject* child = new FastoObject(out, val, mdb->Delimiter()); out->AddChildren(child); return common::Error(); }
/*server apply socket and bind*/ int ServerPrepare(char * ServerId) { char ip[50] ="\0"; socklen_t len; struct sockaddr_in raddr; struct epoll_event event; getlocalhostip(); printf("ip is %s\n",ipptr); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr(ipptr); //set ip server_addr.sin_port = htons(0); //set port if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { fprintf(stderr, "socket error:%s\n\a", strerror(errno)); exit(1); } epollfd = epoll_create(MAX_CONNECT); SetNonBlocking(sockfd); event.data.fd = sockfd; event.events = EPOLLIN | EPOLLRDHUP; epoll_ctl(epollfd,EPOLL_CTL_ADD,sockfd,&event); if(bind(sockfd, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr)) == -1) { fprintf(stderr, "bind error:%s\n\a", strerror(errno)); close(sockfd); exit(1); } len=sizeof(raddr); if(getsockname(sockfd,(struct sockaddr *)&raddr,&len)<0) { printf("getsockname failed!\n"); return -1; } strcpy(ip,inet_ntoa(raddr.sin_addr)); //printf("ip is %s,port is %d\n",ip,ntohs(raddr.sin_port)); sprintf(ports,"%d",ntohs(raddr.sin_port)); //printf("ports is %s\n",ports); ServerInfo(ServerId,ip,ports); if(listen(sockfd,MAX_CONNECT_QUEUE) == -1) { fprintf(stderr, "listen error:%s\n\a", strerror(errno)); exit(1); } return 0; }
void ServerDialog::action(const ActionEvent &event) { const std::string &eventId = event.getId(); if (eventId == "connect") { connectToSelectedServer(); } else if (eventId == "quit") { close(); } else if (eventId == "load") { downloadServerList(); } else if (eventId == "addEntry") { CREATEWIDGET(EditServerDialog, this, ServerInfo(), -1); } else if (eventId == "editEntry") { const int index = mServersList->getSelected(); if (index >= 0) { CREATEWIDGET(EditServerDialog, this, mServers.at(index), index); } } else if (eventId == "remove") { const int index = mServersList->getSelected(); if (index >= 0) { mServersList->setSelected(0); mServers.erase(mServers.begin() + index); saveCustomServers(); } } }
ServerInfo MPDConnection::server() const { return isConnected() ? d->server : ServerInfo(); }
am_status_t BaseService::doRequest(const ServiceInfo& service, const BodyChunk& headerPrefix, const std::string& uriParameters, const Http::CookieList& cookieList, const BodyChunk& headerSuffix, const BodyChunkList& bodyChunkList, Http::Response& response, std::size_t initialBufferLen, const std::string &cert_nick_name, const ServerInfo** serverInfo) const { am_status_t status = AM_SERVICE_NOT_AVAILABLE; std::size_t dataLen = 0; // Create a temporary buffer for the Content-Line header // the extra '2' is for the <CR><LF> at the end. The // sizeof the CONTENT_LENGTH_HDR includes space for the // terminating NUL. char contentLine[sizeof(CONTENT_LENGTH_HDR) + (sizeof(dataLen) * DIGITS_PER_BYTE) + 2]; std::size_t contentLineLen; for (unsigned int i = 0; i < bodyChunkList.size(); ++i) { dataLen += bodyChunkList[i].data.size(); } contentLineLen = snprintf(contentLine, sizeof(contentLine), "%s%d\r\n", CONTENT_LENGTH_HDR, dataLen); if (sizeof(contentLine) > contentLineLen) { BodyChunk contentLineChunk(contentLine, contentLineLen); ServiceInfo::const_iterator iter; for (iter = service.begin(); iter != service.end(); ++iter) { ServerInfo svrInfo = ServerInfo((const ServerInfo&)(*iter)); if (!svrInfo.isHealthy(poll_primary_server)) { Log::log(logModule, Log::LOG_WARNING, "BaseService::doRequest(): " "Server is unavailable: %s.", svrInfo.getURL().c_str()); continue; } else { Log::log(logModule, Log::LOG_DEBUG, "BaseService::doRequest(): Using server: %s.", iter->getURL().c_str()); } Http::HeaderList headerList, proxyHeaderList; Http::Cookie hostHeader("Host", svrInfo.getHost()); headerList.push_back(hostHeader); if (useProxy) { proxyHeaderList.push_back(hostHeader); // Override (temporarily) server credentials if using proxy svrInfo.setHost(proxyHost); svrInfo.setPort(proxyPort); // We don't use SSL for initial proxy connection svrInfo.setUseSSL(false); Log::log(logModule, Log::LOG_DEBUG, "BaseService::doRequest(): Using proxy: %s:%d", proxyHost.c_str(),proxyPort); // Add Proxy-Authorization header if user defined if (useProxyAuth) { // allocate enough for a base64-encoded digest int authSize = proxyUser.size() + proxyPassword.size() + 1; // 11 extra bytes for prefix and terminator char * digest = (char *)malloc(authSize * 4/3 + 11); strcpy(digest, "Basic "); encode_base64((proxyUser + ":" + proxyPassword).c_str(), authSize,(digest + 6)); Log::log(logModule, Log::LOG_MAX_DEBUG, "BaseService::doRequest(): Using proxy auth as: %s", proxyUser.c_str()); hostHeader = Http::Cookie("Proxy-Authorization", digest); proxyHeaderList.push_back(hostHeader); free(digest); } } // retry to connect to server before marking it as down. // making the number of attempts configurable may have a negative // side effect on performance, if the the value is a high number. int retryAttempts = 3; int retryCount = 0; while(retryCount < retryAttempts) { retryCount++; try { Connection conn(svrInfo, certDBPasswd, (cert_nick_name.size()>0)?cert_nick_name:certNickName, alwaysTrustServerCert); const char *operation = "sending to"; // in case proxy is defined and target URL is HTTPS, // establish an SSL tunnel first send // CONNECT host:port string if (useProxy && iter->useSSL()) { SECStatus secStatus = SECFailure; // All the other parameters would be empty for a // proxy CONNECT Http::CookieList emptyCookieList; BodyChunk emptyChunk; BodyChunkList emptyChunkList; // Add a Keep-alive header since we're using HTTP/1.0 hostHeader = Http::Cookie("Connection", "Keep-Alive\r\n"); proxyHeaderList.push_back(hostHeader); status = sendRequest(conn, BodyChunk(std::string("CONNECT ")), iter->getHost() + ":" + Utils::toString(iter->getPort()), std::string(""), proxyHeaderList, emptyCookieList, emptyChunk, emptyChunk, emptyChunkList); if (status == AM_SUCCESS) { // Retrieve proxie's response if tunnel // established (void) response.readAndIgnore(logModule, conn); // Secure the tunnel now by upgrading the socket PRFileDesc *sock = conn.secureSocket( certDBPasswd, (cert_nick_name.size()>0)? cert_nick_name:certNickName, alwaysTrustServerCert, NULL); if (sock != static_cast<PRFileDesc *>(NULL)) { secStatus = SSL_SetURL(sock, iter->getHost().c_str()); } } if (status != AM_SUCCESS || SECSuccess != secStatus){ Log::log(logModule, Log::LOG_ERROR, "BaseService::doRequest(): could not " "establish a secure proxy tunnel"); // Can't continue and mark server as down as // it was a proxy failure return AM_FAILURE; } } if(Log::isLevelEnabled(logModule, Log::LOG_MAX_DEBUG)) { std::string commString; for(std::size_t i = 0; i<bodyChunkList.size(); ++i) { if(!bodyChunkList[i].secure) { commString.append(bodyChunkList[i].data); } else { commString.append("<secure data>"); } } for(std::size_t commPos = commString.find("%"); commPos != std::string::npos && commPos < commString.size(); commPos = commString.find("%", commPos)) { commString.replace(commPos, 1, "%%"); commPos += 2; } Log::log(logModule, Log::LOG_MAX_DEBUG, commString.c_str()); } std::string requestString = iter->getURI(); /* * In case the following request would go to a proxy * we need to use full URL and special headers. * If the resource is HTTPS, we're not posting our * request to the proxy, but to the server * through proxy tunnel */ if (useProxy && !(iter->useSSL())) { requestString = iter->getURL(); headerList = proxyHeaderList; } status = sendRequest(conn, headerPrefix, requestString, uriParameters, headerList, cookieList, contentLineChunk, headerSuffix, bodyChunkList); if (AM_SUCCESS == status) { operation = "receiving from"; status = response.readAndParse(logModule, conn, initialBufferLen); if (AM_SUCCESS == status) { Log::log(logModule, Log::LOG_MAX_DEBUG, "%.*s", response.getBodyLen(), response.getBodyPtr()); } } if (AM_NSPR_ERROR == status) { PRErrorCode nspr_code = PR_GetError(); Log::log(logModule, Log::LOG_ALWAYS, "BaseService::doRequest() NSPR failure while " "%s %s, error = %s", operation, (*iter).toString().c_str(), PR_ErrorToName(nspr_code)); } if (AM_SUCCESS == status) { if(serverInfo != NULL) *serverInfo = &(*iter); break; } else { if(retryCount < retryAttempts) { continue; } else { Log::log(logModule, Log::LOG_DEBUG, "BaseService::doRequest() Invoking markSeverDown"); svrInfo.markServerDown(poll_primary_server); } } } catch (const NSPRException& exc) { Log::log(logModule, Log::LOG_DEBUG, "BaseService::doRequest() caught %s: %s called by %s " "returned %s", exc.what(), exc.getNsprMethod(), exc.getThrowingMethod(), PR_ErrorToName(exc.getErrorCode())); if(retryCount < retryAttempts) { status = AM_NSPR_ERROR; continue; } else { Log::log(logModule, Log::LOG_DEBUG, "BaseService::doRequest() Invoking markSeverDown"); svrInfo.markServerDown(poll_primary_server); status = AM_NSPR_ERROR; } } } //end of while if (AM_SUCCESS == status) { if(serverInfo != NULL) *serverInfo = &(*iter); break; } if (status = AM_NSPR_ERROR) { continue; } } // end of for } else { status = AM_BUFFER_TOO_SMALL; } return status; }
int readUrlConfig(const http_method& method, const std::string& path, ServerInfo& svr_info, StatementsInfo& smt_info) { nlohmann::json si_config; nlohmann::json exec_config; { MUTEXGUARD_T(g_mutex); si_config = g_si_config; exec_config = g_exec_config; } //匹配path if(exec_config.find(path) == exec_config.end()) return -1; try { nlohmann::json j_exec = exec_config[path]; smt_info.flag_type = j_exec["exec"]; if(j_exec["exec"] == "query") smt_info.flag = HTTP_GET; else if(j_exec["exec"] == "exec" || j_exec["exec"] == "exec_identity") smt_info.flag = HTTP_POST; else if(j_exec["exec"] == "delete") smt_info.flag = HTTP_DELETE; else smt_info.flag = -1; //匹配method if(smt_info.flag != method) { LOG_STDOUT("readUrlConfig(%s): method can not match", path.c_str()); return -1; } std::string si_name = j_exec["db"]; nlohmann::json j_db = si_config[si_name]; //获取server参数 svr_info = ServerInfo(j_db["host"], j_db["db"], j_db["uid"], j_db["pwd"]); //获取exec参数 smt_info.sql = j_exec["sql"]; //获取param_count参数 nlohmann::json count = j_exec["param_count"]; if(!count.empty() && count.is_number()) smt_info.param_count = count; else smt_info.param_count = 0; if(j_exec.find("param") != j_exec.end()) { smt_info.param = j_exec["param"]; } //获取content_type参数 if(j_exec.find("content_type") != j_exec.end()) { smt_info.content_type = j_exec["content_type"]; } } catch(std::exception const& e) { LOG_STDOUT("readUrlConfig(%s): %s", path.c_str(), e.what()); return -1; } return 0; }
void ServerModel::addServer() { m_servers << ServerInfo("New server"); Config::instance()->setServers(m_servers); reset(); }
void Connection::onConnect() { BaseConnection::onConnect(); m_typeService->init(); m_info = ServerInfo(_host); }
} } SDL_UnlockMutex(resolvermutex); return false; } static vector<ServerInfo> servers; static ENetSocket pingsock = ENET_SOCKET_NULL; static int lastinfo = 0; const char *getservername(int n) { return servers[n].name; } void addserver(const char *servername) { loopv(servers) if (strcmp(servers[i].name, servername)==0) return; // ServerInfo &si = servers.insert(0, ServerInfo()); servers.insert(0, ServerInfo()); ServerInfo &si = *servers.begin(); strcpy_s(si.name, servername); si.full[0] = 0; si.mode = 0; si.numplayers = 0; si.ping = 9999; si.protocol = 0; si.minremain = 0; si.map[0] = 0; si.sdesc[0] = 0; si.address.host = ENET_HOST_ANY; si.address.port = CUBE_SERVINFO_PORT; } CMD(addserver, ARG_1STR);