void SimpleAppSettings::ReadOptionsFile(void) { TCHAR optionFile[MAX_PATH]; if(!GetExePath(optionFile)) { fprintf(stderr, "Cannot get exe path\r\n"); } strcat(optionFile, OptionsFileName); FILE *FP = fopen(optionFile, "rb"); if(!FP) return; fprintf(stderr, "simple_app: Reading options file \"%s\".\n", optionFile); fflush(stderr); char Line[1024]; int LineNum = 1; while(fgets(Line, sizeof(Line), FP) != NULL) { StripNewLine(Line); if(Line[0] == 0) continue; char *Name = strtok(Line, "\t"); char *Value = strtok(NULL, ""); if(!Name || !Value) Error("Invalid format in options file \"%s\" on line %d\n", OptionsFileName, LineNum); map<string, OptionValue>::const_iterator OptVal = OptionValueMap.find(string(Name)); if(OptVal == OptionValueMap.end()) Error("Unknown option \"%s\" defined in options file \"%s\" on line %d.", Name, OptionsFileName, LineNum); SetOptionValue(Name, OptVal->second.Type, Value); LineNum++; } fclose(FP); }
size_t writefunction( void *ptr, size_t size, size_t nmemb, void *userdata) { int length = -1; char * plain = NULL; cJSON *root=NULL, *item=NULL; struct NodeStatus * ns = (struct NodeStatus *)userdata; if(size*nmemb == 0) return 0; length = ContentDecode(NODE_3DES_KEY, NODE_3DES_IV, ptr, &plain, StripNewLine(ptr, size*nmemb)); log4c_cdn(mycat, info, "POST", "%s",plain); if(length<0) { log4c_cdn(mycat, error, "ENDEC", "ContentDecode() failed"); exit(1); } if((root = cJSON_Parse(plain)) == NULL) { log4c_cdn(mycat, error, "JSON", "cJSON_Parse() failed: %s",cJSON_GetErrorPtr()); exit(1); } item = cJSON_GetObjectItem(root,"Status"); ns->Status = item->valueint; item = cJSON_GetObjectItem(root,"StatusDesc"); strcpy(ns->StatusDesc, item->valuestring); if(ns->Status == SUCCESS) { item = cJSON_GetObjectItem(root,"NodeId"); ns->NodeId = item->valueint; } cJSON_Delete(root); if(ns->Status == FAIL) { log4c_cdn(mycat, error, "POST", "FAIL received"); exit(1); } free(plain); return size*nmemb; }
/** * Function: SzDateFromFileName * Returns a string containing the time and date stamp on a file. * * Arguments: * sz, destination buffer * szFile, path to file * * Returns: * date and time in sz * * Error Codes: * none (but leaves sz empty) * * Comments: * Assumes sz is large enough for date string. * * History: * 2/92, Implemented SteveBl */ void SzDateFromFileName(CHAR *sz,CHAR *szFile) { #ifdef RLWIN32 HANDLE hFile; WCHAR szt[MAXFILENAME]; _MBSTOWCS( szt, szFile, WCHARSIN( sizeof( szt)), ACHARSIN( lstrlenA( szFile) + 1)); hFile = CreateFile( szt, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if ( hFile != (HANDLE)-1 ) { FILETIME ft; GetFileTime( hFile, NULL, NULL, &ft); TranslateFileTime( sz, ft); CloseHandle( hFile); } #else //RLWIN32 struct _stat s; if (!_stat(szFile,&s)) { sprintf(sz,"%s",ctime(&s.st_atime)); StripNewLine(sz); } else { sz[0] = 0; } #endif }
static std::string GetErrorMessage(DWORD error) { std::string message; LPVOID buffer = NULL; DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; DWORD lang_id = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); DWORD result = FormatMessageA(flags, NULL, error, lang_id, reinterpret_cast<LPSTR>(&buffer), 0, NULL); if (result > 0) { message.assign(StripNewLine(reinterpret_cast<char*>(buffer))); } LocalFree(buffer); return message; }