distroquery: fixes for query_path search
This commit is contained in:
parent
5b3b2caa2e
commit
eca33e1e9e
@ -91,7 +91,7 @@ char *reply_xmltag = "queryreply";
|
||||
int reply_plain = 0;
|
||||
char *lang = "";
|
||||
int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 };
|
||||
char *file_browser = NULL;
|
||||
char *query_path = NULL;
|
||||
|
||||
struct configTag *query_repositories[100];
|
||||
|
||||
@ -317,30 +317,37 @@ void printInputForm() {
|
||||
}
|
||||
}
|
||||
|
||||
int findFileIdFromPath(sqlite3 *db, char* path) {
|
||||
int findFileIdFromPath(sqlite3 *db, char** path) {
|
||||
int frompos = 1, topos;
|
||||
int parent = -1;
|
||||
char* pt;
|
||||
char buffer[PATH_MAX];
|
||||
char sql[PATH_MAX];
|
||||
char* linkpath = calloc(strlen(*path),0);
|
||||
sqlite3_stmt* stmt1;
|
||||
|
||||
printf("[<a href='javascript:distroquery_request(\"repository=%s&arch=%s&file_browser=/\")'>ROOT</a>]",
|
||||
printf("[<a href='javascript:distroquery_request(\"repository=%s&arch=%s&path=/\")'>ROOT</a>]",
|
||||
query_repository, query_arch);
|
||||
while (frompos < strlen(path)) {
|
||||
pt = strchr(path + frompos, '/');
|
||||
if (pt) topos = pt - path; else topos = strlen(path);
|
||||
strncpy(buffer, path + frompos, topos - frompos);
|
||||
printf("/<a href='javascript:distroquery_request(\"repository=%s&arch=%s&file_browser=/%s\")'>%s</a>",
|
||||
query_repository, query_arch, buffer, buffer);
|
||||
while (frompos < strlen(*path)) {
|
||||
pt = strchr(*path + frompos, '/');
|
||||
if (pt) topos = pt - *path; else topos = strlen(*path);
|
||||
strncpy(buffer, *path + frompos, topos - frompos);
|
||||
buffer[topos-frompos]=0;
|
||||
snprintf(sql, PATH_MAX, "SELECT id FROM files WHERE parent=%d"
|
||||
" AND name='%s'", parent, buffer);
|
||||
if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK && sqlite3_step(stmt1) == SQLITE_ROW) {
|
||||
parent = sqlite3_column_int(stmt1,0);
|
||||
sqlite3_finalize(stmt1);
|
||||
strcat(linkpath, "/");
|
||||
strncat(linkpath, buffer, strlen(*path) - strlen(linkpath));
|
||||
printf("/<a href='javascript:distroquery_request(\"repository=%s&arch=%s&path=%s\")'>%s</a>",
|
||||
query_repository, query_arch, linkpath, buffer);
|
||||
}
|
||||
frompos = topos + 1;
|
||||
}
|
||||
/* return clean path */
|
||||
//free(path);
|
||||
*path = linkpath;
|
||||
return parent;
|
||||
}
|
||||
|
||||
@ -358,7 +365,7 @@ void printFileBrowser() {
|
||||
|
||||
snprintf(dbname, PATH_MAX, "%s%s-%s-files.db", ct->repository_dir, ct->tag, query_arch);
|
||||
if (!sqlite3_open_v2(dbname, &dbf, SQLITE_OPEN_READONLY, NULL)) {
|
||||
startid = findFileIdFromPath(dbf, file_browser);
|
||||
startid = findFileIdFromPath(dbf, &query_path);
|
||||
snprintf(sql, PATH_MAX, "SELECT * FROM files WHERE"
|
||||
" parent=%d"
|
||||
" ORDER BY name", startid);
|
||||
@ -379,13 +386,13 @@ void printFileBrowser() {
|
||||
printf("<tr><td style=\"font-family:courier\">%s</td><td style=\"font-family:courier\">%s</td>"
|
||||
"<td style=\"font-family:courier\">%s</td>"
|
||||
"<td width=50%% style=\"font-family:courier\">"
|
||||
"<a href='javascript:distroquery_request(\"repository=%s&arch=%s&file_browser=%s/%s\")'>%s</a></td>",
|
||||
"<a href='javascript:distroquery_request(\"repository=%s&arch=%s&path=%s/%s\")'>%s</a></td>",
|
||||
sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, "fileusers", "name")),
|
||||
sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, "filegroups", "name")),
|
||||
expandFileFlags(flags, sql),
|
||||
query_repository,
|
||||
query_arch,
|
||||
file_browser,
|
||||
query_path,
|
||||
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
|
||||
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")));
|
||||
} else {
|
||||
@ -406,11 +413,11 @@ void printFileBrowser() {
|
||||
}
|
||||
if (cnt == 0) {
|
||||
printf("<tr><td></td><td></td><td></td>"
|
||||
"<td width=50%% style=\"font-family:courier\"><a href='javascript:distroquery_request(\"repository=%s&arch=%s&file_browser=%s/%s\")'>%s</a></td>"
|
||||
"<td width=50%% style=\"font-family:courier\"><a href='javascript:distroquery_request(\"repository=%s&arch=%s&path=%s/%s\")'>%s</a></td>"
|
||||
"<td></td></tr>",
|
||||
query_repository,
|
||||
query_arch,
|
||||
file_browser,
|
||||
query_path,
|
||||
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")),
|
||||
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")));
|
||||
}
|
||||
@ -1172,8 +1179,8 @@ void parse_request_variables(char *data) {
|
||||
reply_plain = strstr(valuetok, "true") == valuetok;
|
||||
} else if (!strcmp(vartok, "query_compact")) {
|
||||
query_compact = strstr(valuetok, "true") == valuetok;
|
||||
} else if (!strcmp(vartok, "file_browser")) {
|
||||
file_browser = valuetok;
|
||||
} else if (!strcmp(vartok, "path")) {
|
||||
query_path = valuetok;
|
||||
} else {
|
||||
/* fields to make reusable query string for next pages */
|
||||
if (!strcmp(vartok, "query")) {
|
||||
@ -1263,7 +1270,7 @@ main(int argc, char *argv[])
|
||||
} else if (query && strlen(query)) {
|
||||
printQueryResponse();
|
||||
responsed = 1;
|
||||
} else if (file_browser) {
|
||||
} else if (query_path) {
|
||||
printFileBrowser();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user