Ejemplo n.º 1
0
axl_bool mod_ticket_ensure_alternative_user (ValvuladCtx * ctx, ValvuladRes result, const char * user_or_domain)
{
    /* get result and row */
    ValvuladRow      row;
    const char     * str_value;
    char          ** items;
    int              iterator;

    /* check result received */
    if (result == NULL) {
        /* msg ("No alternative user found for %s", user_or_domain); */
        return axl_false;
    }

    /* trim value */
    axl_stream_trim ((char *) user_or_domain);

    /* get row */
    row = GET_ROW (result);
    while (row) {
        /* get cell */
        str_value = GET_CELL(row, 0);
        if (str_value) {
            /* split */
            items = axl_split (str_value, 1, ",");
            iterator = 0;
            while (items && items[iterator]) {

                /* trim value */
                axl_stream_trim (items[iterator]);
                /*msg ("Alternative checking %s with %s", user_or_domain, items[iterator]);*/

                if (axl_cmp (items[iterator], user_or_domain)) {
                    /* release results */
                    valvulad_db_release_result (result);

                    /* found match, perfect! */
                    axl_freev (items);
                    return axl_true;
                }

                /* next position */
                iterator++;
            } /* end while */

            /* free this items */
            axl_freev (items);
        } /* end if */

        /* next row */
        row = GET_ROW (result);
    } /* end while */

    /* release results */
    valvulad_db_release_result (result);

    /* msg ("No alternative user found for %s (2)", user_or_domain); */
    return axl_false;

}
enum jal_status jaln_process_journal_resume(VortexFrame *frame, char **nonce_out, uint64_t *offset_out)
{
	enum jal_status ret = JAL_E_INVAL;
	char *nonce = NULL;

	if (!frame || !nonce_out || *nonce_out || !offset_out) {
		goto err_out;
	}

	if (!jaln_check_content_type_and_txfr_encoding_are_valid(frame)) {
		goto err_out;
	}

	const char *msg = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_MESSAGE);
	if (!msg) {
		return JAL_E_INVAL;
	}
	if (0 != strcasecmp(msg, JALN_MSG_JOURNAL_RESUME)) {
		goto err_out;
	}

	const char *nonce_from_frame = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_ID);
	if (!nonce_from_frame) {
		goto err_out;
	}
	nonce = jal_strdup(nonce_from_frame);
	axl_stream_trim(nonce);
	if (0 == strlen(nonce)) {
		goto err_out;
	}

	const char *offset_str = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_JOURNAL_OFFSET);
	if (!offset_str) {
		goto err_out;
	}
	if (!jaln_ascii_to_uint64(offset_str, offset_out)) {
		goto err_out;
	}

	ret = JAL_OK;
	*nonce_out = nonce;

	goto out;

err_out:
	free(nonce);
out:
	return ret;
}
Ejemplo n.º 3
0
/** 
 * @internal
 * @brief Compiles the provided file.
 * 
 */
axl_bool      xml_rpc_gen_compile_selected (const char  * selected)
{
	axlError * error;
	axlDoc   * doc = NULL;

	char    * out_dir;
	char    * comp_name;
	char    * aux_file;
	int       length;

	/* load the xml document */
	if (! exarg_is_defined ("idl-format"))
		doc = axl_doc_parse_from_file (selected, &error);

	/* check result */
	if (doc == NULL) {
		/* check if the input format was expected to be xml
		   (XDL) */
		if (exarg_is_defined ("xdl-format")) {
			fprintf (stderr, "error: unable to parse file '%s', expected XDL format. Error was:\n%s",
				    selected, axl_error_get (error));
			axl_error_free (error);
			/* stop from parsing */
			return axl_false;
		}
	    
		/* try to load the document as an IDL definition using
		 * the structured format */
		doc = xml_rpc_gen_translate_idl_to_xdl (selected, &error);

		if (exarg_is_defined ("to-xml")) {
			/* get file */
			length = strlen (selected);
			if ((selected[length - 1] == 'l') && 
			    (selected[length - 2] == 'd') && 
			    (selected[length - 3] == 'i')) {
				/* create an aux file replacing ending
				 * idl by xml */
				aux_file = axl_strdup (selected);

				/* translate */
				aux_file [length - 2] = 'm';
				aux_file [length - 3] = 'x';
			}else {
				/* create an aux file replacing
				 * appending the .xml value */
				aux_file = axl_strdup_printf ("%s.xml", selected);
			}

			xml_rpc_report ("translating %s into %s", selected, aux_file);
			if (! axl_doc_dump_pretty_to_file (doc, aux_file, 4)) {
				fprintf (stderr, "error: unable to dump document, error was: %s\n", 
					 axl_error_get (error));
				axl_error_free (error);
			}else {
				xml_rpc_report ("translation ok");
			}

			/* free the aux file */
			axl_free (aux_file);

			/* free the document */
			axl_doc_free (doc);
			
			return axl_true;
		}

		/* seems that the document provided is either not XDL
		 * and IDL. */
		if (doc == NULL) {
			/* report the error */
			fprintf (stderr, "error: unable to parse file '%s', error was:\n%s",
				    selected, axl_error_get (error));
			axl_error_free (error);
			
			/* return that the document wasn't compiled */
			return axl_false;
		}
	}else {
		xml_rpc_report ("detected XDL format definition..");
	}

	xml_rpc_report ("document is well-formed: %s..", selected);

	/* validate file received */
	if (! axl_dtd_validate (doc, dtd, &error)) {
		/* report the error */
		fprintf (stderr, "error: validation failed for '%s', error was:\n%s",
			    selected, axl_error_get (error));
		axl_error_free (error);

		/* return that the document wasn't compiled */
		return axl_false;
	}

	xml_rpc_report ("document is valid: %s..", selected);

	/* get out dir */
	if (exarg_is_defined ("out-dir")) 
		out_dir = exarg_get_string ("out-dir");
	else
		out_dir = "out";

	/* get the name node */
	comp_name = (char*) axl_doc_get_content_at (doc, "/xml-rpc-interface/name", NULL);
	

	/* trim the name */
	axl_stream_trim (comp_name);
	
	xml_rpc_report ("component name: '%s'..", comp_name);

	/* now produce the stub required */
	if (! exarg_is_defined ("only-server")) {
		xml_rpc_c_stub_create (doc, out_dir, comp_name);

		/* write autoconf files for the server component */
		if (! exarg_is_defined ("disable-autoconf"))
			xml_rpc_autoconf_c_stub_create (doc, out_dir, comp_name);
	} else 
		xml_rpc_report ("client stub have been disabled..");
	
	/* now produce the server required */
	if (! exarg_is_defined ("only-client")) {
		xml_rpc_c_server_create (doc, out_dir, comp_name);
		
		/* write autoconf files for the client component */
		if (! exarg_is_defined ("disable-autoconf")) 
			xml_rpc_autoconf_c_server_create (doc, out_dir, comp_name);
	} else
		xml_rpc_report ("server stub have been disabled..");

	/* document parsed */
	axl_doc_free (doc);
	
	xml_rpc_report ("compilation ok");
	
	return axl_true;
}
Ejemplo n.º 4
0
enum jal_status jaln_process_init(VortexFrame *frame, struct jaln_init_info **info_out)
{
	if (!frame || !info_out || *info_out) {
		return JAL_E_INVAL;
	}
	enum jal_status ret = JAL_E_INVAL;

