1.上传崩溃文件接口变动

2.HGVersion类函数的返回值现在正确了
This commit is contained in:
luoliangyi 2022-07-07 15:03:10 +08:00
parent 302824716a
commit 56ee129530
1 changed files with 135 additions and 110 deletions

View File

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