#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;
}
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;
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;
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;
/** 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];
/**
*
* \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);
};
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++) {
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;
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
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);
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;
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)
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;
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",
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
*
*/
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;
long unsigned challenge_nr, chall_response;
char **argv = NULL;
char *p, *command = NULL;
+ size_t numbytes;
signal(SIGCHLD, SIG_IGN);
signal(SIGINT, SIG_DFL);
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) {
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);
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);
* \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;
}
* \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);
* \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;
}
#include <openssl/pem.h>
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);
__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;
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);
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;
/** 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;
};
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 */
{
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;
}
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;
* 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;
* 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;
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';
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;
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;
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);
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;
/*
* 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;
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);
* 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;
{
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)
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;
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;
}
{
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;
}
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;
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;
}
void *result = NULL;
char *q;
int num, ret;
+ my_ulonglong top = 0, left = 0, right = 0;
if (argc < 2)
num = 10;
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;
}
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");
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)
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)
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;
{
char *q, *ebn;
void *result = NULL;
- long unsigned ret;
+ int ret;
MYSQL_ROW row;
if (!(ebn = escaped_basename(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;
}
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;
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;
}
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;
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
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;
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;
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))) {
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);
/*
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;
}
*/
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) {
*
* \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)
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);
*
* \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';
* \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;
return ret;
}
-static void dispose_fds(int *fds, int num)
+static void dispose_fds(int *fds, unsigned num)
{
int i;
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*);
}
-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;
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;
* 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;
/*
* 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;
/*
- * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
*
* 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
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);
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;
}
/*
- * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
*
* 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
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;
freeb (consumed);
buffer += mlen;
rlen -= mlen;
- } else { /*if mlen>rlen */
+ } else {
memcpy (buffer, m->b_rptr, rlen);
m->b_rptr += rlen;
return len;
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;
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);
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;
}
{
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)
/** \file ortp_send.c para_server's ortp sender */
#include <ortp/ortp.h>
+#include <ortp/port.h>
#include "server.cmdline.h"
#include "server.h"
/** 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 */
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");
{
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;
}
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;
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*, ...);
/* 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; \
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;
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)
/** 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 */
* 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;
* \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) {
*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;
}
__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());
}
{
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);
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);
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);
}
}
}
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 */
* 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;
{
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())
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);
*/
#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;