Esempio n. 1
0
static ret_t
get_info (cherokee_plugin_loader_t  *loader,
	  const char                *module,
	  int                        flags,
	  cherokee_plugin_info_t   **info,
	  void                     **dl_handler)
{
	ret_t             ret;
	cherokee_buffer_t info_name = CHEROKEE_BUF_INIT;

	/* Build the info struct string
	 */
	cherokee_buffer_add_va (&info_name, "cherokee_%s_info", module);

	/* Open it
	 */
	ret = dylib_open (loader, module, flags, dl_handler);
	if (ret != ret_ok) {
		cherokee_buffer_mrproper (&info_name);
		return ret_error;
	}

	*info = get_sym_from_dlopen_handler (*dl_handler, info_name.buf);
	if (*info == NULL) {
		cherokee_buffer_mrproper (&info_name);
		return ret_not_found;
	}

	/* Free the info struct string
	 */
	cherokee_buffer_mrproper (&info_name);
	return ret_ok;
}
Esempio n. 2
0
ret_t
cherokee_url_mrproper (cherokee_url_t *url)
{
	cherokee_buffer_mrproper (&url->host);
	cherokee_buffer_mrproper (&url->request);
	return ret_ok;
}
Esempio n. 3
0
static ret_t
parse_if (cherokee_buffer_t *buf, const char *if_entry, size_t len_entry, cherokee_boolean_t show)
{
    char              *begin;
    char              *end;
    cherokee_buffer_t  token = CHEROKEE_BUF_INIT;

    cherokee_buffer_add_str (&token, "%if ");
    cherokee_buffer_add (&token, if_entry, len_entry);
    cherokee_buffer_add_str (&token, "%");

    begin = strstr (buf->buf, token.buf);
    if (begin == NULL)
        goto error;

    end = strstr (begin, "%fi%");
    if (end == NULL)
        goto error;

    if (show) {
        cherokee_buffer_remove_chunk (buf, end - buf->buf, 4);
        cherokee_buffer_remove_chunk (buf, begin - buf->buf, token.len);
    } else {
        cherokee_buffer_remove_chunk (buf, begin - buf->buf, (end+4) - begin);
    }

    cherokee_buffer_mrproper (&token);
    return ret_ok;
error:
    cherokee_buffer_mrproper (&token);
    return ret_error;
}
Esempio n. 4
0
ret_t
cherokee_validator_parse_basic (cherokee_validator_t *validator, char *str, cuint_t str_len)
{
	char              *colon;
	cherokee_buffer_t  auth = CHEROKEE_BUF_INIT;

	/* Decode base64
	 */
	cherokee_buffer_add (&auth, str, str_len);
	cherokee_buffer_decode_base64 (&auth);

	/* Look for the user:passwd structure
	 */
	colon = strchr (auth.buf, ':');
	if (colon == NULL)
		goto error;

	/* Copy user and password
	 */
	cherokee_buffer_add (&validator->user, auth.buf, colon - auth.buf);
	cherokee_buffer_add (&validator->passwd, colon+1, auth.len  - ((colon+1) - auth.buf));

	TRACE (ENTRIES, "Parse basic auth got user=%s, passwd=%s\n", validator->user.buf, validator->passwd.buf);

	/* Clean up and exit
	 */
	cherokee_buffer_mrproper (&auth);
	return ret_ok;

error:
	cherokee_buffer_mrproper (&auth);
	return ret_error;
}
Esempio n. 5
0
ret_t
cherokee_handler_ssi_free (cherokee_handler_ssi_t *hdl)
{
	cherokee_buffer_mrproper (&hdl->dir);
	cherokee_buffer_mrproper (&hdl->source);
	cherokee_buffer_mrproper (&hdl->render);
	return ret_ok;
}
Esempio n. 6
0
ret_t
cherokee_plugin_loader_mrproper (cherokee_plugin_loader_t *loader)
{
	cherokee_buffer_mrproper (&loader->module_dir);
	cherokee_buffer_mrproper (&loader->deps_dir);

	cherokee_avl_mrproper (&loader->table, free_entry);
	return ret_ok;
}
Esempio n. 7
0
ret_t
cherokee_validator_digest_response (cherokee_validator_t  *validator,
				    char                  *A1,
				    cherokee_buffer_t     *buf,
				    cherokee_connection_t *conn)
{
	ret_t              ret;
	cherokee_buffer_t a2 = CHEROKEE_BUF_INIT;

	/* A1 has to be in string of length 32:
	 * MD5_digest(user":"******":"passwd)
	 */

	/* Sanity checks
	 */
	if (A1 == NULL)
		return ret_deny;

	if (cherokee_buffer_is_empty (&validator->nonce))
		return ret_deny;

	/* Build A2
	 */
	ret = digest_HA2 (validator, &a2, conn);
	if (ret != ret_ok)
		goto error;

	/* Build the final string
	 */
	cherokee_buffer_ensure_size (buf, 32 + a2.len + validator->nonce.len + 4);

	cherokee_buffer_add (buf, A1, 32);
	cherokee_buffer_add_str (buf, ":");
	cherokee_buffer_add_buffer (buf, &validator->nonce);
	cherokee_buffer_add_str (buf, ":");

	if (!cherokee_buffer_is_empty (&validator->qop)) {
		if (!cherokee_buffer_is_empty (&validator->nc))
			cherokee_buffer_add_buffer (buf, &validator->nc);
		cherokee_buffer_add_str (buf, ":");
		if (!cherokee_buffer_is_empty (&validator->cnonce))
			cherokee_buffer_add_buffer (buf, &validator->cnonce);
		cherokee_buffer_add_str (buf, ":");
		cherokee_buffer_add_buffer (buf, &validator->qop);
		cherokee_buffer_add_str (buf, ":");
	}

	cherokee_buffer_add_buffer (buf, &a2);
	cherokee_buffer_encode_md5_digest (buf);
	cherokee_buffer_mrproper (&a2);

	return ret_ok;

error:
	cherokee_buffer_mrproper (&a2);
	return ret;
}
Esempio n. 8
0
ret_t
cherokee_logger_ncsa_free (cherokee_logger_ncsa_t *logger)
{
	cherokee_buffer_mrproper (&logger->now_dtm);
	cherokee_buffer_mrproper (&logger->referer);
	cherokee_buffer_mrproper (&logger->useragent);

	return ret_ok;
}
Esempio n. 9
0
ret_t
cherokee_request_header_mrproper (cherokee_request_header_t *request)
{
	cherokee_buffer_mrproper (&request->user);
	cherokee_buffer_mrproper (&request->password);
	cherokee_buffer_mrproper (&request->extra_headers);

	cherokee_url_mrproper (&request->url);
	return ret_ok;
}
ret_t
cherokee_handler_proxy_conn_free (cherokee_handler_proxy_conn_t *pconn)
{
	cherokee_socket_close    (&pconn->socket);
	cherokee_socket_mrproper (&pconn->socket);

	cherokee_buffer_mrproper (&pconn->post.buf_temp);
	cherokee_buffer_mrproper (&pconn->header_in_raw);

	return ret_ok;
}
Esempio n. 11
0
ret_t
cherokee_post_mrproper (cherokee_post_t *post)
{
	cherokee_buffer_mrproper (&post->send.buffer);
	cherokee_buffer_mrproper (&post->chunked.buffer);
	cherokee_buffer_mrproper (&post->read_header_100cont);
	cherokee_buffer_mrproper (&post->header_surplus);
	cherokee_buffer_mrproper (&post->progress_id);

	return ret_ok;
}
Esempio n. 12
0
static ret_t
props_free  (cherokee_handler_tmi_props_t *props)
{
    zmq_close (props->socket);
    zmq_term (props->context);
    cherokee_buffer_mrproper (&props->reply);
    cherokee_buffer_mrproper (&props->subscriberid);
    cherokee_buffer_mrproper (&props->version);
    cherokee_buffer_mrproper (&props->dossiername);
    cherokee_buffer_mrproper (&props->endpoint);
    return ret_ok;
}
static ret_t
props_free  (cherokee_handler_dbslayer_props_t *props)
{
	if (props->balancer)
		cherokee_balancer_free (props->balancer);

	cherokee_buffer_mrproper (&props->user);
	cherokee_buffer_mrproper (&props->password);
	cherokee_buffer_mrproper (&props->db);

	return ret_ok;
}
Esempio n. 14
0
ret_t
cherokee_source_mrproper (cherokee_source_t *src)
{
	if (src->free) {
		src->free (src);
	}

	cherokee_buffer_mrproper (&src->original);
	cherokee_buffer_mrproper (&src->unix_socket);
	cherokee_buffer_mrproper (&src->host);

	return ret_ok;
}
Esempio n. 15
0
ret_t
cherokee_header_op_free (cherokee_header_op_t *op)
{
	if (unlikely (op == NULL)) {
		return ret_ok;
	}

	cherokee_buffer_mrproper (&op->header);
	cherokee_buffer_mrproper (&op->value);

	free (op);
	return ret_ok;
}
Esempio n. 16
0
static void
entry_free (void *entry)
{
	cherokee_resolv_cache_entry_t *e = entry;

	if (e->addr) {
		freeaddrinfo (e->addr);
	}

	cherokee_buffer_mrproper (&e->ip_str);
	cherokee_buffer_mrproper (&e->ip_str_all);
	free(entry);
}
Esempio n. 17
0
ret_t
cherokee_handler_dirlist_props_free  (cherokee_handler_dirlist_props_t *props)
{
    cherokee_list_content_free (&props->notice_files, (cherokee_list_free_func)file_match_free);
    cherokee_list_content_free (&props->hidden_files, (cherokee_list_free_func)file_match_free);

    cherokee_buffer_mrproper (&props->header);
    cherokee_buffer_mrproper (&props->footer);
    cherokee_buffer_mrproper (&props->entry);
    cherokee_buffer_mrproper (&props->css);
    cherokee_buffer_mrproper (&props->icon_web_dir);

    return cherokee_handler_props_free_base (HANDLER_PROPS(props));
}
Esempio n. 18
0
ret_t
cherokee_validator_file_props_free_base (cherokee_validator_file_props_t *props)
{
	cherokee_buffer_mrproper (&props->password_file);

	return cherokee_validator_props_free_base (VALIDATOR_PROPS(props));
}
Esempio n. 19
0
static ret_t
find_empty_port (int starting, int *port)
{
	ret_t             ret;
	cherokee_socket_t s;
	int               p     = starting;
	cherokee_buffer_t bind_ = CHEROKEE_BUF_INIT;

	cherokee_buffer_add_str (&bind_, "127.0.0.1");

	cherokee_socket_init (&s);
	cherokee_socket_set_client (&s, AF_INET);

	while (true) {
		ret = cherokee_socket_bind (&s, p, &bind_);
		if (ret == ret_ok)
			break;

		p += 1;
		if (p > 0XFFFF)
			return ret_error;
	}

	cherokee_socket_close (&s);

	cherokee_socket_mrproper (&s);
	cherokee_buffer_mrproper (&bind_);

	*port = p;
	return ret_ok;
}
Esempio n. 20
0
static ret_t
do_download__read_body (cherokee_downloader_t *downloader, void *param)
{
    ret_t             ret;
    ssize_t           len;
    cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;

    UNUSED(param);

    /* Write down
     */
    len = write (output_fd, downloader->body.buf, downloader->body.len);
    if (len > 0) {
        ret = cherokee_buffer_move_to_begin (&downloader->body, len);
        if (ret != ret_ok) return ret;
    }

    /* Print info
     */
    cherokee_buffer_add_fsize (&tmp, downloader->content_length);
    cherokee_buffer_add_str   (&tmp, " of ");
    cherokee_buffer_add_fsize (&tmp, downloader->info.body_recv);

    if (! quiet) {
        fprintf (stderr, "\rDownloading: %s", tmp.buf);
        fflush(stderr);
    }

    cherokee_buffer_mrproper (&tmp);
    return ret_ok;
}
Esempio n. 21
0
static ret_t
do_download__has_headers (cherokee_downloader_t *downloader, void *param)
{
    cherokee_url_t    *url;
    cherokee_buffer_t *req;
    cherokee_header_t *hdr;

    UNUSED(param);

    url = &downloader->request.url;
    req = &url->request;
    hdr = downloader->header;

    TRACE(ENTRIES, "quiet=%d http_code=%d\n", quiet, hdr->response);

    /* Check the response
     */
    if (quiet == false) {
        cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;

        cherokee_http_code_copy (HDR_RESPONSE(hdr), &tmp);
        print_tuple_str ("Response", tmp.buf);
        cherokee_buffer_mrproper (&tmp);
    }

    /* Open a new file if needed
     */
    if (global_fd == UNSET_FD) {
        char *name;

        name = strrchr (req->buf, '/');
        if (name == NULL) {
            name = "index.html";
        }

        output_fd = open (name, O_WRONLY, O_CREAT);
        if (output_fd < 0) {
            return ret_error;
        }

    } else {
        output_fd = global_fd;
    }

    /* Save the headers?
     */
    if (save_headers == true) {
        ssize_t  written;
        uint32_t len;

        cherokee_header_get_length (hdr, &len);
        written = write (output_fd, hdr->input_buffer->buf, len);
        if (written < 0) {
            PRINT_MSG_S ("ERROR: Can not write to output file\n");
            return ret_error;
        }
    }

    return ret_ok;
}
Esempio n. 22
0
ret_t
cherokee_logger_writer_free (cherokee_logger_writer_t *writer)
{
	logger_writer_close_file (writer);

	cherokee_buffer_mrproper (&writer->buffer);
	cherokee_buffer_mrproper (&writer->filename);
	cherokee_buffer_mrproper (&writer->command);

	CHEROKEE_MUTEX_DESTROY (&PRIV(writer)->mutex);

	free (writer->priv);
	free (writer);

	return ret_ok;
}
static ret_t
validate_basic (cherokee_validator_htdigest_t *htdigest, cherokee_connection_t *conn, cherokee_buffer_t *file)
{
	ret_t               ret;
	cherokee_boolean_t  equal;
	char               *user   = NULL;
	char               *realm  = NULL;
	char               *passwd = NULL;
	cherokee_buffer_t   ha1 = CHEROKEE_BUF_INIT;

	UNUSED(htdigest);

	/* Extact the right entry information
	 */
	ret = extract_user_entry (file, conn->validator->user.buf, &user, &realm, &passwd);
	if (ret != ret_ok)
		return ret;

	/* Build the hash
	 */
	build_HA1 (conn, &ha1);

	/* Compare it with the stored hash, clean, and return
	 */
	equal = (strncmp(ha1.buf, passwd, ha1.len) == 0);
	cherokee_buffer_mrproper (&ha1);

	return (equal) ? ret_ok : ret_not_found;
}
Esempio n. 24
0
ret_t
cherokee_logger_writer_new (cherokee_logger_writer_t **writer)
{
	CHEROKEE_NEW_STRUCT(n,logger_writer);

	INIT_LIST_HEAD (&n->listed);

	n->type        = cherokee_logger_writer_syslog;
	n->fd          = -1;
	n->max_bufsize = DEFAULT_LOGGER_MAX_BUFSIZE;

	cherokee_buffer_init (&n->command);
	cherokee_buffer_init (&n->filename);
	cherokee_buffer_init (&n->buffer);

	cherokee_buffer_ensure_size (&n->buffer, n->max_bufsize);

	n->priv = malloc (sizeof(priv_t));
	if (n->priv == NULL) {
		cherokee_buffer_mrproper (&n->buffer);
		free(n);
		return ret_nomem;
	}

	CHEROKEE_MUTEX_INIT (&PRIV(n)->mutex, NULL);
	n->initialized = false;

	*writer = n;
	return ret_ok;
}