From: Andre Noll Date: Sat, 26 May 2007 19:38:36 +0000 (+0200) Subject: be more carful wrt. signed vs. unsigned argument passing X-Git-Tag: v0.2.17~66 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=ae0e4594c6a0312c5b4b4c0bde86f9c12253d11b;hp=7f053695dcb0ab70745a457048e6fb0b83d75d47 be more carful wrt. signed vs. unsigned argument passing --- diff --git a/aac_afh.c b/aac_afh.c index 8b635c48..126eb6ce 100644 --- a/aac_afh.c +++ b/aac_afh.c @@ -27,7 +27,7 @@ #include "string.h" #include "aac.h" -static int aac_find_stsz(unsigned char *buf, off_t buflen, off_t *skip) +static int aac_find_stsz(unsigned char *buf, size_t buflen, off_t *skip) { int i; @@ -52,7 +52,7 @@ static int aac_find_stsz(unsigned char *buf, off_t buflen, off_t *skip) } static ssize_t aac_compute_chunk_table(struct audio_format_info *afi, - unsigned char *map, off_t numbytes) + unsigned char *map, size_t numbytes) { int ret, i; size_t sum = 0; @@ -76,25 +76,32 @@ static ssize_t aac_compute_chunk_table(struct audio_format_info *afi, return skip; } -static long unsigned aac_set_chunk_tv(struct audio_format_info *afi, - mp4AudioSpecificConfig *mp4ASC) +static int aac_set_chunk_tv(struct audio_format_info *afi, + mp4AudioSpecificConfig *mp4ASC, long unsigned *seconds) { - float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023, - ms = 1000.0 * afi->chunks_total * tmp / mp4ASC->samplingFrequency; + float tmp = mp4ASC->sbr_present_flag == 1? 2047 : 1023; struct timeval total; + long unsigned ms = 1000.0 * afi->chunks_total * tmp + / mp4ASC->samplingFrequency; + if (!mp4ASC->samplingFrequency) + return -E_MP4ASC; + ms = 1000.0 * afi->chunks_total * tmp / mp4ASC->samplingFrequency; ms2tv(ms, &total); tv_divide(afi->chunks_total, &total, &afi->chunk_tv); - PARA_INFO_LOG("%luHz, %fs (%lu x %lums)\n", + PARA_INFO_LOG("%luHz, %lus (%lu x %lums)\n", mp4ASC->samplingFrequency, ms / 1000, afi->chunks_total, tv2ms(&afi->chunk_tv)); - return ms < 1000? -E_MP4ASC : ms / 1000; + if (ms < 1000) + return -E_MP4ASC; + *seconds = ms / 1000; + return 1; } /* * Init m4a file and write some tech data to given pointers. */ -static int aac_get_file_info(char *map, off_t numbytes, +static int aac_get_file_info(char *map, size_t numbytes, struct audio_format_info *afi) { int i; @@ -126,7 +133,9 @@ static int aac_get_file_info(char *map, off_t numbytes, if (ret < 0) goto out; skip = ret; - afi->seconds_total = aac_set_chunk_tv(afi, &mp4ASC); + ret = aac_set_chunk_tv(afi, &mp4ASC, &afi->seconds_total); + if (ret < 0) + goto out; ret = aac_find_entry_point(umap + skip, numbytes - skip, &skip); if (ret < 0) goto out; diff --git a/afh.h b/afh.h index 38e1ff04..e0087a56 100644 --- a/afh.h +++ b/afh.h @@ -48,7 +48,7 @@ struct audio_format_info { /** the number of chunks this audio file contains */ long unsigned chunks_total; /** the length of the audio file in seconds */ - int seconds_total; + long unsigned seconds_total; /** a string that gets filled in by the audio format handler */ char info_string[AUDIO_FILE_INFO_SIZE]; /** @@ -112,7 +112,7 @@ struct audio_format_handler { * * \sa struct audio_format_info */ - int (*get_file_info)(char *map, off_t numbytes, + int (*get_file_info)(char *map, size_t numbytes, struct audio_format_info *afi); }; diff --git a/audioc.c b/audioc.c index 3cc5b0bd..551c34e6 100644 --- a/audioc.c +++ b/audioc.c @@ -32,7 +32,7 @@ struct audioc_args_info conf; INIT_STDERR_LOGGING(conf.loglevel_arg); -static char *concat_args(const int argc, char * const *argv) +static char *concat_args(unsigned argc, char * const *argv) { int i; char *buf = NULL; for (i = 0; i < argc; i++) { @@ -77,10 +77,10 @@ static char *configfile_exists(void) int main(int argc, char *argv[]) { struct sockaddr_un unix_addr; - int ret = -E_AUDIOC_SYNTAX, fd, loaded = 0; + int ret = -E_AUDIOC_SYNTAX, fd; char *cf, *socket_name, *randname = para_tmpname(), *tmpsocket_name = NULL, *buf = NULL, *hn = para_hostname(), *args, *home = para_homedir(); - + size_t bufsize = conf.bufsize_arg, loaded = 0; if (audioc_cmdline_parser(argc, argv, &conf)) goto out; @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) args = conf.inputs_num? concat_args(conf.inputs_num, conf.inputs) : para_strdup("stat"); - buf = para_malloc(conf.bufsize_arg); + buf = para_malloc(bufsize); if (conf.socket_given) socket_name = para_strdup(conf.socket_arg); else @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) fd_set rfd, wfd; FD_ZERO(&rfd); FD_ZERO(&wfd); - if (loaded < conf.bufsize_arg) + if (loaded < bufsize) para_fd_set(fd, &rfd, &max_fileno); if (loaded > 0) { para_fd_set(STDOUT_FILENO, &wfd, &max_fileno); @@ -140,9 +140,9 @@ int main(int argc, char *argv[]) ret = para_select(max_fileno + 1, &rfd, &wfd, NULL); if (ret < 0) goto out; - if (loaded < conf.bufsize_arg && FD_ISSET(fd, &rfd)) { + if (loaded < bufsize && FD_ISSET(fd, &rfd)) { len = recv_bin_buffer(fd, buf + loaded, - conf.bufsize_arg - loaded); + bufsize - loaded); if (len <= 0) { ret = len < 0? -E_AUDIOC_READ : 0; goto out; diff --git a/audiod_command.c b/audiod_command.c index 77a0a1ee..2d5bb799 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -426,6 +426,7 @@ int handle_connect(int accept_fd) int i, argc, ret, clifd = -1; char *cmd = NULL, *p, *buf = para_calloc(MAXLINE), **argv = NULL; struct sockaddr_un unix_addr; + uid_t uid; ret = para_accept(accept_fd, &unix_addr, sizeof(struct sockaddr_un)); if (ret < 0) @@ -434,8 +435,9 @@ int handle_connect(int accept_fd) ret = recv_cred_buffer(clifd, buf, MAXLINE - 1); if (ret < 0) goto out; + uid = ret; PARA_INFO_LOG("connection from user %i, buf: %s\n", ret, buf); - ret = check_perms(ret); + ret = check_perms(uid); if (ret < 0) goto out; ret = -E_INVALID_AUDIOD_CMD; diff --git a/command.c b/command.c index de56ce82..2bd10191 100644 --- a/command.c +++ b/command.c @@ -151,7 +151,7 @@ static char *get_status(struct misc_meta_data *nmmd) bar = para_basename(nmmd->filename); gettimeofday(&now, NULL); ret = make_message( - "%s:%lu\n" "%s:%s\n" "%s:%i\n" "%s:%u\n" + "%s:%zu\n" "%s:%s\n" "%s:%lu\n" "%s:%u\n" "%s:%s\n" "%s:%s\n" "%s:%s\n" "%s:%s\n" "%s:%li\n" "%s:%s\n" "%s" "%s" "%s:%s\n" "%s:%lu.%lu\n" "%s:%lu.%lu\n", @@ -756,6 +756,42 @@ static void rc4_send(unsigned long len, const unsigned char *indata, RC4(&rc4_send_key, len, indata, outdata); } +static int read_command(int fd, char **result) +{ + int ret; + char buf[4096]; + char *command = NULL; + + for (;;) { + size_t numbytes; + char *p; + + ret = recv_buffer(fd, buf, sizeof(buf)); + if (ret < 0) + goto out; + if (!ret) + break; + numbytes = ret; + ret = -E_COMMAND_SYNTAX; + if (command && numbytes + strlen(command) > MAX_COMMAND_LEN) /* DOS */ + goto out; + command = para_strcat(command, buf); + p = strstr(command, EOC_MSG); + if (p) { + *p = '\0'; + break; + } + } + ret = command? 1 : -E_COMMAND_SYNTAX; +out: + if (ret < 0) + free(command); + else + *result = command; + return ret; + +} + /** * perform user authentication and execute a command * @@ -789,7 +825,7 @@ static void rc4_send(unsigned long len, const unsigned char *indata, */ int handle_connect(int fd, struct sockaddr_in *addr) { - int numbytes, ret, argc, use_rc4 = 0; + int ret, argc, use_rc4 = 0; char buf[4096]; unsigned char crypt_buf[MAXLINE]; struct user *u; @@ -797,6 +833,7 @@ int handle_connect(int fd, struct sockaddr_in *addr) long unsigned challenge_nr, chall_response; char **argv = NULL; char *p, *command = NULL; + size_t numbytes; signal(SIGCHLD, SIG_IGN); signal(SIGINT, SIG_DFL); @@ -845,17 +882,17 @@ int handle_connect(int fd, struct sockaddr_in *addr) if (ret < 0) goto err_out; /* recv decrypted number */ - numbytes = recv_buffer(fd, buf, sizeof(buf)); - ret = numbytes; + ret = recv_buffer(fd, buf, sizeof(buf)); if (ret < 0) goto err_out; + numbytes = ret; ret = -E_AUTH; if (!numbytes) goto err_out; if (sscanf(buf, CHALLENGE_RESPONSE_MSG "%lu", &chall_response) < 1 || chall_response != challenge_nr) goto err_out; - /* auth successful. Send 'Proceed' message */ + /* auth successful, send 'Proceed' message */ PARA_INFO_LOG("good auth for %s (%lu)\n", u->name, challenge_nr); sprintf(buf, "%s", PROCEED_MSG); if (use_rc4) { @@ -872,24 +909,12 @@ int handle_connect(int fd, struct sockaddr_in *addr) goto err_out; if (use_rc4) enable_crypt(fd, rc4_recv, rc4_send, NULL); - /* read command */ - while ((numbytes = recv_buffer(fd, buf, sizeof(buf))) > 0) { -// PARA_INFO_LOG("recvd: %s (%d)\n", buf, numbytes); - ret = -E_COMMAND_SYNTAX; - if (command && numbytes + strlen(command) > MAX_COMMAND_LEN) /* DOS */ - goto err_out; - command = para_strcat(command, buf); - if ((p = strstr(command, EOC_MSG))) { - *p = '\0'; - break; - } - } - ret = numbytes; + ret = read_command(fd, &command); if (ret < 0) goto err_out; ret = -E_BAD_CMD; - /* parse command */ - if (!(cmd = parse_cmd(command))) + cmd = parse_cmd(command); + if (!cmd) goto err_out; /* valid command, check permissions */ ret = check_perms(u->perms, cmd); @@ -909,10 +934,9 @@ int handle_connect(int fd, struct sockaddr_in *addr) goto out; } err_out: - if (ret != -E_SEND && ret != -E_RECV) { - PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-ret)); + PARA_NOTICE_LOG("%s\n", PARA_STRERROR(-ret)); + if (ret != -E_SEND && ret != -E_RECV) send_va_buffer(fd, "%s\n", PARA_STRERROR(-ret)); - } ret = EXIT_FAILURE; out: free(command); diff --git a/crypt.c b/crypt.c index 0d8b4241..b3bac466 100644 --- a/crypt.c +++ b/crypt.c @@ -93,14 +93,17 @@ void rsa_free(RSA *rsa) * \sa RSA_private_decrypt(3) **/ int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *inbuf, - int rsa_inlen) + unsigned rsa_inlen) { RSA *rsa; - int ret = get_rsa_key(key_file, &rsa, LOAD_PRIVATE_KEY); + int ret, inlen = rsa_inlen; + if (inlen < 0) + return -E_RSA; + ret = get_rsa_key(key_file, &rsa, LOAD_PRIVATE_KEY); if (ret < 0) return ret; - ret = RSA_private_decrypt(rsa_inlen, inbuf, outbuf, rsa, RSA_PKCS1_PADDING); + ret = RSA_private_decrypt(inlen, inbuf, outbuf, rsa, RSA_PKCS1_PADDING); rsa_free(rsa); return (ret > 0)? ret : -E_DECRYPT; } @@ -118,7 +121,7 @@ int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *in * \sa para_decrypt_buffer() */ int para_decrypt_challenge(char *key_file, long unsigned *challenge_nr, - unsigned char *inbuf, int rsa_inlen) + unsigned char *inbuf, unsigned rsa_inlen) { unsigned char *rsa_out = OPENSSL_malloc(rsa_inlen + 1); int ret = para_decrypt_buffer(key_file, rsa_out, inbuf, rsa_inlen); @@ -145,10 +148,13 @@ int para_decrypt_challenge(char *key_file, long unsigned *challenge_nr, * \sa RSA_public_encrypt(3) */ int para_encrypt_buffer(RSA *rsa, unsigned char *inbuf, - const unsigned len, unsigned char *outbuf) + unsigned len, unsigned char *outbuf) { - int ret = RSA_public_encrypt(len, inbuf, outbuf, rsa, - RSA_PKCS1_PADDING); + int ret, flen = len; /* RSA_public_encrypt expects a signed int */ + + if (flen < 0) + return -E_ENCRYPT; + ret = RSA_public_encrypt(flen, inbuf, outbuf, rsa, RSA_PKCS1_PADDING); return ret < 0? -E_ENCRYPT : ret; } diff --git a/crypt.h b/crypt.h index 1f7b8a86..54586aa6 100644 --- a/crypt.h +++ b/crypt.h @@ -20,13 +20,13 @@ #include int para_decrypt_challenge(char *key_file, long unsigned *challenge_nr, - unsigned char *buf, int rsa_inlen); + unsigned char *buf, unsigned rsa_inlen); int para_encrypt_challenge(RSA* rsa, long unsigned challenge_nr, unsigned char *outbuf); -int para_encrypt_buffer(RSA* rsa, unsigned char *inbuf, const unsigned len, +int para_encrypt_buffer(RSA* rsa, unsigned char *inbuf, unsigned len, unsigned char *outbuf); int para_decrypt_buffer(char *key_file, unsigned char *outbuf, unsigned char *inbuf, - int rsa_inlen); + unsigned rsa_inlen); int get_rsa_key(char *key_file, RSA **rsa, int private); void rsa_free(RSA *rsa); diff --git a/dccp_send.c b/dccp_send.c index e4b50879..738e9b6c 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -151,8 +151,9 @@ static void dccp_send(long unsigned current_chunk, __a_unused long unsigned chunks_sent, const char *buf, size_t len) { struct dccp_client *dc, *tmp; - int ret, header_len; + int ret; char *header_buf; + size_t header_len; if (listen_fd < 0 || !len) return; @@ -171,7 +172,7 @@ static void dccp_send(long unsigned current_chunk, ret = dccp_write(dc->fd, header_buf, header_len); if (ret != header_len) { int err = errno; - PARA_ERROR_LOG("header write: %d/%d (%s)\n", + PARA_ERROR_LOG("header write: %d/%zu (%s)\n", ret, header_len, ret < 0? strerror(err) : ""); dccp_shutdown_client(dc); diff --git a/filter_chain.c b/filter_chain.c index ee94e8ff..3a5b85dd 100644 --- a/filter_chain.c +++ b/filter_chain.c @@ -133,21 +133,22 @@ again: conv = 0; list_for_each_entry(fn, &fc->filters, node) { if (*loaded && fn->loaded < fn->bufsize) { - size_t old_fn_loaded = fn->loaded; + size_t size, old_fn_loaded = fn->loaded; // PARA_DEBUG_LOG("fc %p loaded: %zd, calling %s convert\n", // fc, *loaded, fn->filter->name); t->ret = fn->filter->convert(ib, *loaded, fn); if (t->ret < 0) goto err_out; - call_callbacks(fn, ib, t->ret, fn->buf + old_fn_loaded, + size = t->ret; + call_callbacks(fn, ib, size, fn->buf + old_fn_loaded, fn->loaded - old_fn_loaded); - *loaded -= t->ret; - conv += t->ret; - if (*loaded && t->ret) { + *loaded -= size; + conv += size; + if (*loaded && size) { // PARA_DEBUG_LOG("moving %zd bytes in input " // "buffer for %s filter\n", // *loaded, fn->filter->name); - memmove(ib, ib + t->ret, *loaded); + memmove(ib, ib + size, *loaded); } } ib = fn->buf; diff --git a/http_send.c b/http_send.c index 6c912951..97b4d919 100644 --- a/http_send.c +++ b/http_send.c @@ -98,7 +98,7 @@ struct access_info { /** the address to be black/whitelisted */ struct in_addr addr; /** the netmask for this entry */ - int netmask; + unsigned netmask; /** the position of this entry in the access_perm_list */ struct list_head node; }; @@ -207,7 +207,7 @@ static void http_send( long unsigned current_chunk, hc->status != HTTP_READY_TO_STREAM) continue; if (hc->status == HTTP_READY_TO_STREAM) { - int hlen; + unsigned hlen; char *hbuf = vss_get_header(&hlen); if (hbuf && hlen > 0 && current_chunk) { /* need to send header */ @@ -247,7 +247,7 @@ static int host_in_access_perm_list(struct http_client *hc) { struct access_info *ai, *tmp; list_for_each_entry_safe(ai, tmp, &access_perm_list, node) { - unsigned mask = ((~0) >> ai->netmask); + unsigned mask = ((~0U) >> ai->netmask); if ((hc->addr.sin_addr.s_addr & mask) == (ai->addr.s_addr & mask)) return 1; } diff --git a/ipc.c b/ipc.c index b6c525ab..acf0249d 100644 --- a/ipc.c +++ b/ipc.c @@ -57,7 +57,7 @@ int mutex_destroy(int id) return ret < 0? -E_SEM_REMOVE : 1; } -static void para_semop(int id, struct sembuf *sops, int num) +static void para_semop(int id, struct sembuf *sops, unsigned num) { int i; diff --git a/mp3_afh.c b/mp3_afh.c index 4764d3ce..8d4a5416 100644 --- a/mp3_afh.c +++ b/mp3_afh.c @@ -200,7 +200,7 @@ static int compare_headers(struct mp3header *h1,struct mp3header *h2) * retrieve a valid frame header, and a negative return value indicates an * error. */ -static int get_header(unsigned char *map, off_t numbytes, off_t *fpos, +static int get_header(unsigned char *map, size_t numbytes, off_t *fpos, struct mp3header *header) { int fl, ret; @@ -239,7 +239,7 @@ out: * Return the length of the next frame header or zero if the end of the file is * reached. */ -static int mp3_seek_next_header(unsigned char *map, off_t numbytes, off_t *fpos) +static int mp3_seek_next_header(unsigned char *map, size_t numbytes, off_t *fpos) { int k, l = 0, first_len; struct mp3header h, h2; @@ -269,7 +269,7 @@ static int mp3_seek_next_header(unsigned char *map, off_t numbytes, off_t *fpos) return 0; } -static void mp3_get_id3(unsigned char *map, off_t numbytes, off_t *fpos) +static void mp3_get_id3(unsigned char *map, size_t numbytes, off_t *fpos) { mp3.id3_isvalid = 0; mp3.id3.title[0] = '\0'; @@ -307,7 +307,7 @@ static void mp3_get_id3(unsigned char *map, off_t numbytes, off_t *fpos) unpad(mp3.id3.comment); } -static int find_valid_start(unsigned char *map, off_t numbytes, off_t *fpos) +static int find_valid_start(unsigned char *map, size_t numbytes, off_t *fpos) { int frame_len; @@ -325,7 +325,7 @@ static int find_valid_start(unsigned char *map, off_t numbytes, off_t *fpos) return frame_len; } -static int mp3_read_info(unsigned char *map, off_t numbytes, +static int mp3_read_info(unsigned char *map, size_t numbytes, struct audio_format_info *afi) { long fl_avg = 0, freq_avg = 0, br_avg = 0; @@ -340,17 +340,24 @@ static int mp3_read_info(unsigned char *map, off_t numbytes, fpos = 0; mp3.vbr = 0; while (1) { - int freq, br, fl; + unsigned long freq, br, fl; struct timeval tmp, cct; /* current chunk time */ fpos += len; len = find_valid_start(map, numbytes, &fpos); if (len <= 0) break; - freq = header_frequency(&mp3.header); - br = header_bitrate(&mp3.header); - fl = frame_length(&mp3.header); - if (freq < 0 || br < 0 || fl < 0) + ret = header_frequency(&mp3.header); + if (ret < 0) continue; + freq = ret; + ret = header_bitrate(&mp3.header); + if (ret < 0) + continue; + br = ret; + ret = frame_length(&mp3.header); + if (ret < 0) + continue; + fl = ret; tmp.tv_sec = fl; tmp.tv_usec = 0; tv_divide(br * 125, &tmp, &cct); @@ -374,9 +381,9 @@ static int mp3_read_info(unsigned char *map, off_t numbytes, fl_avg = fl; continue; } - freq_avg += (freq - freq_avg) / (afi->chunks_total + 1); - fl_avg += (fl - fl_avg) / (afi->chunks_total + 1); - br_avg += (br - br_avg) / ((long)afi->chunks_total + 1); + freq_avg += ((long)freq - freq_avg) / ((long)afi->chunks_total + 1); + fl_avg += ((long)fl - fl_avg) / ((long)afi->chunks_total + 1); + br_avg += ((long)br - br_avg) / ((long)afi->chunks_total + 1); if (old_br != br) mp3.vbr = 1; old_br = br; @@ -404,7 +411,7 @@ err_out: /* * Read mp3 information from audio file */ -static int mp3_get_file_info(char *map, off_t numbytes, +static int mp3_get_file_info(char *map, size_t numbytes, struct audio_format_info *afi) { int ret; diff --git a/mysql_selector.c b/mysql_selector.c index b2a925e0..a6c66772 100644 --- a/mysql_selector.c +++ b/mysql_selector.c @@ -228,11 +228,11 @@ out: return ret; } -static char *escape_blob(const char* old, int size) +static char *escape_blob(const char* old, size_t size) { char *new; - if (!mysql_ptr || size < 0) + if (!mysql_ptr) return NULL; new = para_malloc(2 * size * sizeof(char) + 1); mysql_real_escape_string(mysql_ptr, new, old, size); @@ -368,8 +368,8 @@ int com_picadd(int fd, int argc, char *argv[]) * print results to fd */ static int print_results(int fd, void *result, - unsigned int top, unsigned int left, - unsigned int bottom, unsigned int right) + my_ulonglong top, my_ulonglong left, + my_ulonglong bottom, my_ulonglong right) { unsigned int i,j; int ret; @@ -399,7 +399,7 @@ int com_verb(int fd, int argc, char *argv[]) { void *result = NULL; int ret; - unsigned int num_rows, num_fields; + my_ulonglong num_rows, num_fields, top = 0, left = 0; char *tmp; if (argc < 2) @@ -416,7 +416,7 @@ int com_verb(int fd, int argc, char *argv[]) num_rows = mysql_num_rows(result); ret = 1; if (num_fields && num_rows) - ret = print_results(fd, result, 0, 0, num_rows - 1, + ret = print_results(fd, result, top, left, num_rows - 1, num_fields - 1); mysql_free_result(result); return ret; @@ -435,7 +435,7 @@ static void *get_all_attributes(void) mysql_free_result(result); return NULL; } - mysql_data_seek(result, 4); /* skip Lastplayed, Numplayed... */ + mysql_data_seek(result, (my_ulonglong)4); /* skip Lastplayed, Numplayed... */ return result; } @@ -446,13 +446,18 @@ int com_laa(int fd, int argc, __a_unused char *argv[]) { void *result; int ret; + my_ulonglong top = 0, left = 0, bottom, right = 0; if (argc != 1) return -E_MYSQL_SYNTAX; result = get_all_attributes(); if (!result) return -E_NOATTS; - ret = print_results(fd, result, 0, 0, mysql_num_rows(result) - 5, 0); + bottom = mysql_num_rows(result); + if (bottom < 5) + return -E_MYSQL_SYNTAX; + bottom -= 5; + ret = print_results(fd, result, top, left, bottom, right); mysql_free_result(result); return ret; } @@ -465,7 +470,7 @@ int com_hist(int fd, int argc, char *argv[]) int ret; void *result = NULL; char *q, *atts; - unsigned int num_rows; + my_ulonglong num_rows, top = 0, left = 0, right = 1; if (argc > 3) return -E_MYSQL_SYNTAX; @@ -488,7 +493,7 @@ int com_hist(int fd, int argc, char *argv[]) num_rows = mysql_num_rows(result); ret = 1; if (num_rows) - ret = print_results(fd, result, 0, 0, num_rows - 1, 1); + ret = print_results(fd, result, top, left, num_rows - 1, right); mysql_free_result(result); return ret; } @@ -501,6 +506,7 @@ int com_last(int fd, int argc, char *argv[]) void *result = NULL; char *q; int num, ret; + my_ulonglong top = 0, left = 0, right = 0; if (argc < 2) num = 10; @@ -514,7 +520,8 @@ int com_last(int fd, int argc, char *argv[]) free(q); if (!result) return -E_NORESULT; - ret = print_results(fd, result, 0, 0, mysql_num_rows(result) - 1, 0); + ret = print_results(fd, result, top, left, mysql_num_rows(result) - 1, + right); mysql_free_result(result); return ret; } @@ -524,7 +531,7 @@ int com_mbox(int fd, int argc, char *argv[]) void *result; MYSQL_ROW row; int ret; - unsigned int num_rows, num_fields; + my_ulonglong num_rows, num_fields, top = 0, left = 0; char *query = para_strdup("select concat('From foo@localhost ', " "date_format(Lastplayed, '%a %b %e %T %Y'), " "'\nReceived: from\nTo: bar\n"); @@ -571,7 +578,8 @@ int com_mbox(int fd, int argc, char *argv[]) num_rows = mysql_num_rows(result); if (!num_fields || !num_rows) goto out; - ret = print_results(fd, result, 0, 0, num_rows - 1, num_fields - 1); + ret = print_results(fd, result, top, left, num_rows - 1, + num_fields - 1); out: free(query); if (result) @@ -592,7 +600,8 @@ static char *get_atts(char *name, int verbose) void *result = NULL, *result2 = NULL; MYSQL_ROW row, row2; int i; - unsigned num_fields; + my_ulonglong num_fields, offset = 4; /* skip Lastplayed, Numplayed... */ + result2 = get_all_attributes(); if (!result2) @@ -609,7 +618,7 @@ static char *get_atts(char *name, int verbose) num_fields = mysql_num_fields(result); if (num_fields < 5) goto out; - mysql_data_seek(result2, 4); /* skip Lastplayed, Numplayed... */ + mysql_data_seek(result2, offset); row = mysql_fetch_row(result); if (!row) goto out; @@ -994,7 +1003,7 @@ static int get_pic_id_by_name(char *name) { char *q, *ebn; void *result = NULL; - long unsigned ret; + int ret; MYSQL_ROW row; if (!(ebn = escaped_basename(name))) @@ -1008,7 +1017,7 @@ static int get_pic_id_by_name(char *name) row = mysql_fetch_row(result); ret = -E_NOROW; if (row && row[0]) - ret = atol(row[0]); + ret = atoi(row[0]); mysql_free_result(result); return ret; } @@ -1367,7 +1376,7 @@ int com_ls(int fd, int argc, char *argv[]) char *q; void *result; int ret; - unsigned int num_rows; + my_ulonglong num_rows, top = 0, left = 0, right = 0; if (argc > 2) return -E_MYSQL_SYNTAX; @@ -1387,7 +1396,7 @@ int com_ls(int fd, int argc, char *argv[]) num_rows = mysql_num_rows(result); ret = 1; if (num_rows) - ret = print_results(fd, result, 0, 0, num_rows - 1, 0); + ret = print_results(fd, result, top, left, num_rows - 1, right); mysql_free_result(result); return ret; } @@ -1520,11 +1529,12 @@ static int com_ps_ns(__a_unused int fd, int argc, char *argv[]) char *query, *stream = get_current_stream(); void *result = get_result("select name from streams"); MYSQL_ROW row; - int match = -1, ret, i; - unsigned int num_rows; + int ret; + my_ulonglong num_rows, match, i; + ret = -E_MYSQL_SYNTAX; if (argc != 1) - return -E_MYSQL_SYNTAX; + goto out; ret = -E_NORESULT; if (!result) goto out; @@ -1539,14 +1549,13 @@ static int com_ps_ns(__a_unused int fd, int argc, char *argv[]) goto out; if (!strcmp(row[0], "current_stream")) continue; - if (!strcmp(row[0], stream)) { - match = i; + if (!strcmp(row[0], stream)) break; - } } ret = -E_NO_STREAM; - if (match < 0) + if (i == num_rows) goto out; + match = i; if (!strcmp(argv[0], "ps")) i = match > 0? match - 1 : num_rows - 1; else @@ -1558,8 +1567,7 @@ static int com_ps_ns(__a_unused int fd, int argc, char *argv[]) goto out; if (!strcmp(row[0], "current_stream")) { if (!strcmp(argv[0], "ps")) { - i = match - 2; - i = i < 0? i + num_rows : i; + i = match < 2? match + num_rows - 2 : match - 2; } else { i = match + 2; i = i > num_rows - 1? i - num_rows : i; @@ -1934,9 +1942,9 @@ static int com_vrfy_clean(int fd, int argc, __a_unused char *argv[]) char *query; int ret, vrfy_mode = strcmp(argv[0], "clean"); void *result = NULL; - unsigned int num_rows; MYSQL_ROW row; char *escaped_name; + my_ulonglong num_rows, top = 0, left = 0, right = 0; if (argc != 1) return -E_MYSQL_SYNTAX; @@ -1953,7 +1961,7 @@ static int com_vrfy_clean(int fd, int argc, __a_unused char *argv[]) if (vrfy_mode) { send_va_buffer(fd, "found %i invalid entr%s\n", num_rows, num_rows == 1? "y" : "ies"); - ret = print_results(fd, result, 0, 0, num_rows - 1, 0); + ret = print_results(fd, result, top, left, num_rows - 1, right); goto out; } while ((row = mysql_fetch_row(result))) { @@ -2141,14 +2149,17 @@ success: static int init_mysql_server(void) { char *u = conf.mysql_user_arg? conf.mysql_user_arg : para_logname(); + unsigned int port; mysql_ptr = mysql_init(NULL); if (!mysql_ptr) { PARA_CRIT_LOG("%s", "mysql init error\n"); return -E_NOTCONN; } - PARA_DEBUG_LOG("connecting: %s@%s:%d\n", u, conf.mysql_host_arg, - conf.mysql_port_arg); + if (conf.mysql_port_arg < 0) + return -E_MYSQL_SYNTAX; + port = conf.mysql_port_arg; + PARA_DEBUG_LOG("connecting: %s@%s:%d\n", u, conf.mysql_host_arg, port); if (!conf.mysql_user_arg) free(u); /* @@ -2160,7 +2171,7 @@ static int init_mysql_server(void) conf.mysql_user_arg, conf.mysql_passwd_arg, conf.mysql_database_arg, - conf.mysql_port_arg, NULL, 0))) { + port, NULL, 0))) { PARA_CRIT_LOG("%s", "connect error\n"); return -E_NOTCONN; } diff --git a/net.c b/net.c index 6a8eea3b..6248de55 100644 --- a/net.c +++ b/net.c @@ -120,8 +120,7 @@ void init_sockaddr(struct sockaddr_in *addr, int port, const struct hostent *he) */ static int sendall(int fd, const char *buf, size_t *len) { - int total = 0; /* how many bytes we've sent */ - int bytesleft = *len; /* how many we have left to send */ + size_t total = 0, bytesleft = *len; /* how many we have left to send */ int n = -1; while (total < *len) { @@ -222,9 +221,9 @@ __printf_2_3 int send_va_buffer(int fd, const char *fmt, ...) * * \sa recv(2) */ -__must_check int recv_bin_buffer(int fd, char *buf, ssize_t size) +__must_check int recv_bin_buffer(int fd, char *buf, size_t size) { - int n; + ssize_t n; crypt_function *cf = NULL; if (fd + 1 <= cda_size) @@ -233,8 +232,11 @@ __must_check int recv_bin_buffer(int fd, char *buf, ssize_t size) unsigned char *tmp = para_malloc(size); void *private = crypt_data_array[fd].private_data; n = recv(fd, tmp, size, 0); - if (n > 0) - (*cf)(n, tmp, (unsigned char *)buf, private); + if (n > 0) { + size_t numbytes = n; + unsigned char *b = (unsigned char *)buf; + (*cf)(numbytes, tmp, b, private); + } free(tmp); } else n = recv(fd, buf, size, 0); @@ -257,10 +259,12 @@ __must_check int recv_bin_buffer(int fd, char *buf, ssize_t size) * * \sa recv_bin_buffer() */ -int recv_buffer(int fd, char *buf, ssize_t size) +int recv_buffer(int fd, char *buf, size_t size) { int n; + if (!size) + return -E_RECV; n = recv_bin_buffer(fd, buf, size - 1); if (n >= 0) buf[n] = '\0'; @@ -397,7 +401,8 @@ int init_unix_addr(struct sockaddr_un *u, const char *name) * \sa bind(2) * \sa chmod(2) */ -int create_pf_socket(const char *name, struct sockaddr_un *unix_addr, int mode) +int create_pf_socket(const char *name, struct sockaddr_un *unix_addr, + mode_t mode) { int fd, ret; @@ -471,7 +476,7 @@ ssize_t send_cred_buffer(int sock, char *buf) return ret; } -static void dispose_fds(int *fds, int num) +static void dispose_fds(int *fds, unsigned num) { int i; diff --git a/net.h b/net.h index 5ff53987..1399a24d 100644 --- a/net.h +++ b/net.h @@ -40,10 +40,11 @@ int para_connect(int, struct sockaddr_in *); int send_buffer(int, const char *); int send_bin_buffer(int, const char *, size_t); int send_va_buffer(int, const char *, ...); -int recv_buffer(int, char *, ssize_t); -int recv_bin_buffer(int, char *, ssize_t); +int recv_buffer(int fd, char *buf, size_t size); +int recv_bin_buffer(int fd, char *buf, size_t size); int para_accept(int, void *addr, socklen_t size); -int create_pf_socket(const char *, struct sockaddr_un *, int mod); +int create_pf_socket(const char *name, struct sockaddr_un *unix_addr, + mode_t mode); int init_unix_addr(struct sockaddr_un *, const char *); int recv_cred_buffer(int, char *, size_t); ssize_t send_cred_buffer(int, char*); diff --git a/ogg_afh.c b/ogg_afh.c index 5adcc252..d5c47262 100644 --- a/ogg_afh.c +++ b/ogg_afh.c @@ -117,12 +117,14 @@ static int ogg_open_callbacks(void *datasource, OggVorbis_File *vf, ov_callbacks } -static int ogg_compute_header_len(char *map, off_t numbytes, +static int ogg_compute_header_len(char *map, size_t numbytes, struct audio_format_info *afi) { - int ret, len = PARA_MIN(numbytes, CHUNK_SIZE); - unsigned int serial; + int ret; + size_t len = PARA_MIN(numbytes, CHUNK_SIZE); + int serial; char *buf; + ogg_page page; ogg_packet packet; vorbis_comment vc; @@ -134,9 +136,9 @@ static int ogg_compute_header_len(char *map, off_t numbytes, ogg_sync_init(sync_in); vorbis_info_init(&vi); vorbis_comment_init(&vc); - buf = ogg_sync_buffer(sync_in, len); + buf = ogg_sync_buffer(sync_in, (long)len); memcpy(buf, map, len); - ogg_sync_wrote(sync_in, len); + ogg_sync_wrote(sync_in, (long)len); ret = -E_SYNC_PAGEOUT; if (ogg_sync_pageout(sync_in, &page) <= 0) goto err1; @@ -199,7 +201,7 @@ err1: * CHUNK_TIME begins. Always successful. */ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of, - struct audio_format_info *afi, double time_total) + struct audio_format_info *afi, long unsigned time_total) { int i, ret, num; ssize_t max_chunk_len, pos = 0, min = 0, old_pos; @@ -239,7 +241,7 @@ static long unsigned ogg_compute_chunk_table(OggVorbis_File *of, /* * Init oggvorbis file and write some tech data to given pointers. */ -static int ogg_get_file_info(char *map, off_t numbytes, +static int ogg_get_file_info(char *map, size_t numbytes, struct audio_format_info *afi) { int ret; diff --git a/oggdec.c b/oggdec.c index 82ac9b43..1cd1f028 100644 --- a/oggdec.c +++ b/oggdec.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,7 +64,7 @@ static size_t cb_read(void *buf, size_t size, size_t nmemb, void *datasource) if (*fn->fc->input_eof) return 0; errno = EAGAIN; - return -1; + return (size_t)-1; } ret = PARA_MIN(nmemb, have / size) * size; memcpy(buf, p, ret); @@ -161,19 +161,19 @@ static ssize_t ogg_convert(char *inbuffer, size_t len, struct filter_node *fn) return -E_OGGDEC_FAULT; fn->fc->channels = ov_info(pod->vf, 0)->channels; fn->fc->samplerate = ov_info(pod->vf, 0)->rate; - PARA_NOTICE_LOG("%d channels, %d Hz\n", fn->fc->channels, fn->fc->samplerate); + PARA_NOTICE_LOG("%d channels, %d Hz\n", fn->fc->channels, + fn->fc->samplerate); } -again: - ret = ov_read(pod->vf, fn->buf + fn->loaded, fn->bufsize - fn->loaded, - ENDIAN, BITS / 8, SIGN, NULL); - if (ret == OV_HOLE || !ret) { - return pod->converted; + while (!*fn->fc->input_eof && fn->loaded < fn->bufsize) { + int length = fn->bufsize - fn->loaded; + long read_ret = ov_read(pod->vf, fn->buf + fn->loaded, length, + ENDIAN, BITS / 8, SIGN, NULL); + if (read_ret == OV_HOLE || !read_ret) + return pod->converted; + if (read_ret < 0) + return -E_OGGDEC_BADLINK; + fn->loaded += read_ret; } - if (ret < 0) - return -E_OGGDEC_BADLINK; - fn->loaded += ret; - if (!*fn->fc->input_eof && fn->loaded < fn->bufsize) - goto again; return pod->converted; } diff --git a/ortp_recv.c b/ortp_recv.c index 287d7064..c9696729 100644 --- a/ortp_recv.c +++ b/ortp_recv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,17 +68,16 @@ uint32_t chunk_ts; static int msg_to_buf(mblk_t *mp, char *buffer, int len) { - int rlen = len; mblk_t *m, *mprev; - int mlen; + size_t mlen, rlen = len; m = mp->b_cont; mprev = mp; while (m != NULL) { - mlen = (int) (m->b_wptr - m->b_rptr); + mlen = m->b_wptr - m->b_rptr; if (mlen <= rlen) { mblk_t *consumed = m; - memcpy (buffer, m->b_rptr, mlen); + memcpy(buffer, m->b_rptr, mlen); /* go to next mblk_t */ mprev->b_cont = m->b_cont; m = m->b_cont; @@ -86,7 +85,7 @@ static int msg_to_buf(mblk_t *mp, char *buffer, int len) freeb (consumed); buffer += mlen; rlen -= mlen; - } else { /*if mlen>rlen */ + } else { memcpy (buffer, m->b_rptr, rlen); m->b_rptr += rlen; return len; @@ -133,6 +132,7 @@ static void ortp_recv_post_select(__a_unused struct sched *s, struct task *t) int packet_type, stream_type; char tmpbuf[CHUNK_SIZE + 3]; unsigned chunk_time; + size_t packet_size; // PARA_INFO_LOG("rn: %p, pord: %p, session: %p\n", rn, pord, pord->session); t->ret = -E_ORTP_RECV_EOF; @@ -169,6 +169,7 @@ static void ortp_recv_post_select(__a_unused struct sched *s, struct task *t) t->ret = -E_ORTP_RECV_EOF; goto err_out; } + packet_size = t->ret; packet_type = READ_PACKET_TYPE(tmpbuf); stream_type = READ_STREAM_TYPE(tmpbuf); chunk_time = READ_CHUNK_TIME(tmpbuf); @@ -183,48 +184,43 @@ static void ortp_recv_post_select(__a_unused struct sched *s, struct task *t) t->ret = -E_ORTP_RECV_EOF; goto err_out; case ORTP_BOF: - PARA_INFO_LOG("bof (%d)\n", t->ret); + PARA_INFO_LOG("bof (%zu)\n", packet_size); pord->have_header = 1; /* fall through */ case ORTP_DATA: if (!pord->have_header && stream_type) /* can't use the data, wait for header */ goto success; - if (t->ret + rn->loaded >= CHUNK_SIZE + ORTP_AUDIO_HEADER_LEN) { - t->ret = -E_OVERRUN; + t->ret = -E_OVERRUN; + if (packet_size + rn->loaded >= CHUNK_SIZE + ORTP_AUDIO_HEADER_LEN) goto err_out; - } - if (t->ret > ORTP_AUDIO_HEADER_LEN) { + if (packet_size > ORTP_AUDIO_HEADER_LEN) { memcpy(rn->buf + rn->loaded, tmpbuf + ORTP_AUDIO_HEADER_LEN, - t->ret - ORTP_AUDIO_HEADER_LEN); - rn->loaded += t->ret - ORTP_AUDIO_HEADER_LEN; + packet_size - ORTP_AUDIO_HEADER_LEN); + rn->loaded += packet_size - ORTP_AUDIO_HEADER_LEN; } goto success; case ORTP_HEADER: header_len = READ_HEADER_LEN(tmpbuf); - PARA_DEBUG_LOG("header packet (%d bytes), header len: %d\n", - t->ret, header_len); + PARA_DEBUG_LOG("header packet (%zu bytes), header len: %d\n", + packet_size, header_len); if (!pord->have_header) { pord->have_header = 1; memcpy(rn->buf, tmpbuf + ORTP_AUDIO_HEADER_LEN, - t->ret - ORTP_AUDIO_HEADER_LEN); - rn->loaded = t->ret - ORTP_AUDIO_HEADER_LEN; + packet_size - ORTP_AUDIO_HEADER_LEN); + rn->loaded = packet_size - ORTP_AUDIO_HEADER_LEN; goto success; } - if (header_len + ORTP_AUDIO_HEADER_LEN > t->ret) { - t->ret = -E_INVALID_HEADER; + t->ret = -E_INVALID_HEADER; + if (header_len + ORTP_AUDIO_HEADER_LEN > packet_size) goto err_out; - } - payload_len = t->ret - ORTP_AUDIO_HEADER_LEN - header_len; -// PARA_INFO_LOG("len: %d header_len: %d, payload_len: %d, loaded: %d\n", ret, -// header_len, payload_len, rn->loaded); - if (rn->loaded + payload_len > CHUNK_SIZE) { - t->ret = -E_OVERRUN; + payload_len = packet_size - ORTP_AUDIO_HEADER_LEN - header_len; + t->ret = -E_OVERRUN; + if (rn->loaded + payload_len > CHUNK_SIZE) goto err_out; - } if (payload_len) memcpy(rn->buf + rn->loaded, tmpbuf - + (t->ret - payload_len), payload_len); + + (packet_size - payload_len), payload_len); rn->loaded += payload_len; goto success; } @@ -261,7 +257,8 @@ static void *ortp_recv_parse_config(int argc, char **argv) { int ret; - struct ortp_recv_args_info *tmp = para_calloc(sizeof(struct ortp_recv_args_info)); + struct ortp_recv_args_info *tmp = + para_calloc(sizeof(struct ortp_recv_args_info)); ret = ortp_recv_cmdline_parser(argc, argv, tmp)? -E_ORTP_SYNTAX : 1; if (ret > 0) diff --git a/ortp_send.c b/ortp_send.c index b06a1b84..65c68418 100644 --- a/ortp_send.c +++ b/ortp_send.c @@ -19,6 +19,7 @@ /** \file ortp_send.c para_server's ortp sender */ #include +#include #include "server.cmdline.h" #include "server.h" @@ -39,9 +40,9 @@ struct ortp_target { /** whether the ortp sender is activated */ int status; /** the ortp timestamp increases by this amount */ - int chunk_ts; + uint32_t chunk_ts; /** the currently used timestamp for this target */ - int last_ts; + uint32_t last_ts; /** the position of this target in the list of targets */ struct list_head node; /** the UDP port */ @@ -67,19 +68,21 @@ static void ortp_delete_target(struct ortp_target *ot, const char *msg) free(ot); } -static void ortp_send_buf(char *buf, int len, long unsigned chunks_sent) +static void ortp_send_buf(char *buf, size_t len, long unsigned chunks_sent) { struct ortp_target *ot, *tmp; - int ret; + int ret, ortp_len = len; /* rtp_session_send_with_ts expects int */ + if (ortp_len < 0) + return; list_for_each_entry_safe(ot, tmp, &targets, node) { - int ts; + uint32_t ts; if (!ot->session) continue; WRITE_CHUNK_TS(buf, ot->chunk_ts); ts = ot->chunk_ts * chunks_sent; ret = rtp_session_send_with_ts(ot->session, - (unsigned char*)buf, len, ts); + (unsigned char*)buf, ortp_len, ts); ot->last_ts = ts; if (ret < 0) ortp_delete_target(ot, "send error"); @@ -168,7 +171,7 @@ static void ortp_send(long unsigned current_chunk, long unsigned chunks_sent, { struct ortp_target *ot, *tmp; size_t sendbuf_len; - int header_len = 0; + size_t header_len = 0; int packet_type = ORTP_DATA; char *sendbuf, *header_buf = NULL; struct timeval *chunk_tv; @@ -186,7 +189,7 @@ static void ortp_send(long unsigned current_chunk, long unsigned chunks_sent, } if (!ot->chunk_ts) ot->chunk_ts = rtp_session_time_to_ts(ot->session, - tv2ms(chunk_tv)); + (int)tv2ms(chunk_tv)); // PARA_DEBUG_LOG("len: %d, ts: %lu, ts: %d\n", // len, ot->chunk_ts * chunks_sent, ot->chunk_ts); ot->streaming = 1; diff --git a/para.h b/para.h index 5e839215..ed2c0bcc 100644 --- a/para.h +++ b/para.h @@ -186,9 +186,9 @@ enum { int stat_item_valid(const char *item); int stat_line_valid(const char *); -void stat_client_write(char *msg, int itemnum); +void stat_client_write(const char *msg, int itemnum); int stat_client_add(int fd, long unsigned mask); -unsigned for_each_line(char *, int, void (*)(char *)); +size_t for_each_line(char *buf, size_t n, void (*line_handler)(char *)); #define FOR_EACH_STAT_ITEM(i) for (i = 0; i < NUM_STAT_ITEMS; i++) __printf_2_3 void para_log(int, const char*, ...); @@ -196,7 +196,8 @@ __printf_2_3 void para_log(int, const char*, ...); /* taken from printf man page */ #define PARA_VSPRINTF(fmt, p) \ { \ - int n, size = 100; \ + int n; \ + size_t size = 100; \ p = para_malloc(size); \ while (1) { \ va_list ap; \ diff --git a/random_selector.c b/random_selector.c index d9efaaf2..a9863d52 100644 --- a/random_selector.c +++ b/random_selector.c @@ -133,10 +133,12 @@ static void random_shutdown(void) int random_selector_init(struct audio_file_selector *s) { struct timeval now; + unsigned int seed; PARA_INFO_LOG("%s", "registering random handlers ;)\n"); gettimeofday(&now, NULL); - srand(now.tv_usec); + seed = now.tv_usec; + srand(seed); s->cmd_list = random_selector_cmds; s->get_audio_file_list = random_get_audio_file_list; s->shutdown = random_shutdown; diff --git a/server.c b/server.c index 7e52fa5e..c25786e3 100644 --- a/server.c +++ b/server.c @@ -328,8 +328,9 @@ err: static void init_random_seed(void) { - int fd, ret = -1, len = sizeof(unsigned int); + int fd, ret = -1; unsigned int seed; + size_t len = sizeof(unsigned int); fd = open("/dev/urandom", O_RDONLY); if (fd < 0) diff --git a/server.h b/server.h index 3f01e05e..ae3a7dd8 100644 --- a/server.h +++ b/server.h @@ -76,7 +76,7 @@ struct misc_meta_data { /** information on the current audio file */ struct audio_format_info afi; /** the size of the current audio file in bytes */ - long unsigned int size; + size_t size; /** the full path of the current audio file */ char filename[_POSIX_PATH_MAX]; /** the last modification file of the current audio file */ diff --git a/stat.c b/stat.c index dc511192..e881ae09 100644 --- a/stat.c +++ b/stat.c @@ -143,15 +143,14 @@ int stat_client_add(int fd, long unsigned mask) * On write errors, remove the status client from the client list and close its * file descriptor. */ -void stat_client_write(char *msg, int itemnum) +void stat_client_write(const char *msg, int itemnum) { struct stat_client *sc, *tmp; - ssize_t len; + size_t len = strlen(msg); struct timeval tv = {0 , 0}; - if (!initialized) + if (!initialized || !len) return; - len = strlen(msg); list_for_each_entry_safe(sc, tmp, &client_list, node) { int fd = sc->fd, ret; fd_set wfds; @@ -244,18 +243,18 @@ int stat_line_valid(const char *line) * \return If line_handler is not NULL, this function returns the number * of bytes not handled to \a line_handler. */ -unsigned for_each_line(char *buf, int n, void (*line_handler)(char *)) +size_t for_each_line(char *buf, size_t n, void (*line_handler)(char *)) { char *start = buf, *end; - int i, num_lines = 0; + size_t num_lines = 0, bytes_left = n; // PARA_INFO_LOG("buf: %s", buf); - while (start < buf + n) { + while (bytes_left) { char *next_null; char *next_cr; - next_cr = memchr(start, '\n', buf + n - start); - next_null = memchr(start, '\0', buf + n - start); + next_cr = memchr(start, '\n', bytes_left); + next_null = memchr(start, '\0', bytes_left); if (!next_cr && !next_null) break; if (next_cr && next_null) { @@ -269,15 +268,14 @@ unsigned for_each_line(char *buf, int n, void (*line_handler)(char *)) *end = '\0'; // PARA_INFO_LOG("calling line handler: %s\n", start); line_handler(start); - start = ++end; - } else - start = ++end; + } + start = ++end; + bytes_left = buf + n - start; } if (!line_handler) return num_lines; - i = buf + n - start; - if (i && i != n) - memmove(buf, start, i); - return i; + if (bytes_left && bytes_left != n) + memmove(buf, start, bytes_left); + return bytes_left; } diff --git a/string.c b/string.c index 0a55ed20..9ad6bfb8 100644 --- a/string.c +++ b/string.c @@ -253,8 +253,11 @@ void chop(char *buf) __must_check __malloc char *para_tmpname(void) { struct timeval now; + unsigned int seed; + gettimeofday(&now, NULL); - srand(now.tv_usec); + seed = now.tv_usec; + srand(seed); return make_message("%08i", rand()); } diff --git a/vss.c b/vss.c index a3c2e650..e1e4ead5 100644 --- a/vss.c +++ b/vss.c @@ -158,6 +158,10 @@ void vss_init(void) { int i; char *hn = para_hostname(), *home = para_homedir(); + long unsigned announce_time = conf.announce_time_arg > 0? + conf.announce_time_arg : 300, + autoplay_delay = conf.autoplay_delay_arg > 0? + conf.autoplay_delay_arg : 0; PARA_DEBUG_LOG("supported audio formats: %s\n", SUPPORTED_AUDIO_FORMATS); @@ -166,7 +170,7 @@ void vss_init(void) afl[i].name); afl[i].init(&afl[i]); } - ms2tv(conf.announce_time_arg, &announce_tv); + ms2tv(announce_time, &announce_tv); PARA_INFO_LOG("announce timeval: %lums\n", tv2ms(&announce_tv)); for (i = 0; senders[i].name; i++) { PARA_NOTICE_LOG("initializing %s sender\n", senders[i].name); @@ -179,7 +183,7 @@ void vss_init(void) mmd->vss_status_flags |= VSS_PLAYING; mmd->new_vss_status_flags |= VSS_PLAYING; gettimeofday(&now, NULL); - ms2tv(conf.autoplay_delay_arg, &tmp); + ms2tv(autoplay_delay, &tmp); tv_add(&now, &tmp, &autoplay_barrier); } } @@ -275,7 +279,7 @@ static void vss_get_audio_file(void) } mmd->size = file_status.st_size; mmd->mtime = file_status.st_mtime; - map = para_mmap(file_status.st_size, PROT_READ, MAP_PRIVATE, + map = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE, audio_file, 0); strcpy(mmd->filename, sl[i]); mmd->afi.header_len = 0; /* default: no header */ @@ -408,7 +412,7 @@ static void vss_eof(void) * treamtment. * */ -char *vss_get_header(int *header_len) +char *vss_get_header(unsigned *header_len) { if (mmd->audio_format < 0 || !map || !mmd->afi.header_len) return NULL; @@ -516,7 +520,8 @@ void vss_send_chunk(void) { int i; struct audio_format_handler *af; - ssize_t pos, len; + ssize_t pos; + size_t len; struct timeval now, due; if (mmd->audio_format < 0 || !map || !vss_playing()) diff --git a/vss.h b/vss.h index 0234296f..ebc51a5e 100644 --- a/vss.h +++ b/vss.h @@ -25,7 +25,7 @@ unsigned int vss_playing(void); unsigned int vss_next(void); unsigned int vss_repos(void); unsigned int vss_paused(void); -char *vss_get_header(int *header_len); +char *vss_get_header(unsigned *header_len); struct timeval *vss_chunk_time(void); int guess_audio_format(const char *name); const char *supported_audio_formats(void); diff --git a/wav.c b/wav.c index 308c8bc1..891769a5 100644 --- a/wav.c +++ b/wav.c @@ -51,7 +51,8 @@ */ #define WRITE_U16(buf, x) (buf)[0] = (unsigned char)((x) & 0xff); -static void make_wav_header(int channels, int samplerate, struct filter_node *fn) +static void make_wav_header(unsigned int channels, unsigned int samplerate, + struct filter_node *fn) { char *headbuf = fn->buf;