	struct jaln_init_info *info = jaln_init_info_create();

	if (!jaln_check_content_type_and_txfr_encoding_are_valid(frame)) {
		goto err_out;
	}

	const char *msg = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_MESSAGE);
	if (!msg) {
		goto err_out;
	}

	if (0 != strcasecmp(msg, JALN_MSG_INIT)) {
		goto err_out;
	}

	const char *role = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_MODE);
	if (!role) {
		goto err_out;
	}
	if (0 == strcasecmp(role, JALN_MSG_SUBSCRIBE_LIVE)) {
		info->role = JALN_ROLE_SUBSCRIBER;
		info->mode = JALN_LIVE_MODE;
	} else if (0 ==strcasecmp(role, JALN_MSG_SUBSCRIBE_ARCHIVE)) {
		info->role = JALN_ROLE_SUBSCRIBER;
		info->mode = JALN_ARCHIVE_MODE;
	} else if (0 == strcasecmp(role, JALN_MSG_PUBLISH_LIVE)) {
		info->role = JALN_ROLE_PUBLISHER;
		info->mode = JALN_LIVE_MODE;
	} else if (0 == strcasecmp(role, JALN_MSG_PUBLISH_ARCHIVE)) {
		info->role = JALN_ROLE_PUBLISHER;
		info->mode = JALN_ARCHIVE_MODE;
	} else {
		goto err_out;
	}
	const char *type = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_DATA_CLASS);
	if (!type) {
		goto err_out;
	}
	if (0 == strcasecmp(type, JALN_STR_JOURNAL)) {
		info->type = JALN_RTYPE_JOURNAL;
	} else if (0 == strcasecmp(type, JALN_STR_AUDIT)) {
		info->type = JALN_RTYPE_AUDIT;
	} else if (0 == strcasecmp(type, JALN_STR_LOG)) {
		info->type = JALN_RTYPE_LOG;
	} else {
		goto err_out;
	}
	const char *agent = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_AGENT);
	if (agent) {
		info->peer_agent = jal_strdup(agent);
	}
	char *cpy = NULL;
	const char *accept_dgst = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_ACCEPT_DIGEST);
	if (accept_dgst) {
		cpy = jal_strdup(accept_dgst);
		char *cookie = NULL;
		char *token = NULL;
		for (token = strtok_r(cpy, ",", &cookie);
				token != NULL;
				token = strtok_r(NULL, ",", &cookie)) {
			axl_stream_trim(token);
			if (0 == strlen(token)) {
				goto err_out;
			}
			axl_list_append(info->digest_algs, jal_strdup(token));
		}
		free(cpy);
		cpy = NULL;
	} else {
		axl_list_append(info->digest_algs, jal_strdup(JALN_DGST_SHA256));
	}
	const char *accept_enc = VORTEX_FRAME_GET_MIME_HEADER(frame, JALN_HDRS_ACCEPT_ENCODING);
	if (accept_enc) {
		cpy = jal_strdup(accept_enc);
		char *cookie = NULL;
		char *token = NULL;
		for (token = strtok_r(cpy, ",", &cookie);
				token != NULL;
				token = strtok_r(NULL, ",", &cookie)) {
			axl_stream_trim(token);
			if (0 == strlen(token)) {
				goto err_out;
			}
			axl_list_append(info->encodings, jal_strdup(token));
		}
		free(cpy);
		cpy = NULL;
	} else {
		axl_list_append(info->encodings, jal_strdup(JALN_ENC_XML));
	}
	ret = JAL_OK;
	*info_out = info;
	goto out;
err_out:
	jaln_init_info_destroy(&info);
out:
	return ret;
}