diff --git a/app/scanner/HGVersion.cpp b/app/scanner/HGVersion.cpp index 42f3a106..5882a5ad 100644 --- a/app/scanner/HGVersion.cpp +++ b/app/scanner/HGVersion.cpp @@ -56,42 +56,45 @@ static bool GetServerConfig(bool &postCrashInfo, bool & postUserBehavior, bool & if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res)); else - ret = true; - - curl_slist_free_all(headers); - - std::string str_json = out.str(); // 返回值 - printf("%s\n", str_json.c_str()); - - cJSON* json = cJSON_Parse(str_json.c_str()); - if (nullptr != json) { - cJSON* p = json->child; - if (nullptr != p) + std::string str_json = out.str(); // 返回值 + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str()); + + cJSON* json = cJSON_Parse(str_json.c_str()); + if (nullptr != json) { - while (nullptr != p && 0 != strcmp(p->string, "data")) - p = p->next; - - if (nullptr != p && 0 == strcmp(p->string, "data") && p->type == cJSON_Object) + cJSON* p = json->child; + while (nullptr != p) { - cJSON* p2 = p->child; - while (nullptr != p2) + if (0 == strcmp(p->string, "code") && p->type == cJSON_Number) { - if (0 == strcmp(p2->string, "report_switch")) - postUserBehavior = (bool)p2->valueint; - else if (0 == strcmp(p2->string, "collapse_switch")) - postCrashInfo = (bool)p2->valueint; - else if (0 == strcmp(p2->string, "device_info_switch")) - postDeviceInfo = (bool)p2->valueint; - - p2 = p2->next; + if (1 == p->valueint) + ret = true; } - } - } + else if (0 == strcmp(p->string, "data") && p->type == cJSON_Object) + { + cJSON* p2 = p->child; + while (nullptr != p2) + { + if (0 == strcmp(p2->string, "report_switch")) + postUserBehavior = (bool)p2->valueint; + else if (0 == strcmp(p2->string, "collapse_switch")) + postCrashInfo = (bool)p2->valueint; + else if (0 == strcmp(p2->string, "device_info_switch")) + postDeviceInfo = (bool)p2->valueint; - cJSON_Delete(json); + p2 = p2->next; + } + } + + p = p->next; + } + + cJSON_Delete(json); + } } + curl_slist_free_all(headers); /* always cleanup */ curl_easy_cleanup(curl); } @@ -137,42 +140,42 @@ static bool CrashFileUpload(const std::string &filePath, std::string &crashFileU if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res)); else - ret = true; + { + std::string str_json = out.str(); // 返回值 + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str()); + + cJSON* json = cJSON_Parse(str_json.c_str()); + if (nullptr != json) + { + cJSON* p = json->child; + while (nullptr != p) + { + if (0 == strcmp(p->string, "code") && p->type == cJSON_Number) + { + if (1 == p->valueint) + ret = true; + } + else if (0 == strcmp(p->string, "data") && p->type == cJSON_Object) + { + cJSON* p2 = p->child; + while (nullptr != p2) + { + if (0 == strcmp(p2->string, "url") && p2->type == cJSON_String) + crashFileUrl = p2->valuestring; + + p2 = p2->next; + } + } + + p = p->next; + } + + cJSON_Delete(json); + } + } /* then cleanup the formpost chain */ curl_formfree(formpost); - - std::string str_json = out.str(); // 返回值 - printf("%s\n", str_json.c_str()); - - cJSON *json = cJSON_Parse(str_json.c_str()); - if (nullptr != json) - { - cJSON *p = json->child; - if (nullptr != p) - { - while (nullptr != p && 0 != strcmp(p->string, "code")) - p = p->next; - - if (nullptr != p && 0 == strcmp(p->string, "code")) - { - cJSON *p2 = p->child; - if (nullptr != p2) - { - while (nullptr != p2 && 0 != strcmp(p2->string, "url")) - p2 = p->next; - - if (nullptr != p2 && 0 == strcmp(p2->string, "url") && p2->type == cJSON_String) - { - crashFileUrl = p2->valuestring; - } - } - } - } - - cJSON_Delete(json); - } - /* always cleanup */ curl_easy_cleanup(curl); } @@ -527,13 +530,30 @@ static bool PostInfo(int type, const std::string &crashFileUrl, const std::strin if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res)); else - ret = true; + { + std::string str_json = out.str(); // 返回值 + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str()); + + cJSON* json = cJSON_Parse(str_json.c_str()); + if (nullptr != json) + { + cJSON* p = json->child; + while (nullptr != p) + { + if (0 == strcmp(p->string, "code") && p->type == cJSON_Number) + { + if (1 == p->valueint) + ret = true; + } + + p = p->next; + } + + cJSON_Delete(json); + } + } curl_slist_free_all(headers); - - std::string str_json = out.str(); // 返回值 - printf("%s\n", str_json.c_str()); - /* always cleanup */ curl_easy_cleanup(curl); } @@ -545,7 +565,7 @@ static bool PostCrashInfo(const std::string& crashFilePath, const std::string& e { std::string crashFileUrl; bool ret = CrashFileUpload(crashFilePath, crashFileUrl); - if (ret) + if (ret && !crashFileUrl.empty()) { ret = PostInfo(3, crashFileUrl, exceptionAddr, "", "", "collapse"); } @@ -646,57 +666,60 @@ static bool GetVersionInfoList(std::list& versionList) if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res)); else - ret = true; - - curl_slist_free_all(headers); - - std::string str_json = out.str(); // 返回值 - printf("%s\n", str_json.c_str()); - - cJSON* json = cJSON_Parse(str_json.c_str()); - if (nullptr != json) { - cJSON* p = json->child; - if (nullptr != p) + std::string str_json = out.str(); // 返回值 + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str()); + + cJSON* json = cJSON_Parse(str_json.c_str()); + if (nullptr != json) { - while (nullptr != p && 0 != strcmp(p->string, "data")) - p = p->next; - - if (nullptr != p && 0 == strcmp(p->string, "data") && p->type == cJSON_Array) + cJSON* p = json->child; + while (nullptr != p) { - cJSON* p2 = p->child; - while (nullptr != p2) + if (0 == strcmp(p->string, "code") && p->type == cJSON_Number) { - VersionInfo version; - - cJSON* p3 = p2->child; - while (nullptr != p3) - { - if (0 == strcmp(p3->string, "full") && p3->type == cJSON_String) - version.url = p3->valuestring; - else if (0 == strcmp(p3->string, "size") && p3->type == cJSON_String) - version.size = atoi(p3->valuestring); - else if (0 == strcmp(p3->string, "desc") && p3->type == cJSON_String) - version.desc = p3->valuestring; - else if (0 == strcmp(p3->string, "bug") && p3->type == cJSON_String) - version.bugInfo = p3->valuestring; - else if (0 == strcmp(p3->string, "md5") && p3->type == cJSON_String) - version.md5 = p3->valuestring; - else if (0 == strcmp(p3->string, "v") && p3->type == cJSON_String) - version.version = p3->valuestring; - - p3 = p3->next; - } - - versionList.push_back(version); - p2 = p2->next; + if (1 == p->valueint) + ret = true; } - } - } + else if (0 == strcmp(p->string, "data") && p->type == cJSON_Array) + { + cJSON* p2 = p->child; + while (nullptr != p2) + { + VersionInfo version; - cJSON_Delete(json); + cJSON* p3 = p2->child; + while (nullptr != p3) + { + if (0 == strcmp(p3->string, "full") && p3->type == cJSON_String) + version.url = p3->valuestring; + else if (0 == strcmp(p3->string, "size") && p3->type == cJSON_String) + version.size = atoi(p3->valuestring); + else if (0 == strcmp(p3->string, "desc") && p3->type == cJSON_String) + version.desc = p3->valuestring; + else if (0 == strcmp(p3->string, "bug") && p3->type == cJSON_String) + version.bugInfo = p3->valuestring; + else if (0 == strcmp(p3->string, "md5") && p3->type == cJSON_String) + version.md5 = p3->valuestring; + else if (0 == strcmp(p3->string, "v") && p3->type == cJSON_String) + version.version = p3->valuestring; + + p3 = p3->next; + } + + versionList.push_back(version); + p2 = p2->next; + } + } + + p = p->next; + } + + cJSON_Delete(json); + } } + curl_slist_free_all(headers); /* always cleanup */ curl_easy_cleanup(curl); } @@ -822,6 +845,8 @@ static bool HttpDownload(const std::string& url, const std::string& saveFilePath #if defined(HG_CMP_MSC) static LONG WINAPI UnhandledExceptionFilterEx(struct _EXCEPTION_POINTERS* ExceptionInfo) { + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "Unhandled Exception!!!"); + HGChar tmpPath[256]; HGBase_GetTmpFileName("dmp", tmpPath, 256);