X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=mysql_selector.c;h=e2c9562c7aa64bb14e4f5f4830ca0117130aaa63;hp=82f197cdd9ce0362167cc017af09fea59be13ea8;hb=2a8029478dfc65f0c935d864faf4aea9e3deb27d;hpb=3049c5f8212fa4b0a6c502fd0a8b11b96aea63f2 diff --git a/mysql_selector.c b/mysql_selector.c index 82f197cd..e2c9562c 100644 --- a/mysql_selector.c +++ b/mysql_selector.c @@ -663,7 +663,7 @@ out: return ret; } -static char *escape_blob(char* old, int size) +static char *escape_blob(const char* old, int size) { char *new; @@ -674,7 +674,7 @@ static char *escape_blob(char* old, int size) return new; } -static char *escape_str(char* old) +static char *escape_str(const char* old) { return escape_blob(old, strlen(old)); } @@ -693,7 +693,7 @@ static char *escaped_basename(const char *name) /* * new attribute */ -static int com_na(__unused int fd, int argc, char *argv[]) +static int com_na(__a_unused int fd, int argc, char *argv[]) { char *q, *tmp; int ret; @@ -714,7 +714,7 @@ static int com_na(__unused int fd, int argc, char *argv[]) /* * delete attribute */ -static int com_da(__unused int fd, int argc, char *argv[]) +static int com_da(__a_unused int fd, int argc, char *argv[]) { char *q, *tmp; int ret; @@ -865,7 +865,7 @@ static void *get_all_attributes(void) /* * list all attributes */ -static int com_laa(int fd, int argc, __unused char *argv[]) +static int com_laa(int fd, int argc, __a_unused char *argv[]) { void *result; int ret; @@ -1465,7 +1465,7 @@ out: /* * remove/add entries */ -static int com_rm_ne(__unused int fd, int argc, char *argv[]) +static int com_rm_ne(__a_unused int fd, int argc, char *argv[]) { int ne = !strcmp(argv[0], "ne"); int i, ret; @@ -1487,7 +1487,7 @@ static int com_rm_ne(__unused int fd, int argc, char *argv[]) /* * mv: rename entry */ -static int com_mv(__unused int fd, int argc, char *argv[]) +static int com_mv(__a_unused int fd, int argc, char *argv[]) { char *q, *dn, *ebn1 = NULL, *ebn2 = NULL, *edn = NULL; int ret; @@ -1545,7 +1545,7 @@ out: * picass: associate pic to audio file * snp: set numplayed */ -static int com_set(__unused int fd, int argc, char *argv[]) +static int com_set(__a_unused int fd, int argc, char *argv[]) { char *q, *ebn; long unsigned id; @@ -1573,7 +1573,7 @@ static int com_set(__unused int fd, int argc, char *argv[]) /* * picch: change entry's name in pics table */ -static int com_picch(__unused int fd, int argc, char *argv[]) +static int com_picch(__a_unused int fd, int argc, char *argv[]) { int ret; long unsigned id; @@ -1596,7 +1596,7 @@ static int com_picch(__unused int fd, int argc, char *argv[]) /* * piclist: print list of pics in db */ -static int com_piclist(__unused int fd, int argc, __unused char *argv[]) +static int com_piclist(__a_unused int fd, int argc, __a_unused char *argv[]) { void *result = NULL; MYSQL_ROW row; @@ -1698,7 +1698,7 @@ out: } /* strdel */ -static int com_strdel(__unused int fd, int argc, char *argv[]) +static int com_strdel(__a_unused int fd, int argc, char *argv[]) { char *q, *tmp; int ret; @@ -1751,7 +1751,7 @@ static int com_ls(int fd, int argc, char *argv[]) /* * summary */ -static int com_summary(__unused int fd, int argc, __unused char *argv[]) +static int com_summary(__a_unused int fd, int argc, __a_unused char *argv[]) { MYSQL_ROW row; MYSQL_ROW row2; @@ -1840,10 +1840,10 @@ static int update_audio_file(char *name) ret = real_query(q); free(q); out: - if (ebn) - free(ebn); + free(ebn); return ret; } + /* If called as child, mmd_lock must be held */ static void update_mmd(char *info) { @@ -1861,7 +1861,7 @@ static void update_audio_file_server_handler(char *name) update_audio_file(name); } -static int com_us(__unused int fd, int argc, char *argv[]) +static int com_us(__a_unused int fd, int argc, char *argv[]) { char *tmp; int ret; @@ -1892,7 +1892,7 @@ static void refresh_selector_info(void) } /* select previous/next stream */ -static int com_ps(__unused int fd, int argc, char *argv[]) +static int com_ps(__a_unused int fd, int argc, char *argv[]) { char *query, *stream = get_current_stream(); void *result = get_result("select name from streams"); @@ -1959,7 +1959,7 @@ out: } /* streams */ -static int com_streams(int fd, int argc, __unused char *argv[]) +static int com_streams(int fd, int argc, __a_unused char *argv[]) { unsigned int num_rows; int i, ret = -E_NORESULT; @@ -2265,7 +2265,7 @@ out: /* * verify / clean */ -static int com_vrfy(int fd, int argc, __unused char *argv[]) +static int com_vrfy(int fd, int argc, __a_unused char *argv[]) { char *query; int ret, vrfy_mode = strcmp(argv[0], "clean"); @@ -2321,7 +2321,6 @@ static int mysql_write_tmp_file(const char *dir, const char *name) { int ret = -E_TMPFILE; char *msg = make_message("%s\t%s\n", dir, name); - if (fputs(msg, out_file) != EOF) ret = 1; free(msg); @@ -2331,7 +2330,7 @@ static int mysql_write_tmp_file(const char *dir, const char *name) /* * update database */ -static int com_upd(int fd, int argc, __unused char *argv[]) +static int com_upd(int fd, int argc, __a_unused char *argv[]) { char *tempname = NULL, *query = NULL; int ret, out_fd = -1, num = 0; @@ -2366,7 +2365,7 @@ static int com_upd(int fd, int argc, __unused char *argv[]) goto out; if ((ret = real_query("delete from dir")) < 0) goto out; - query = make_message("load data infile '%s' into table dir " + query = make_message("load data infile '%s' ignore into table dir " "fields terminated by '\t' lines terminated by '\n' " "(dir, name)", tempname); ret = real_query(query); @@ -2384,12 +2383,15 @@ static int com_upd(int fd, int argc, __unused char *argv[]) goto out; } while ((row = mysql_fetch_row(result))) { + char *erow; ret = -E_NOROW; if (!row[0]) goto out; send_va_buffer(fd, "new entry: %s\n", row[0]); + erow = escape_str(row[0]); query = make_message("insert into data (name, pic_id) values " - "('%s','%s')", row[0], "1"); + "('%s','%s')", erow, "1"); + free(erow); ret = real_query(query); free(query); if (ret < 0) @@ -2420,9 +2422,8 @@ static char **server_get_audio_file_list(unsigned int num) free(stream); query = make_message("%s limit %d", tmp, num); free(tmp); - if (!query) - goto err_out; result = get_result(query); + free(query); if (!result) goto err_out; num_rows = mysql_num_rows(result); @@ -2444,8 +2445,6 @@ err_out: free(list); list = NULL; success: - if (query) - free(query); if (result) mysql_free_result(result); return list;