Exemplo n.º 1
0
static void topic_index_init()
{
    remote_registry_t *remote_registry = NULL;
    const axutil_env_t *env = NULL;
    remote_registry_resource_t *res = NULL;
    axis2_char_t *id = NULL;
	
    axis2_char_t *reg_url = "http://localhost:9762/registry";

    env = axutil_env_create_all("test.log", AXIS2_LOG_LEVEL_TRACE);
    remote_registry = remote_registry_create(env, reg_url, "admin", "admin");

    res = remote_registry_get(remote_registry, env, TOPIC_INDEX, NULL);
    if(!res)
    {
        printf("came\n");
        res = remote_registry_resource_create(env);
        id = axutil_strcat(env, reg_url, TOPIC_INDEX, NULL);
        remote_registry_resource_set_id(res, env, id);
        remote_registry_resource_set_title(res, env, TOPIC_INDEX);
        remote_registry_resource_set_parent_path(res, env, "");
        remote_registry_resource_set_properties(res, env, axutil_hash_make(env));
        remote_registry_resource_set_author_name(res, env, "admin");
        remote_registry_resource_set_description(res, env, "");
        remote_registry_resource_set_last_modified_time(res, env, axutil_date_time_create(env));
        remote_registry_put(remote_registry, env, TOPIC_INDEX, res);
        return;
    }
}
Exemplo n.º 2
0
rampart_saml_token_t * AXIS2_CALL
create_saml_token(const axutil_env_t *env)
{
    oxs_sign_ctx_t *sign_ctx = NULL;
	oxs_x509_cert_t *cert = NULL;
	openssl_pkey_t *prv_key = NULL;
	rampart_saml_token_t *saml = NULL;

	axutil_date_time_t *time = NULL;
	saml_assertion_t *assertion = NULL;
	axiom_node_t *node = NULL;
    axis2_char_t *prv_key_file = NULL;
    axis2_char_t *certificate_file = NULL;
    /* 
     * Create a rampart_saml_token_t to give to the Rampart/C 
     * Here the token type is protection token.
     */    
	saml = rampart_saml_token_create(env, NULL, RAMPART_ST_CONFIR_TYPE_HOLDER_OF_KEY);
	time = axutil_date_time_create(env);
	assertion = saml_assertion_create(env);
	if (assertion)	
	{
		saml_assertion_set_minor_version(assertion, env, 1);		
		saml_assertion_set_issue_instant(assertion, env, time);
		saml_assertion_set_issuer(assertion, env, "http://ws.apache.org/rampart/c");	
		saml_assertion_add_condition(assertion, env, create_condition(env));
		saml_assertion_set_not_before(assertion, env, axutil_date_time_create(env));
		saml_assertion_add_statement(assertion, env, create_auth_statement(env, saml));
	}
    /* Load the private key from file*/
    prv_key_file = axutil_stracat(env, axis2c_home, PRIVATE_KEY_FILE);  
    certificate_file = axutil_stracat(env, axis2c_home, CERTIFICATE_FILE);
    prv_key = oxs_key_mgr_load_private_key_from_pem_file(env, prv_key_file, PRIVATE_KEY_PASSWORD);
    cert = oxs_key_mgr_load_x509_cert_from_pem_file(env, certificate_file);

	sign_ctx = oxs_sign_ctx_create(env);
	saml_util_set_sig_ctx_defaults(sign_ctx, env, "AssertionID");
	oxs_sign_ctx_set_private_key(sign_ctx, env, prv_key);
    oxs_sign_ctx_set_certificate(sign_ctx, env, cert);
    saml_assertion_set_signature(assertion, env, sign_ctx);

	node = saml_assertion_to_om(assertion, NULL, env);	 
	rampart_saml_token_set_assertion(saml, env, node);
    rampart_saml_token_set_token_type(saml, env, RAMPART_ST_TYPE_PROTECTION_TOKEN);
	saml_assertion_free(assertion, env);
	return saml;
}
Exemplo n.º 3
0
int
main(
    int argc,
    char **argv)
{
    axutil_env_t *env = NULL;
    axis2_char_t *client_home = NULL;

    axis2_char_t *endpoint_uri = NULL;

    axis2_stub_t *stub = NULL;

    /* variables use databinding */
    adb_echoDate_t *echo_in = NULL;
    adb_echoDateResponse_t *echo_out = NULL;

    axutil_date_time_t *echo_date = NULL;
    axutil_date_time_t *return_echo_date = NULL;

    axis2_char_t *send_date_str = NULL;
    axis2_char_t *return_date_str = NULL;

    endpoint_uri = "http://localhost:9090/axis2/services/interop_doc1";

    env = axutil_env_create_all("codegen_utest_blocking.log",
                                AXIS2_LOG_LEVEL_TRACE);

    /* Set up deploy folder. */
    client_home = AXIS2_GETENV("AXIS2C_HOME");
    if (!client_home)
        client_home = "../../../deploy";

    stub = axis2_stub_create_InteropTestPortTypeDocService(env,
                                                           client_home,
                                                           endpoint_uri);

    /* create the struct */
    echo_date = axutil_date_time_create(env);   /* default to current date */
    send_date_str = axutil_date_time_serialize_date_time(echo_date, env);
    printf("sending date %s\n", send_date_str);

    /* create the input params using databinding */
    echo_in = adb_echoDate_create(env);
    adb_echoDate_set_arg_0_10(echo_in, env, echo_date);

    /* invoke the web service method */
    echo_out = axis2_stub_op_InteropTestPortTypeDocService_echoDate(stub, env, echo_in);

    /* return the output params using databinding */
    return_echo_date = adb_echoDateResponse_get_echoDateReturn(echo_out, env);

    return_date_str =
        axutil_date_time_serialize_date_time(return_echo_date, env);
    printf("returned date %s\n", return_date_str);

    return 0;
}
Exemplo n.º 4
0
axiom_node_t *
create_saml_token(axutil_env_t *env)
{
	axutil_date_time_t *time = NULL;
	saml_assertion_t *assertion = NULL;
	axiom_node_t *node = NULL;
	time = axutil_date_time_create(env);
	assertion = saml_assertion_create(env);
	if (assertion)	
	{
		saml_assertion_set_minor_version(assertion, env, 1);		
		saml_assertion_set_issue_instant(assertion, env, time);
		saml_assertion_set_issuer(assertion, env, "http://ws.apache.org/rampart/c");	
		saml_assertion_add_condition(assertion, env, create_condition(env));
		saml_assertion_set_not_before(assertion, env, axutil_date_time_create(env));
		saml_assertion_add_statement(assertion, env, create_auth_statement(env));
	}	
	node = saml_assertion_to_om(assertion, NULL, env);	 
	saml_assertion_free(assertion, env);
	return node;
}
Exemplo n.º 5
0
AXIS2_EXTERN unsigned int AXIS2_CALL
axutil_rand_get_seed_value_based_on_time(
    const axutil_env_t * env)
{
    axutil_date_time_t *date = axutil_date_time_create(env);
    unsigned int rand_var = axutil_date_time_get_year(date, env);
    rand_var += axutil_date_time_get_month(date, env);
    rand_var += axutil_date_time_get_date(date, env);
    rand_var += axutil_date_time_get_hour(date, env);
    rand_var += axutil_date_time_get_minute(date, env);
    rand_var += axutil_date_time_get_second(date, env);
    axutil_date_time_free(date, env);
    return rand_var;
}
Exemplo n.º 6
0
saml_stmt_t *
create_auth_statement(axutil_env_t *env)
{
	saml_auth_stmt_t *a_stmt = NULL;	
	saml_stmt_t *stmt = saml_stmt_create(env);
	a_stmt = saml_auth_stmt_create(env);
	saml_stmt_set_stmt(stmt, env, a_stmt, SAML_STMT_AUTHENTICATIONSTATEMENT);

	saml_auth_stmt_set_auth_method(a_stmt, env, SAML_AUTH_METHOD_URI_PASSWORD);
	saml_auth_stmt_set_auth_instant(a_stmt, env, axutil_date_time_create(env));
	
	saml_auth_stmt_set_subject(a_stmt, env, create_subject(env));	
	saml_auth_stmt_set_subject_dns(a_stmt, env,  "192.148.5.8");
	saml_auth_stmt_set_subject_ip(a_stmt, env,  "128.5.6.4");
	saml_auth_stmt_add_auth_binding(a_stmt, env, create_autherity_binding(env));
	return stmt;	
}
Exemplo n.º 7
0
axiom_node_t * AXIS2_CALL
create_saml_assertion(const axutil_env_t *env)
{
    saml_assertion_t *assertion = NULL;
    saml_attr_stmt_t *attr_stmt = NULL;
    saml_subject_t *subject = NULL;
    saml_named_id_t *named_id = NULL;
    saml_attr_t *attr = NULL;
    axiom_node_t *attr_val = NULL;
    axiom_element_t *e = NULL;
    saml_stmt_t *stmt = NULL;

    assertion = saml_assertion_create(env);
    attr_stmt = saml_attr_stmt_create(env);
    subject = saml_subject_create(env);

    saml_assertion_set_issue_instant(assertion, env, axutil_date_time_create(env));
    saml_assertion_set_issuer(assertion, env, "www.mrt.ac.lk");
    saml_assertion_set_minor_version(assertion, env, 1);

    saml_subject_add_confirmation(subject, env, SAML_SUB_CONFIRMATION_SENDER_VOUCHES);

    named_id = saml_named_id_create(env);
    saml_named_id_set_name(named_id, env, "cse07");
    saml_subject_set_named_id(subject, env, named_id);

    attr = saml_attr_create(env);
    saml_attr_set_name(attr, env, "csestudent");
    saml_attr_set_namespace(attr, env, "www.mrt.ac.lk/cse");
    e = axiom_element_create(env, NULL, "noofstudent", NULL, &attr_val);
    axiom_element_set_text(e, env, "10", attr_val);
    saml_attr_add_value(attr, env, attr_val); 
   
    saml_attr_stmt_set_subject(attr_stmt, env, subject);
    saml_attr_stmt_add_attribute(attr_stmt, env, attr);

    stmt = saml_stmt_create(env);
    saml_stmt_set_stmt(stmt, env, attr_stmt, SAML_STMT_ATTRIBUTESTATEMENT);

    saml_assertion_add_statement(assertion, env, stmt);
    return saml_assertion_to_om(assertion, NULL, env);
}
Exemplo n.º 8
0
int add_subscriber()
{
    remote_registry_t *remote_registry = NULL;
    const axutil_env_t *env = NULL;
    axis2_char_t *subscription_id = NULL;
    axis2_char_t *id = NULL;
    axis2_char_t *path = NULL; 
    axis2_char_t *index_path = NULL; 
    remote_registry_resource_t *res = NULL;
    axutil_hash_t *properties = NULL;
    int res_len = 0;
	
    char *content = strdup("<subscription><syn:endpoint xmlns:syn=\"http://ws.apache.org/ns/synapse\"><syn:address "\
                     "uri=\"http://localhost:9000/services/SimpleStockQuoteService\" /></syn:endpoint></subscription>");

    axis2_char_t *epr_type = "application/vnd.epr";
    axis2_char_t *filter = "/weather/4/";
    axis2_char_t *reg_url = "http://localhost:9762/registry";

    env = axutil_env_create_all("test.log", AXIS2_LOG_LEVEL_TRACE);
    subscription_id = axutil_strcat(env, "urn:uuid:", axutil_uuid_gen(env), NULL);
    path = axutil_strcat(env, filter, SUBSCRIPTION_COLLECTION_NAME, "/", subscription_id, NULL);
    id = axutil_strcat(env, reg_url, filter, SUBSCRIPTION_COLLECTION_NAME, "/", subscription_id, NULL);
    remote_registry = remote_registry_create(env, reg_url, "admin", "admin");

    topic_index_init();
    res = remote_registry_resource_create(env);
    remote_registry_resource_set_content(res, env, content);
    remote_registry_resource_set_content_len(res, env, axutil_strlen(content));
    remote_registry_resource_set_id(res, env, id);
    remote_registry_resource_set_media_type(res, env, epr_type);
    remote_registry_resource_set_title(res, env, path);
    remote_registry_resource_set_author_name(res, env, "admin");
    remote_registry_resource_set_description(res, env, "");
	remote_registry_resource_set_last_modified_time(res, env, axutil_date_time_create(env));

    properties = axutil_hash_make(env);
    if(properties)
    {
        axutil_hash_set(properties, axutil_strdup(env, "expires"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "*"));
        axutil_hash_set(properties, axutil_strdup(env, "staticFlag"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "false"));
        axutil_hash_set(properties, axutil_strdup(env, "filterValue"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, filter));
        axutil_hash_set(properties, axutil_strdup(env, "subManagerURI"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "http://10.100.1.44:8280/services/SampleEventSource"));
        axutil_hash_set(properties, axutil_strdup(env, "filterDialect"), AXIS2_HASH_KEY_STRING, axutil_strdup(env, "http://synapse.apache.org/eventing/dialect/topicFilter"));
        remote_registry_resource_set_properties(res, env, properties);
    }

    remote_registry_put(remote_registry, env, path, res);
    if(id)
    {
        AXIS2_FREE(env->allocator, id);
    }
    if(path)
    {
        AXIS2_FREE(env->allocator, path);
        path = NULL;
    }
    if(res)
    {
        remote_registry_resource_free(res, env);
        res = NULL;
    }

    res = remote_registry_get(remote_registry, env, TOPIC_INDEX, NULL);
    if(!res)
    {
        return 0;
    }
    id = axutil_strcat(env, reg_url, TOPIC_INDEX, NULL);
    remote_registry_resource_set_id(res, env, id);
    remote_registry_resource_set_title(res, env, TOPIC_INDEX);
    properties = remote_registry_resource_get_properties(res, env);
    if(properties)
    {
        path = axutil_strcat(env, filter, SUBSCRIPTION_COLLECTION_NAME, NULL);
        axutil_hash_set(properties, subscription_id, AXIS2_HASH_KEY_STRING, path);
        remote_registry_resource_set_properties(res, env, properties);
    }

    remote_registry_resource_set_content(res, env, NULL);
    remote_registry_resource_set_content_len(res, env, 0);
    remote_registry_resource_set_parent_path(res, env, "/eventing/index");
    index_path = axutil_strcat(env, TOPIC_INDEX, "/TopicIndex", NULL);
    remote_registry_put(remote_registry, env, index_path, res);

    if(id)
    {
        AXIS2_FREE(env->allocator, id);
    }
    if(res)
    {
        remote_registry_resource_free(res, env);
        res = NULL;
    }
    printf("\n");

    return 0;
}
Exemplo n.º 9
0
AXIS2_EXTERN axutil_date_time_t *AXIS2_CALL
axutil_date_time_local_to_utc(
    axutil_date_time_t *date_time,
    const axutil_env_t *env)
{
    int year;
    int mon;
    int day;
    int hour;
    int min;
    float sec;
    int tz_hour;
    int tz_min;
    axis2_bool_t tz_pos = AXIS2_FALSE;

    axutil_date_time_t *ret = NULL;

    year = date_time->year;
    mon = date_time->mon;
    day = date_time->day;
    hour = date_time->hour;
    min = date_time->min;
    sec = date_time->sec;
    tz_pos = date_time->tz_pos;
    tz_hour = date_time->tz_hour;
    tz_min = date_time->tz_min;

    if(tz_pos)
    {
        tz_hour *= -1;
        tz_min *= -1;
    }
    hour += tz_hour;
    min += tz_min;

    if(min > 59)
    {
        hour += min / 60;
        min %= 60;
    }
    while(min < 0)
    {
        hour--;
        min += 60;
    }

    if(hour > 23)
    {
        day += hour / 24;
        hour %= 24;
    }
    while(hour < 0)
    {
        day--;
        hour += 24;
    }

    mon--;
    while(mon < 0)
    {
        mon += 12;
        year--;
    }
    while(mon > 11)
    {
        mon -= 12;
        year++;
    }
    mon++;

    day--;
    while(day > 27)
    {
        if(mon == 2)
        {
            if(year % 4 != 0 || year % 400 == 0)
            {
                day -= 28;
                mon++;
            }
            else if(day > 28)
            {
                day -= 29;
                mon++;
            }
            else
                break;
        }
        else if(day > 29)
        {
            if (mon == 4 || mon == 6 || mon == 9 || mon == 11)
                day -= 30;
            else if (day > 30)
                day -= 31;
            else
                break;

            mon++;
        }
        else
            break;

        if(mon > 12)
        {
            mon = 1;
            year++;
        }
    }

    while(day < 0)
    {
        if (mon == 3)
        {
            day += 28;
            if (year % 4 == 0 || year % 400 != 0)
                day++;
        }

        if (mon == 5 || mon == 7 || mon == 10 || mon == 12)
            day += 30;
        else
            day += 31;

        mon--;
        if(mon < 1)
        {
            mon = 12;
            year--;
        }
    }
    day++;

    if (mon < 1 || mon > 12)
        return NULL;

    if (day < 1 || day > 31)
        return NULL;

    if (day == 31 && (mon == 2 || mon == 4 || mon == 6 || mon == 9 || mon == 11))
        return NULL;

    if (day == 30 && mon == 2)
        return NULL;

    if (day == 29 && mon == 2)
    {
        if(year % 4 != 0 || year % 400 == 0)
            return NULL;
    }

    if (hour < 0 || hour > 23)
        return NULL;

    if (min < 0 || min > 59)
        return NULL;

    if (sec < 0 || sec >= 60)
        return NULL;

    ret = axutil_date_time_create(env);
    ret->year = year - 1900;
    ret->mon = mon - 1;
    ret->day = day;
    ret->hour = hour;
    ret->min = min;
    ret->sec = sec;
    return ret;
}
Exemplo n.º 10
0
AXIS2_EXTERN axiom_node_t *AXIS2_CALL
remote_registry_resource_serialize(
    remote_registry_resource_t *resource,
    const axutil_env_t *env)
{
    axiom_node_t *entry_node = NULL;
    axiom_element_t *entry_element = NULL;
    axiom_namespace_t *ns1 = NULL;
    axiom_namespace_t *ns2 = NULL;
    axis2_char_t *description = NULL;
    axis2_char_t *author = NULL;
    axutil_hash_t *properties = NULL;
    axis2_char_t *content = NULL;
    int collection = 0;
    int content_modified= 0;
	axis2_char_t *id = NULL;
	axis2_char_t *title = NULL;
	
    axis2_char_t *media_type = NULL;
    axis2_char_t *parent_path = NULL;
	axutil_date_time_t *modified_date = NULL;

    ns1 = axiom_namespace_create(env, REMOTE_REGISTRY_ATOM_NS, REMOTE_REGISTRY_ATOM_NS_PREFIX);
    ns2 = axiom_namespace_create(env, REMOTE_REGISTRY_REGISTRY_NS, REMOTE_REGISTRY_REGISTRY_NS_PREFIX);

	if(resource->is_collection)
	{
		entry_element = axiom_element_create(env, NULL, REMOTE_REGISTRY_FEED_KEY_FEED, ns1, &entry_node);
	}
	else
	{
		entry_element = axiom_element_create(env, NULL, REMOTE_REGISTRY_FEED_KEY_ENTRY, ns1, &entry_node);
	}

	axiom_element_declare_namespace(entry_element, env, entry_node, ns1);
	axiom_element_declare_namespace(entry_element, env, entry_node, ns2);

    /* getting variables from the structure and rendering into an XML */
	id = remote_registry_resource_get_id(resource, env);
	if(id)
	{
		axiom_node_t *id_node = NULL;
		axiom_element_t *id_element = NULL;

		id_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_ID, ns1, &id_node);
		axiom_element_set_text(id_element, env, id, id_node);
	}


    title = remote_registry_resource_get_title(resource, env);
    if(title)
    {
        axiom_node_t *title_node = NULL;
        axiom_element_t *title_element = NULL;
        axiom_attribute_t *type_attr = NULL;

        title_element = axiom_element_create(env, entry_node,
						REMOTE_REGISTRY_FEED_KEY_TITLE, ns1, &title_node);
        axiom_element_set_text(title_element, env, title, title_node);

        type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE,
						REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT, NULL); 
        axiom_element_add_attribute(title_element, env, type_attr, title_node);
    }

    description = remote_registry_resource_get_description(resource, env);
    if(description)
    {
        axiom_node_t *summary_node = NULL;
        axiom_element_t *summary_element = NULL;
        axiom_attribute_t *type_attr = NULL;

        summary_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_SUMMARY, ns1, &summary_node);
        axiom_element_set_text(summary_element, env, description, summary_node);

        type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE,
					REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT, NULL); 
        axiom_element_add_attribute(summary_element, env, type_attr, summary_node);
    }

    author = remote_registry_resource_get_author_name(resource, env);
    if(author)
    {
        axiom_node_t *author_node = NULL;
        axiom_node_t *name_node = NULL;
        axiom_element_t *name_ele = NULL;

        axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_AUTHOR, ns1, &author_node);
        name_ele = axiom_element_create(env, author_node, REMOTE_REGISTRY_FEED_KEY_NAME, ns1, &name_node);

        axiom_element_set_text(name_ele, env, author, name_node);
    }

	modified_date = remote_registry_resource_get_last_modified_time(resource, env);
	if(!modified_date) {
		modified_date = axutil_date_time_create(env);
		remote_registry_resource_set_last_modified_time(resource, env, modified_date);
	}
	if(modified_date) 
	{
        axiom_node_t *date_node = NULL;
        axiom_element_t *date_ele = NULL;
		axis2_char_t *modified_date_str = NULL;

		modified_date_str = axutil_date_time_serialize_date_time(modified_date, env);
        date_ele = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_UPDATED, ns1, &date_node);
        axiom_element_set_text(date_ele, env, modified_date_str, date_node);

		AXIS2_FREE(env->allocator, modified_date_str);
	}
	

    content = remote_registry_resource_get_content(resource, env);
    if(content)
    {
        axiom_node_t *content_node = NULL;
        axiom_element_t *content_element = NULL;
        axiom_attribute_t *type_attr = NULL;
		axis2_char_t *base64_content = NULL;

		int base64_len = 0;
		int content_len = -1;

		content_len = remote_registry_resource_get_content_len(resource, env);
		if(content_len == -1) /* which mean we have to derive the content length */
		{
			content_len = axutil_strlen(content);
		}

		base64_len = axutil_base64_encode_len(content_len);
		base64_content = AXIS2_MALLOC(env->allocator, base64_len+ 1);

		if(base64_content) 
		{
			axutil_base64_encode(base64_content, content, content_len);
			base64_content[base64_len] = '\0';


			content_element = axiom_element_create(env, entry_node, 
							REMOTE_REGISTRY_FEED_KEY_CONTENT, ns1, &content_node);
			axiom_element_set_text(content_element, env, base64_content, content_node);


			type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, 
							REMOTE_REGISTRY_FEED_ATTR_TYPE_BASE64_VALUE, NULL); 
			axiom_element_add_attribute(content_element, env, type_attr, content_node);
			
			AXIS2_FREE(env->allocator, base64_content);
		}
    }
    else if(!resource->is_collection)
    {
        axiom_node_t *content_node = NULL;
        axiom_element_t *content_element = NULL;
        axiom_attribute_t *type_attr = NULL;

        content_element = axiom_element_create(env, entry_node, 
						REMOTE_REGISTRY_FEED_KEY_CONTENT, ns1, &content_node);
        axiom_element_set_text(content_element, env, 
						REMOTE_REGISTRY_FEED_VALUE_EMPTY_CONTENT, content_node);


        type_attr = axiom_attribute_create(env, REMOTE_REGISTRY_FEED_ATTR_TYPE, 
						REMOTE_REGISTRY_FEED_ATTR_TYPE_TEXT_VALUE, NULL); 
        axiom_element_add_attribute(content_element, env, type_attr, content_node);
    }

    properties = remote_registry_resource_get_properties(resource, env);
    if(properties)
    {
        axiom_node_t *properties_node = NULL;
        axiom_node_t *property_node = NULL;
        axiom_node_t *name_node = NULL;
        axiom_node_t *value_node = NULL;
        axiom_element_t *name_element = NULL;
        axiom_element_t *value_element = NULL;
        axutil_hash_index_t *hi;
        void *val;
        void *key;
        int sum = 0;

        axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_PROPERTIES, ns2, &properties_node);
        
        for (hi = axutil_hash_first(resource->properties, env); hi; hi = axutil_hash_next(env, hi)) {
            axutil_hash_this(hi, (const void**)&key, NULL, &val);
            
            axiom_element_create(env, properties_node, REMOTE_REGISTRY_FEED_KEY_PROPERTY, ns2, &property_node);

            name_element = axiom_element_create(env, property_node, 
								REMOTE_REGISTRY_FEED_KEY_PROPERTY_KEY_NAME, ns2, &name_node);
            axiom_element_set_text(name_element, env, (axis2_char_t*)key, name_node);
            value_element = axiom_element_create(env, property_node, 
								REMOTE_REGISTRY_FEED_KEY_PROPERTY_KEY_VALUE, ns2, &value_node);
            axiom_element_set_text(value_element, env, (axis2_char_t*)val, value_node);
        }
    }
	
	media_type = remote_registry_resource_get_media_type(resource, env);
	if(media_type) 
	{
		axiom_element_t *media_element = NULL;
		axiom_node_t *media_node = NULL;
		media_element = axiom_element_create(env, entry_node, 
								REMOTE_REGISTRY_FEED_KEY_MEDIA_TYPE, ns2, &media_node);
		axiom_element_set_text(media_element, env, media_type, media_node);

	}

    parent_path = remote_registry_resource_get_parent_path(resource, env);
	if(parent_path) 
	{
		axiom_element_t *parent_path_element = NULL;
		axiom_node_t *parent_path_node = NULL;
		parent_path_element = axiom_element_create(env, entry_node, REMOTE_REGISTRY_FEED_KEY_PARENT_PATH, ns2, &parent_path_node);
		if(resource->is_collection) 
		{
			/* for collection parent path is always sent at the http request header */
			parent_path = "";
		}
		axiom_element_set_text(parent_path_element, env, parent_path, parent_path_node);
	}
	if(resource->is_collection)
	{
		axiom_element_t *content_modified_element = NULL;
		axiom_node_t *content_modified_node = NULL;
		content_modified_element = axiom_element_create(env, entry_node, 
				REMOTE_REGISTRY_FEED_KEY_CONTENT_MODIFIED, ns2, &content_modified_node);
		axiom_element_set_text(content_modified_element, env, 
				REMOTE_REGISTRY_FEED_KEY_TRUE_VALUE, content_modified_node);
	}

    return entry_node;
}
Exemplo n.º 11
0
axis2_status_t test_date_time(axutil_env_t *env)
{
    axutil_date_time_t *date_time = NULL;
    axutil_date_time_t *ref = NULL;
    axutil_date_time_t *date_time_offset = NULL;
    axis2_char_t *time_str = "22:45:12";
    axis2_char_t *date_str = "2000-12-12";
    axis2_char_t *date_time_str = "2000-11-11T12:30:24";
    axis2_status_t status = AXIS2_FAILURE;
    axutil_date_time_comp_result_t compare_res = AXIS2_DATE_TIME_COMP_RES_FAILURE;
    axis2_char_t *t_str = NULL, *d_str = NULL, *dt_str = NULL;
    int year , month , date , hour , min , sec , msec;

    date_time_offset = axutil_date_time_create_with_offset(env, 100);
    if(!date_time_offset)
    {
        printf("axutil_date_time_t creation failed.\n");
        return AXIS2_FAILURE;
    }
    date_time = axutil_date_time_create(env);
    if(!date_time)
    {
        printf("axutil_date_time_t creation failed.\n");
        return AXIS2_FAILURE;
    }
    status = axutil_date_time_deserialize_time(date_time, env, time_str);
    if(status)
        printf("axutil_date_time_t time string deserialization success.\n");
    status = axutil_date_time_deserialize_date(date_time, env, date_str);
    if(status)
        printf("axutil_date_time_t date string deserialization success.\n");
    status = axutil_date_time_deserialize_date_time(date_time, env, date_time_str);
    if(status)
        printf("axutil_date_time_t date time string deserialization success.\n");

    ref = axutil_date_time_create(env);
    if(!ref)
    {
        printf("axutil_date_time_t creation failed.\n");
        return AXIS2_FAILURE;
    }
    compare_res = axutil_date_time_compare(date_time, env, ref);
    if(compare_res == AXIS2_DATE_TIME_COMP_RES_FAILURE)
    {
        printf("axutil_date_time comparison failed.\n");
    }

    status = axutil_date_time_deserialize_date_time(ref, env, date_time_str);
    if(status)
        printf("axutil_date_time_t date time string deserialization success.\n");
    compare_res = axutil_date_time_compare(date_time, env, ref);
    if(compare_res == AXIS2_DATE_TIME_COMP_RES_EQUAL)
    {
        printf("axutil_date_time_t comparison success.");
    }
    status = axutil_date_time_set_date_time(date_time, env, 2008, 1, 8, 12, 18, 57, 799);
    if(status)
    {
        printf("axutil_date_time_t set date time success.\n");
    }

    t_str = axutil_date_time_serialize_time(date_time, env);
    if(!t_str)
    {
        printf("axutil_date_time_t time serialization failed.\n");
    }
    else
    {
        printf("axutil_date_time_t Time: %s\n", t_str);
    }
    d_str = axutil_date_time_serialize_date(date_time, env);
    if(!d_str)
    {
        printf("axutil_date_time_t date serialization failed.\n");
    }
    else
    {
        printf("axutil_date_time_t Date: %s\n", d_str);
    }
    dt_str = axutil_date_time_serialize_date_time(date_time, env);
    if(!dt_str)
    {
        printf("axutil_date_time_t date time serialization failed.\n");
    }
    else
    {
        printf("axutil_date_time_t Date Time: %s\n", dt_str);
    }
    year = axutil_date_time_get_year(date_time,env);
    month=axutil_date_time_get_month(date_time,env);
    date = axutil_date_time_get_day(date_time,env);
    hour = axutil_date_time_get_hour(date_time,env);
    min  = axutil_date_time_get_minute(date_time,env);
    sec  = axutil_date_time_get_second(date_time,env);
    msec = axutil_date_time_get_msec(date_time,env);
    printf("axutil_date_time_t year: %d \n",year);
    printf("axutil_date_time_t month: %d \n",month);
    printf("axutil_date_time_t date: %d \n",date);
    printf("axutil_date_time_t hour: %d \n",hour);
    printf("axutil_date_time_t min: %d \n",min);
    printf("axutil_date_time_t sec: %d \n",sec);
    printf("axutil_date_time_t msec: %d \n",msec);

    axutil_date_time_free(date_time,env);
    axutil_date_time_free(ref, env);
    axutil_date_time_free(date_time_offset, env);
    return AXIS2_SUCCESS;
}
Exemplo n.º 12
0
AXIS2_EXTERN remote_registry_comment_t* AXIS2_CALL
remote_registry_comment_create_from_entry_node(
    const axutil_env_t *env,
    axiom_node_t *entry_node)
{
    remote_registry_comment_t *comment = NULL;
    axiom_children_iterator_t *entry_it = NULL;
    axiom_element_t *entry_ele = NULL;

    comment = remote_registry_comment_create(env);
    if(comment == NULL)
    {
		AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    entry_ele = axiom_node_get_data_element(entry_node, env);
    entry_it = axiom_element_get_children(entry_ele, env, entry_node);

    while(axiom_children_iterator_has_next(entry_it, env))
    {
        axiom_node_t *child = NULL;
        axiom_element_t *child_ele = NULL;
        axis2_char_t *local_name = NULL;

        child = axiom_children_iterator_next(entry_it, env);

        if(axiom_node_get_node_type(child, env) != AXIOM_ELEMENT) 
        {
            continue;
        }
        child_ele = (axiom_element_t *)axiom_node_get_data_element(child, env);
        
        local_name = axiom_element_get_localname(child_ele, env);

        /* retriving the attribute one by one */
        if(!axutil_strcmp(local_name, "updated")) 
        {
            axis2_char_t *updated_text = NULL;
            axutil_date_time_t *updated_datetime = NULL;

            updated_text = axiom_element_get_text(child_ele, env, child);
            updated_datetime = axutil_date_time_create(env);
            axutil_date_time_deserialize_time(updated_datetime, env, updated_text);

            remote_registry_comment_set_date_time(comment, env, updated_datetime);
        }
        else if(!axutil_strcmp(local_name, "content")) 
        {
            axis2_char_t *content = NULL;
            
            content = axiom_element_get_text(child_ele, env, child);
            remote_registry_comment_set_text(comment, env, content);
        }
        else if(!axutil_strcmp(local_name, "author"))
        {
            axiom_node_t *name_node = NULL;
            axiom_element_t *name_element = NULL;

            name_node = axiom_node_get_first_child(child, env);

            /* get the first child (with type AXIOM_ELEMENT) where we can find the name */
            if(name_node && axiom_node_get_node_type(name_node, env) != AXIOM_ELEMENT)
            {
                name_node = axiom_node_get_next_sibling(name_node, env);
            }

            if(name_node)
            {
                axis2_char_t *name = NULL;
                name_element = axiom_node_get_data_element(name_node, env);

                name = axiom_element_get_text(name_element, env, name_node);

                remote_registry_comment_set_user(comment, env, name);
            }
        }
            
    }
   
    return comment;
}
        axis2_status_t AXIS2_CALL
        adb_contentItem_type0_deserialize_obj(
                adb_contentItem_type0_t* _contentItem_type0,
                const axutil_env_t *env,
                axiom_node_t **dp_parent,
                axis2_bool_t *dp_is_early_node_valid,
                axis2_bool_t dont_care_minoccurs)
        {
          axiom_node_t *parent = *dp_parent;
          
          axis2_status_t status = AXIS2_SUCCESS;
          
              axiom_attribute_t *parent_attri = NULL;
              axiom_element_t *parent_element = NULL;
              axis2_char_t *attrib_text = NULL;

              axutil_hash_t *attribute_hash = NULL;

          
              void *element = NULL;
           
             const axis2_char_t* text_value = NULL;
             axutil_qname_t *qname = NULL;
          
            axutil_qname_t *element_qname = NULL; 
            
               axiom_node_t *first_node = NULL;
               axis2_bool_t is_early_node_valid = AXIS2_TRUE;
               axiom_node_t *current_node = NULL;
               axiom_element_t *current_element = NULL;
            
            AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
            AXIS2_PARAM_CHECK(env->error, _contentItem_type0, AXIS2_FAILURE);

            
              
              while(parent && axiom_node_get_node_type(parent, env) != AXIOM_ELEMENT)
              {
                  parent = axiom_node_get_next_sibling(parent, env);
              }
              if (NULL == parent)
              {
                /* This should be checked before everything */
                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
                            "Failed in building adb object for contentItem_type0 : "
                            "NULL element can not be passed to deserialize");
                return AXIS2_FAILURE;
              }
              
                      
                      first_node = axiom_node_get_first_child(parent, env);
                      
                    
                 parent_element = (axiom_element_t *)axiom_node_get_data_element(parent, env);
                 attribute_hash = axiom_element_get_all_attributes(parent_element, env);
              

                     
                     /*
                      * building label element
                      */
                     
                     
                     
                                   current_node = first_node;
                                   is_early_node_valid = AXIS2_FALSE;
                                   
                                   
                                    while(current_node && axiom_node_get_node_type(current_node, env) != AXIOM_ELEMENT)
                                    {
                                        current_node = axiom_node_get_next_sibling(current_node, env);
                                    }
                                    if(current_node != NULL)
                                    {
                                        current_element = (axiom_element_t *)axiom_node_get_data_element(current_node, env);
                                        qname = axiom_element_get_qname(current_element, env, current_node);
                                    }
                                   
                                 element_qname = axutil_qname_create(env, "label", "http://www.daisy.org/ns/daisy-online/", NULL);
                                 

                           if (adb_label_type0_is_particle() ||  
                                (current_node   && current_element && (axutil_qname_equals(element_qname, env, qname))))
                           {
                              if( current_node   && current_element && (axutil_qname_equals(element_qname, env, qname)))
                              {
                                is_early_node_valid = AXIS2_TRUE;
                              }
                              
                                 
                                      element = (void*)axis2_extension_mapper_create_from_node(env, &current_node, "adb_label_type0");

                                      status =  adb_label_type0_deserialize((adb_label_type0_t*)element,
                                                                            env, &current_node, &is_early_node_valid, AXIS2_FALSE);
                                      if(AXIS2_FAILURE == status)
                                      {
                                          AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in building adb object for element label");
                                      }
                                      else
                                      {
                                          status = adb_contentItem_type0_set_label(_contentItem_type0, env,
                                                                   (adb_label_type0_t*)element);
                                      }
                                    
                                 if(AXIS2_FAILURE ==  status)
                                 {
                                     AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "failed in setting the value for label ");
                                     if(element_qname)
                                     {
                                         axutil_qname_free(element_qname, env);
                                     }
                                     return AXIS2_FAILURE;
                                 }
                              }
                           
                              else if(!dont_care_minoccurs)
                              {
                                  if(element_qname)
                                  {
                                      axutil_qname_free(element_qname, env);
                                  }
                                  /* this is not a nillable element*/
                                  AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "non nillable or minOuccrs != 0 element label missing");
                                  return AXIS2_FAILURE;
                              }
                           
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
                
                
                  parent_attri = NULL;
                  attrib_text = NULL;
                  if(attribute_hash)
                  {
                       axutil_hash_index_t *hi;
                       void *val;
                       const void *key;

                       for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, &key, NULL, &val);
                           
                           
                               if(!strcmp((axis2_char_t*)key, "id"))
                             
                               {
                                   parent_attri = (axiom_attribute_t*)val;
                                   AXIS2_FREE(env->allocator, hi);
                                   break;
                               }
                       }
                  }

                  if(parent_attri)
                  {
                    attrib_text = axiom_attribute_get_value(parent_attri, env);
                  }
                  else
                  {
                    /* this is hoping that attribute is stored in "id", this happnes when name is in default namespace */
                    attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "id");
                  }

                  if(attrib_text != NULL)
                  {
                      
                      adb_contentItem_type0_set_id(_contentItem_type0,
                                                          env, attrib_text);
                        
                    }
                  
                    else if(!dont_care_minoccurs)
                    {
                        if(element_qname)
                        {
                            axutil_qname_free(element_qname, env);
                        }
                        /* this is not a nillable element*/
                        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "required attribute id missing");
                        return AXIS2_FAILURE;
                    }
                  
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
                
                
                  parent_attri = NULL;
                  attrib_text = NULL;
                  if(attribute_hash)
                  {
                       axutil_hash_index_t *hi;
                       void *val;
                       const void *key;

                       for (hi = axutil_hash_first(attribute_hash, env); hi; hi = axutil_hash_next(env, hi)) 
                       {
                           axutil_hash_this(hi, &key, NULL, &val);
                           
                           
                               if(!strcmp((axis2_char_t*)key, "lastModifiedDate"))
                             
                               {
                                   parent_attri = (axiom_attribute_t*)val;
                                   AXIS2_FREE(env->allocator, hi);
                                   break;
                               }
                       }
                  }

                  if(parent_attri)
                  {
                    attrib_text = axiom_attribute_get_value(parent_attri, env);
                  }
                  else
                  {
                    /* this is hoping that attribute is stored in "lastModifiedDate", this happnes when name is in default namespace */
                    attrib_text = axiom_element_get_attribute_value_by_name(parent_element, env, "lastModifiedDate");
                  }

                  if(attrib_text != NULL)
                  {
                      
                      
                           element = (void*)axutil_date_time_create(env);
                           axutil_date_time_deserialize_date_time((axutil_date_time_t*)element, env,
                                                                      attrib_text);
                           adb_contentItem_type0_set_lastModifiedDate(_contentItem_type0,
                                                          env, (axutil_date_time_t*)element);
                        
                    }
                  
                  if(element_qname)
                  {
                     axutil_qname_free(element_qname, env);
                     element_qname = NULL;
                  }
                 
          return status;
       }