int load_redis_conf(const char * buff) { int retv; retv = read_profile_string("redis", "server", &g_server.server_addr, "localhost", buff); if (retv == FAIL) { zlog_error(logger, "redis server addr fetch failed"); return FAIL; } zlog_debug(logger, "redis server addr: %s", g_server.server_addr); g_server.server_port = read_profile_int("redis", "port", 6379, buff); if (g_server.server_port == FAIL) { zlog_error(logger, "redis server port fetch failed"); free(g_server.server_addr); return FAIL; } zlog_debug(logger, "redis server port: %d", g_server.server_port); g_server.db_choice = read_profile_int("redis", "db", 0, buff); if (g_server.db_choice == FAIL) { zlog_error(logger, "redis server db fetch failed"); free(g_server.server_addr); return FAIL; } zlog_debug(logger, "redis db choice: %d", g_server.db_choice); g_server.timeout.tv_sec = 2; g_server.timeout.tv_usec = 0; g_server.conn = NULL; return OK; }
//#include "mythUdp.hh" mythStreamMapServer::mythStreamMapServer(int port) :mythVirtualServer(port)//, mythVirtualSqlite() { char tmpip[256] = { 0 }; int start = read_profile_int("config", "autostart", 0 , MYTH_INFORMATIONINI_FILE); if (start || MYTH_FORCE_AUTOSTART){ startAll(); } mapmutex = SDL_CreateMutex(); #ifdef MYTH_STREAM_CLOSE this->timerid = SDL_AddTimer(1000, TimerCallbackStatic, this); #endif }
int test_proc(void) { const char *file ="myconfig.ini"; const char *section = "student"; const char *name_key = "name"; const char *age_key = "age"; char name[BUF_SIZE]={0}; char buf[MAX_FILE_SIZE]={0}; int age; int file_size; int i; //write name key value pair if(write_profile_string(section,name_key,"Tony",file)) { printf("write name pair to ini file fail\n"); return -1; } //write age key value pair if(write_profile_string(section,age_key,"20",file)) { printf("write age pair to ini file fail\n"); return -1; } printf("[%s]\n",section); //read string pair, test read string value if(read_profile_string(section, name_key, name, BUF_SIZE,"",file)) { printf("read ini file fail\n"); return -1; } else { printf("%s=%s\n",name_key,name); } //read age pair, test read int value. //if read fail, return default value age = read_profile_int(section,age_key,0,file); printf("%s=%d\n",age_key,age); return 0; }
BOOL read_ini(char *client_path[], char *hostname[], int *port, char *username[], char* password[]){ const char *file ="ps.ini"; const char *section = "integrity"; const char *client_path_key = "client_path"; const char *hostname_key = "hostname"; const char *port_key = "port"; const char *username_key = "username"; const char *password_key = "password"; if(!read_profile_string(section, client_path_key, client_path, BUF_SIZE,"",file)) { printf("read ini file fail\n"); return -1; } if(!read_profile_string(section, hostname_key, hostname, BUF_SIZE,"",file)) { printf("read ini file fail\n"); return -1; } *port = read_profile_int(section,port_key,7001,file); if(!read_profile_string(section, username_key, username, BUF_SIZE,"",file)) { printf("read ini file fail\n"); return -1; } if(!read_profile_string(section, password_key, password, BUF_SIZE,"",file)) { printf("read ini file fail\n"); return -1; } return 0; }
void mythStreamMapServer::ServerDecodeCallBack(MythSocket* people, char* data, int datalength) { if (strstr(data, "GET /list")){ string tmp = showAllClients(); /* HTTP/1.1 200 OK Date: Sat, 31 Dec 2005 23:59:59 GMT Content-Type: text/html;charset=ISO-8859-1 Content-Length: 122 */ //int len = tmp.length(); //char header[256] = { 0 }; //sprintf(header, "HTTP/1.1 200 OK\r\nDate: Sat, 31 Dec 2005 23:59:59 GMT\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n", len); //people->socket_SendStr(header); people->socket_SendStr(tmp.c_str(),tmp.length()); closePeople(people); //people->socket_CloseSocket(1); return; } map<int,mythStreamServer*>::iterator Iter; int cameraid = -1; char cameratype[20] = { 0 }; SDL_sscanf(data,"GET /CameraID=%d&Type=%s ",&cameraid,cameratype); if(cameraid != -1){ mythStreamServer* server = NULL; //find cameraid from map Iter = servermap.find(cameraid); if(Iter == servermap.end() || Iter->second == NULL){ //if (servermap[cameraid] != NULL){ SDL_LockMutex(mapmutex); server = mythStreamServer::CreateNew(cameraid); //add a new server into map list,not found ,so create servermap[cameraid] = server; SDL_UnlockMutex(mapmutex); server->start(); } else{ SDL_LockMutex(mapmutex); server = Iter->second; //find an existing server from map list,then add client into server list SDL_UnlockMutex(mapmutex); } mythBaseClient* client = NULL; if(!people->addtionaldata){ SDL_LockMutex(mapmutex); int usingthread = read_profile_int("config", "usethread", 0, MYTH_INFORMATIONINI_FILE); client = mythBaseClient::CreateNew(people, usingthread,cameratype); people->data = server; people->addtionaldata = client; people->server = this; server->AppendClient(client); SDL_UnlockMutex(mapmutex); } } else{ SDL_sscanf(data, "PUT /CameraID=%d", &cameraid); if (cameraid != -1){ people->isPush = 1; mythStreamServer* server = NULL; //find cameraid from map Iter = servermap.find(cameraid); if (Iter == servermap.end() || Iter->second == NULL){ //if (servermap[cameraid] != NULL){ SDL_LockMutex(mapmutex); server = mythStreamServer::CreateNew(cameraid,people); //add a new server into map list,not found ,so create servermap[cameraid] = server; SDL_UnlockMutex(mapmutex); server->start(); } else{ SDL_LockMutex(mapmutex); server = Iter->second; //find an existing server from map list,then add client into server list if (server){ ((mythProxyDecoder*) server->GetDecoder())->refreshSocket(people); //problem } SDL_UnlockMutex(mapmutex); } /*mythBaseClient* client = NULL; if (!people->addtionaldata){ SDL_LockMutex(mapmutex); int usingthread = read_profile_int("config", "usethread", 0, MYTH_INFORMATIONINI_FILE); if (usingthread == 1) client = mythBaseClient::CreateNew(people, true); else client = mythBaseClient::CreateNew(people, false); people->data = server; people->addtionaldata = client; server->AppendClient(client); SDL_UnlockMutex(mapmutex); }*/ } else{ people->socket_SendStr("404"); closePeople(people); //ServerCloseCallBack(people); } } return; }