Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions cget/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ do_download__has_headers (cherokee_downloader_t *downloader, void *param)
/* Check the response
*/
if (quiet == false) {
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;
cherokee_buffer_init (&tmp);

cherokee_http_code_copy (HDR_RESPONSE(hdr), &tmp);
print_tuple_str ("Response", tmp.buf);
Expand Down Expand Up @@ -226,7 +227,7 @@ do_download__read_body (cherokee_downloader_t *downloader, void *param)
{
ret_t ret;
ssize_t len;
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

UNUSED(param);

Expand All @@ -240,6 +241,7 @@ do_download__read_body (cherokee_downloader_t *downloader, void *param)

/* Print info
*/
cherokee_buffer_init (&tmp);
cherokee_buffer_add_fsize (&tmp, downloader->content_length);
cherokee_buffer_add_str (&tmp, " of ");
cherokee_buffer_add_fsize (&tmp, downloader->info.body_recv);
Expand Down Expand Up @@ -348,7 +350,7 @@ main (int argc, char **argv)
cint_t param_num;
cint_t long_index;
cherokee_downloader_t *downloader;
cherokee_buffer_t proxy = CHEROKEE_BUF_INIT;
cherokee_buffer_t proxy;
cuint_t proxy_port;

struct option long_options[] = {
Expand Down Expand Up @@ -419,49 +421,70 @@ main (int argc, char **argv)
return EXIT_OK;
}

/* Initialise the buffers
*/
cherokee_buffer_init (&proxy);

/* Tracing and proxy discovering..
*/
cherokee_init();
cget_find_proxy (&proxy, &proxy_port);

for (val=optind; val<optind+param_num; val++) {
cherokee_buffer_t url = CHEROKEE_BUF_INIT;
cherokee_buffer_t url;

/* Initialise the buffers
*/
cherokee_buffer_init (&url);

/* Build the url buffer
*/
ret = cherokee_buffer_add_va (&url, "%s", argv[val]);
if (ret != ret_ok)
exit (EXIT_ERROR);
if (ret != ret_ok) {
re = EXIT_ERROR;
goto out;
}

/* Create the downloader object..
*/
ret = cherokee_downloader_new (&downloader);
if (ret != ret_ok)
exit (EXIT_ERROR);
if (ret != ret_ok) {
re = EXIT_ERROR;
goto out;
}

ret = cherokee_downloader_init(downloader);
if (ret != ret_ok)
exit (EXIT_ERROR);
if (ret != ret_ok) {
re = EXIT_ERROR;
goto out;
}

if (! cherokee_buffer_is_empty (&proxy)) {
ret = cherokee_downloader_set_proxy (downloader, &proxy, proxy_port);
if (ret != ret_ok)
exit (EXIT_ERROR);
if (ret != ret_ok) {
re = EXIT_ERROR;
goto out;
}
}

ret = cherokee_downloader_set_url (downloader, &url);
if (ret != ret_ok)
exit (EXIT_ERROR);
if (ret != ret_ok) {
re = EXIT_ERROR;
goto out;
}

ret = cherokee_downloader_connect (downloader);
if (ret != ret_ok)
exit (EXIT_ERROR);
if (ret != ret_ok) {
re = EXIT_ERROR;
goto out;
}

/* Download it!
*/
ret = do_download (downloader);
if ((ret != ret_ok) && (ret != ret_eof)) {
exit (EXIT_ERROR);
re = EXIT_ERROR;
goto out;
}

/* Free the objects..
Expand All @@ -473,9 +496,14 @@ main (int argc, char **argv)
/* Close the output file
*/
re = close (output_fd);
if (re != 0)
exit (EXIT_ERROR);
if (re != 0) {
re = EXIT_ERROR;
goto out;
}

out:
re = EXIT_OK;
cherokee_buffer_mrproper (&proxy);
cherokee_mrproper();
return EXIT_OK;
return re;
}
7 changes: 4 additions & 3 deletions cherokee/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ cherokee_access_add_domain (cherokee_access_t *entry, char *domain)
char ip[46]; // Max IPv6 length is 45
cherokee_resolv_cache_t *resolv;
const struct addrinfo *addr_info, *addr;
cherokee_buffer_t domain_buf = CHEROKEE_BUF_INIT;
cherokee_buffer_t domain_buf;

cherokee_buffer_fake (&domain_buf, domain, strlen(domain));

Expand Down Expand Up @@ -361,20 +361,21 @@ cherokee_access_add_subnet (cherokee_access_t *entry, char *subnet)
char *slash;
char *mask;
subnet_item_t *n;
cherokee_buffer_t ip = CHEROKEE_BUF_INIT;
cherokee_buffer_t ip;

/* Split the string
*/
slash = strpbrk (subnet, "/\\");
if (slash == NULL) return ret_error;

mask = slash +1;
cherokee_buffer_init (&ip);
cherokee_buffer_add (&ip, subnet, mask-subnet-1);

/* Create the new list object
*/
n = new_subnet();
if (n == NULL) return ret_error;
if (n == NULL) goto error;

cherokee_list_add (LIST(n), &entry->list_subnets);

Expand Down
6 changes: 3 additions & 3 deletions cherokee/admin_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ cherokee_admin_server_reply_close_conn (cherokee_handler_t *hdl,
ret_t ret;
char *begin;
cherokee_server_t *server = HANDLER_SRV(hdl);
cherokee_buffer_t match = CHEROKEE_BUF_INIT;
cherokee_buffer_t match;

cherokee_buffer_fake_str (&match, "del server.connection ");

Expand Down Expand Up @@ -265,7 +265,7 @@ cherokee_admin_server_reply_set_trace (cherokee_handler_t *hdl,
cherokee_buffer_t *question)
{
ret_t ret;
cherokee_buffer_t match = CHEROKEE_BUF_INIT;
cherokee_buffer_t match;

UNUSED (hdl);

Expand Down Expand Up @@ -421,7 +421,7 @@ cherokee_admin_server_reply_kill_source (cherokee_handler_t *hdl,
char id[10];
cherokee_source_t *source = NULL;
cherokee_server_t *srv = HANDLER_SRV(hdl);
cherokee_buffer_t match = CHEROKEE_BUF_INIT;
cherokee_buffer_t match;

cherokee_buffer_fake_str (&match, "kill server.source ");

Expand Down
10 changes: 7 additions & 3 deletions cherokee/balancer_failover.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ reactivate_entry (cherokee_balancer_failover_t *balancer,
/* balancer->mutex is LOCKED
*/
ret_t ret;
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

/* Reactivate
*/
ret = reactivate_entry_guts (balancer, entry);

/* Notify
*/
cherokee_buffer_init (&tmp);
cherokee_source_copy_name (entry->source, &tmp);
LOG_WARNING (CHEROKEE_ERROR_BALANCER_FAILOVER_REACTIVE, tmp.buf);
cherokee_buffer_mrproper (&tmp);
Expand Down Expand Up @@ -124,10 +125,12 @@ report_fail (cherokee_balancer_failover_t *balancer,
ret_t ret;
cherokee_list_t *i;
cherokee_balancer_entry_t *entry;
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

UNUSED(conn);

cherokee_buffer_init (&tmp);

CHEROKEE_MUTEX_LOCK (&balancer->mutex);

list_for_each (i, &BAL(balancer)->entries) {
Expand All @@ -152,9 +155,9 @@ report_fail (cherokee_balancer_failover_t *balancer,
*/
cherokee_source_copy_name (entry->source, &tmp);
LOG_WARNING (CHEROKEE_ERROR_BALANCER_FAILOVER_DISABLE, tmp.buf);
cherokee_buffer_mrproper (&tmp);

CHEROKEE_MUTEX_UNLOCK (&balancer->mutex);
cherokee_buffer_mrproper (&tmp);
return ret_ok;
}

Expand All @@ -163,6 +166,7 @@ report_fail (cherokee_balancer_failover_t *balancer,

out:
CHEROKEE_MUTEX_UNLOCK (&balancer->mutex);
cherokee_buffer_mrproper (&tmp);
return ret;
}

Expand Down
10 changes: 7 additions & 3 deletions cherokee/balancer_ip_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ reactivate_entry (cherokee_balancer_ip_hash_t *balancer,
{
/* balancer->mutex is LOCKED
*/
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

/* Disable
*/
Expand All @@ -94,6 +94,7 @@ reactivate_entry (cherokee_balancer_ip_hash_t *balancer,

/* Notify
*/
cherokee_buffer_init (&tmp);
cherokee_source_copy_name (entry->source, &tmp);
LOG_WARNING (CHEROKEE_ERROR_BALANCER_IP_REACTIVE, tmp.buf, balancer->n_active);
cherokee_buffer_mrproper (&tmp);
Expand All @@ -110,10 +111,12 @@ report_fail (cherokee_balancer_ip_hash_t *balancer,
ret_t ret;
cherokee_list_t *i;
cherokee_balancer_entry_t *entry;
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

UNUSED(conn);

cherokee_buffer_init (&tmp);

CHEROKEE_MUTEX_LOCK (&balancer->mutex);

list_for_each (i, &BAL(balancer)->entries) {
Expand All @@ -140,9 +143,9 @@ report_fail (cherokee_balancer_ip_hash_t *balancer,
*/
cherokee_source_copy_name (entry->source, &tmp);
LOG_WARNING (CHEROKEE_ERROR_BALANCER_IP_DISABLE, tmp.buf, balancer->n_active);
cherokee_buffer_mrproper (&tmp);

CHEROKEE_MUTEX_UNLOCK (&balancer->mutex);
cherokee_buffer_mrproper (&tmp);
return ret_ok;
}

Expand All @@ -151,6 +154,7 @@ report_fail (cherokee_balancer_ip_hash_t *balancer,

out:
CHEROKEE_MUTEX_UNLOCK (&balancer->mutex);
cherokee_buffer_mrproper (&tmp);
return ret;
}

Expand Down
11 changes: 8 additions & 3 deletions cherokee/balancer_round_robin.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ reactivate_entry (cherokee_balancer_entry_t *entry)
{
/* balancer->mutex is LOCKED
*/
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

/* Disable
*/
Expand All @@ -78,6 +78,7 @@ reactivate_entry (cherokee_balancer_entry_t *entry)

/* Notify
*/
cherokee_buffer_init (&tmp);
cherokee_source_copy_name (entry->source, &tmp);
LOG_WARNING (CHEROKEE_ERROR_BALANCER_ONLINE_SOURCE, tmp.buf);
cherokee_buffer_mrproper (&tmp);
Expand Down Expand Up @@ -141,9 +142,12 @@ report_fail (cherokee_balancer_round_robin_t *balancer,
ret_t ret;
cherokee_list_t *i;
cherokee_balancer_entry_t *entry;
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t tmp;

UNUSED(conn);

cherokee_buffer_init (&tmp);

CHEROKEE_MUTEX_LOCK (&balancer->mutex);

list_for_each (i, &BAL(balancer)->entries) {
Expand All @@ -168,9 +172,9 @@ report_fail (cherokee_balancer_round_robin_t *balancer,
*/
cherokee_source_copy_name (entry->source, &tmp);
LOG_WARNING (CHEROKEE_ERROR_BALANCER_OFFLINE_SOURCE, tmp.buf);
cherokee_buffer_mrproper (&tmp);

CHEROKEE_MUTEX_UNLOCK (&balancer->mutex);
cherokee_buffer_mrproper (&tmp);
return ret_ok;
}

Expand All @@ -179,6 +183,7 @@ report_fail (cherokee_balancer_round_robin_t *balancer,

out:
CHEROKEE_MUTEX_UNLOCK (&balancer->mutex);
cherokee_buffer_mrproper (&tmp);
return ret;
}

Expand Down
10 changes: 7 additions & 3 deletions cherokee/bogotime.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ init_timezone (void)
ret_t
cherokee_bogotime_init (void)
{
ret_t ret;

if (inited) {
return ret_ok;
}

/* Initialise the buffers */
cherokee_buffer_init (&cherokee_bogonow_strgmt);
ret = cherokee_buffer_ensure_size (&cherokee_bogonow_strgmt, DTM_SIZE_GMTTM_STR+2);
if (unlikely (ret != ret_ok)) return ret;

/* RW-lock mutex */
CHEROKEE_RWLOCK_INIT (&lock, NULL);

Expand All @@ -101,9 +108,6 @@ cherokee_bogotime_init (void)

INIT_LIST_HEAD (&_callbacks);

cherokee_buffer_init (&cherokee_bogonow_strgmt);
cherokee_buffer_ensure_size (&cherokee_bogonow_strgmt, DTM_SIZE_GMTTM_STR+2);

/* Init time zone */
init_timezone();

Expand Down
Loading