fix bug 230622 230621

This commit is contained in:
shaozhimin 2024-05-23 20:34:08 +08:00
parent c1286a7553
commit 9bb74f1292
1 changed files with 55 additions and 23 deletions

View File

@ -52,6 +52,11 @@ static char *_kdk_storage_get_Cache(BrowserEnum type)
break;
}
char line[1024];
int start = 0, def = 0;
char configs[10][64];
memset(configs, 0, 10 * 64);
char path[64];
memset(path, 0, 64);
while (fgets(line, sizeof(line), fp))
{
line[strcspn(line, "\n")] = 0;
@ -59,25 +64,34 @@ static char *_kdk_storage_get_Cache(BrowserEnum type)
// Parse key and value
char *key = strtok(line, "=");
char *value = strtok(NULL, "=");
char start[4], path[64];
if (key != NULL && value != NULL)
{
if (0 == strcmp(key, "StartWithLastProfile"))
strncpy(start, value, strlen(value));
start = atoi(value);
if (0 == strcmp(key, "Path"))
{
strncpy(path, value, strlen(value));
}
if (0 == strcmp(key, "Default"))
{
if (0 == strcmp(start, value))
{
sprintf(result, "%s/.mozilla/firefox/%s/cache2", home, path);
break;
}
def = atoi(value);
}
}
else
{
memcpy(configs[def], path, 64);
def = 0;
memset(path, 0, 64);
}
}
fclose(fp);
if (start > 0)
sprintf(result, "%s/.mozilla/firefox/%s/cache2", home, configs[start]);
else
{
klog_err("%s -> Not have default profile\n", __func__);
return NULL;
}
}
break;
case Chrome:
@ -122,6 +136,11 @@ static char *_kdk_storage_get_cookie(BrowserEnum type)
break;
}
char line[1024];
int start = 0, def = 0;
char configs[10][64];
memset(configs, 0, 10 * 64);
char path[64];
memset(path, 0, 64);
while (fgets(line, sizeof(line), fp))
{
line[strcspn(line, "\n")] = 0;
@ -129,25 +148,34 @@ static char *_kdk_storage_get_cookie(BrowserEnum type)
// Parse key and value
char *key = strtok(line, "=");
char *value = strtok(NULL, "=");
char start[4], path[64];
if (key != NULL && value != NULL)
{
if (0 == strcmp(key, "StartWithLastProfile"))
strncpy(start, value, strlen(value));
start = atoi(value);
if (0 == strcmp(key, "Path"))
{
strncpy(path, value, strlen(value));
}
if (0 == strcmp(key, "Default"))
{
if (0 == strcmp(start, value))
{
sprintf(result, "%s/.mozilla/firefox/%s/cookies.sqlite", home, path);
break;
}
def = atoi(value);
}
}
else
{
memcpy(configs[def], path, 64);
def = 0;
memset(path, 0, 64);
}
}
fclose(fp);
if (start > 0)
sprintf(result, "%s/.mozilla/firefox/%s/cookies.sqlite", home, configs[start]);
else
{
klog_err("%s -> Not have default profile\n", __func__);
return NULL;
}
}
break;
case Chrome:
@ -175,14 +203,15 @@ char *kdk_storage_get_default_cookie_path()
if (NULL == default_browser)
return NULL;
klog_info("%s -> Default Browser %s\n", __func__, default_browser);
char *result = NULL;
if (strstr("qax", default_browser))
if (strstr(default_browser, "Qax"))
result = _kdk_storage_get_cookie(Qax);
else if (strstr("chrome", default_browser))
else if (strstr(default_browser, "Chrome"))
result = _kdk_storage_get_cookie(Chrome);
else if (strstr("firefox", default_browser))
else if (strstr(default_browser, "Firefox"))
result = _kdk_storage_get_cookie(FireFox);
else if (strstr("chromeium", default_browser))
else if (strstr(default_browser, "Chromium"))
result = _kdk_storage_get_cookie(Chromium);
else
result = _kdk_storage_get_cookie(None);
@ -230,7 +259,7 @@ char *kdk_storage_get_default_internetCache_path(char *name)
else if (strstr("chromeium", name))
result = _kdk_storage_get_Cache(Chromium);
else
result = _kdk_storage_get_cookie(None);
result = _kdk_storage_get_Cache(None);
return result;
}
@ -378,7 +407,10 @@ int kdk_storage_read_file(const char *file_name, char *buffer, unsigned long siz
int kdk_storage_write_file(const char *file_name, const char *data, unsigned long length)
{
if (-1 == access(file_name, F_OK))
{
klog_err("%s -> File not exists\n", __func__);
return -1;
}
int fd = open(file_name, O_WRONLY | O_APPEND);
if (-1 == fd)
@ -533,13 +565,13 @@ char *kdk_storage_resolve_symbolic_link(const char *file_name)
if (S_ISLNK(file_stat.st_mode))
{
char link_target[1024];
memset(link_target, 0, 1024);
ssize_t len = readlink(file_name, link_target, sizeof(link_target) - 1);
if (-1 == len)
{
klog_err("%s -> Read link failed: %s\n", __func__, strerror(errno));
return NULL;
}
result = strdup(link_target);
}
@ -549,7 +581,7 @@ char *kdk_storage_resolve_symbolic_link(const char *file_name)
}
else
{
klog_err("%s -> %s is neither a symbolic link nor a hard link\n", __func__);
klog_err("%s -> %s is neither a symbolic link nor a hard link\n", __func__, file_name);
}
return result;