diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 224b4c4..a1d9d6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,8 +65,9 @@ target_include_directories(distromatic PUBLIC # target_compile_options(distromatic PUBLIC -O2 -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER}) # -fno-toplevel-reorder + add_executable(distroquery - distroquery.c + distroquery.cpp functions.c headerlist.c requirelist.c @@ -85,6 +86,7 @@ target_link_libraries(distroquery ${LIBDW_LIBRARIES} ${LIBIBERTY} ) + target_include_directories(distroquery PUBLIC ${RPM_INCLUDE_DIRS} ${LIBREPO_INCLUDE_DIRS} diff --git a/src/distroquery.c b/src/distroquery.cpp similarity index 99% rename from src/distroquery.c rename to src/distroquery.cpp index 07b244e..4e1d7ff 100644 --- a/src/distroquery.c +++ b/src/distroquery.cpp @@ -17,6 +17,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ +#include + #include #include #include @@ -35,26 +37,23 @@ #include #include #include -#include "distromatic.h" #include "config.h" -#include "rpmfunctions.h" -#include "functions.h" // must be as big as ARCHS_MAX (5) const char* ARCHS[ARCHS_MAX] = { "x86_64", "aarch64", "i586", "arm", "" }; static struct configTag *firstconfigtag = NULL; -char *query = ""; +char *query = (char*)""; char *query_package; -char *query_repository = "base"; +char *query_repository = (char*)"base"; char *query_arch = NULL; int query_compact = 0; int query_limit = 10; int query_offset = 0; char query_next[PATH_MAX] = ""; -char *reply_xmltag = "queryreply"; +char *reply_xmltag = (char*)"queryreply"; int reply_plain = 0; -char *lang = ""; +char *lang = (char*)""; int query_archs[ARCHS_MAX] = { 1, 0, 0, 0, 0 }; char *query_path = NULL; @@ -78,7 +77,7 @@ char to_hex(char code) { /* Returns a url-encoded version of str */ /* IMPORTANT: be sure to free() the returned string after use */ char *url_encode(char *str) { - char *pstr = str, *buf = malloc(strlen(str) * 3 + 1), *pbuf = buf; + char *pstr = str, *buf = (char*)malloc(strlen(str) * 3 + 1), *pbuf = buf; while (*pstr) { if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') *pbuf++ = *pstr; @@ -95,8 +94,8 @@ char *url_encode(char *str) { /* Returns a url-decoded version of str */ /* IMPORTANT: be sure to free() the returned string after use */ char *url_decode(char *str) { - if (!str) { char *buf=malloc(1); buf[0]=0; return buf; } - char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf; + if (!str) { char *buf=(char*)malloc(1); buf[0]=0; return buf; } + char *pstr = str, *buf = (char*)malloc(strlen(str) + 1), *pbuf = buf; while (*pstr) { if (*pstr == '%') { if (pstr[1] && pstr[2]) { @@ -369,7 +368,7 @@ int findFileIdFromPath(sqlite3 *db, char** path) { char* pt; char buffer[PATH_MAX]; char sql[PATH_MAX]; - char* linkpath = calloc(strlen(*path),1); + char* linkpath = (char*)calloc(strlen(*path),1); sqlite3_stmt* stmt1; printf("[ROOT]", @@ -512,7 +511,7 @@ void printQueryResponse() { snprintf(dbname, PATH_MAX, "%s%s-%s.db", query_repositories[i]->repository_dir, query_repositories[i]->tag, query_repositories[i]->arch[a]); if (sqlite3_open_v2(dbname, (sqlite3**)&query_repositories[i]->db[a], SQLITE_OPEN_READONLY, NULL)) { - if (query_repositories[i]->db) sqlite3_close(query_repositories[i]->db[a]); + if (query_repositories[i]->db) sqlite3_close((sqlite3*)query_repositories[i]->db[a]); query_repositories[i]->db[a] = NULL; fprintf(stderr, "ERROR: unable to open sqlite3 db %s; ignoring.\n", dbname); } @@ -740,7 +739,7 @@ void printQueryResponse() { if (!query_repositories[i]->db[ARCHS_MAX]) { snprintf(dbname, PATH_MAX, "%s%s-sources.db", query_repositories[i]->repository_dir, query_repositories[i]->tag); if (sqlite3_open_v2(dbname, (sqlite3**)&query_repositories[i]->db[ARCHS_MAX], SQLITE_OPEN_READONLY, NULL)) { - if (query_repositories[i]->db[ARCHS_MAX]) sqlite3_close(query_repositories[i]->db[ARCHS_MAX]); + if (query_repositories[i]->db[ARCHS_MAX]) sqlite3_close((sqlite3*)query_repositories[i]->db[ARCHS_MAX]); query_repositories[i]->db[ARCHS_MAX] = NULL; fprintf(stderr, "ERROR: unable to open sqlite3 db %s; ignoring.\n", dbname); } @@ -792,7 +791,7 @@ void printQueryResponse() { } sqlite3_finalize(statement); } else { - fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg(query_repositories[i]->db[ARCHS_MAX]), sql); + fprintf(stderr, "ERROR: SQLite: %s (%s)\n", sqlite3_errmsg((sqlite3*)query_repositories[i]->db[ARCHS_MAX]), sql); } if (localsourceresults >= query_limit) otherresults = 1; } /* repositories loop */ diff --git a/src/functions.c b/src/functions.c index d71b107..a418d61 100644 --- a/src/functions.c +++ b/src/functions.c @@ -477,12 +477,12 @@ strip_separators(char *st, const char *sepstr) } humanDate * -simpleTimeToTemplate(long calendartime, const char* template, humanDate * strdate) +simpleTimeToTemplate(long calendartime, const char* templ, humanDate * strdate) { struct tm *ltime; ltime = localtime((time_t *) & calendartime); - strftime((char *) strdate, 16, template, ltime); + strftime((char *) strdate, 16, templ, ltime); return strdate; } diff --git a/src/include/distroquery.hpp b/src/include/distroquery.hpp new file mode 100644 index 0000000..0c7ee74 --- /dev/null +++ b/src/include/distroquery.hpp @@ -0,0 +1,33 @@ +/* + * distroquery - tool for querying data generated by distromatic + * + * Copyright (C) 2024 by Silvan Calarco + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of version 2 of the GNU General Public License as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY, to the extent permitted by law; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + */ +#define HDSIZE 16 +#define SSSIZE 24 + +extern "C" typedef char humanDate[HDSIZE]; +extern "C" typedef char sizeString[SSSIZE]; + +extern "C" char *humanSize(long long sbytes, sizeString *s); +extern "C" humanDate *simpleTimeToTemplate(long calendartime, const char* templ, humanDate * strdate); +extern "C" humanDate *simpleTimeToHuman(long calendartime, humanDate * strdate); +extern "C" const char *htmlclean(const char *source,char *dest,unsigned int max); +extern "C" const char *htmlcleanNoBr(const char *source,char *dest,unsigned int max); +extern "C" int get_favicon_from_url(const char* url,char *buf,int bufsize); +extern "C" void backtraceHandler(int sig); +extern "C" struct configTag* findRepositoryByTag(const char *tag); +extern "C" struct configTag* read_configuration(const char *confFile); diff --git a/src/include/functions.h b/src/include/functions.h index 3b301e3..1298b51 100644 --- a/src/include/functions.h +++ b/src/include/functions.h @@ -30,8 +30,7 @@ void *memndup(void *memp, size_t size); void log_debug_set(int value); void logmsg(int level, const char *msg, ...); char *strip_separators(char *st, const char *sepstr); -humanDate * -simpleTimeToTemplate(long calendartime, const char* template, humanDate * strdate); +humanDate *simpleTimeToTemplate(long calendartime, const char* templ, humanDate * strdate); humanDate *simpleTimeToHuman(long calendartime, humanDate * strdate); char *humanSize(long long sbytes, sizeString *s); void fprintf_depstable_filtered_var(FILE* f,char* st);