Author: damitha
Date: Tue Jul  3 02:10:46 2007
New Revision: 552752

URL: http://svn.apache.org/viewvc?view=rev&rev=552752
Log:
adding subscription manager functionality

Added:
    webservices/savan/trunk/c/src/subs_mgr/
    webservices/savan/trunk/c/src/subs_mgr/Makefile.am
    webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h
    webservices/savan/trunk/c/src/subs_mgr/services.xml
    webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c
    webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c

Added: webservices/savan/trunk/c/src/subs_mgr/Makefile.am
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/Makefile.am?view=auto&rev=552752
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/Makefile.am (added)
+++ webservices/savan/trunk/c/src/subs_mgr/Makefile.am Tue Jul  3 02:10:46 2007
@@ -0,0 +1,15 @@
+prglibdir=$(prefix)/services/subscription
+prglib_LTLIBRARIES = libsubscription.la
+prglib_DATA= services.xml
+noinst_HEADERS = savan_subs_mgr.h
+SUBDIRS =
+libsubscription_la_SOURCES = subs_mgr.c subs_mgr_skel.c
+libsubscription_la_LIBADD  = ../client/libsavan_client.la
+
+INCLUDES = -I$(top_builddir)/include \
+               @AXIOMINC@ \
+               @UTILINC@ \
+               @NEETHIINC@ \
+               @AXIS2INC@ 
+
+EXTRA_DIST=services.xml

Added: webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h?view=auto&rev=552752
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h (added)
+++ webservices/savan/trunk/c/src/subs_mgr/savan_subs_mgr.h Tue Jul  3 02:10:46 
2007
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef WSFES_SUBSCRIPTION_H
+#define WSFES_SUBSCRIPTION_H
+
+
+#include <axis2_svc_skeleton.h>
+#include <axutil_log_default.h>
+#include <axutil_error_default.h>
+#include <axiom_text.h>
+#include <axiom_node.h>
+#include <axiom_element.h>
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+savan_subs_mgr_add_subscriber(
+    const axutil_env_t *env,
+    axiom_node_t *node,
+    axis2_msg_ctx_t *msg_ctx);
+
+AXIS2_EXTERN void * AXIS2_CALL
+savan_subs_mgr_remove_subscriber(
+    const axutil_env_t *env,
+    axiom_node_t *remove_sub_node,
+    axis2_msg_ctx_t *msg_ctx);
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+savan_subs_mgr_get_subscriber_list(
+    const axutil_env_t *env,
+    axiom_node_t *node,
+    axis2_msg_ctx_t *msg_ctx);
+
+#endif /* WSFES_SUBSCRIPTION_H*/
+

Added: webservices/savan/trunk/c/src/subs_mgr/services.xml
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/services.xml?view=auto&rev=552752
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/services.xml (added)
+++ webservices/savan/trunk/c/src/subs_mgr/services.xml Tue Jul  3 02:10:46 2007
@@ -0,0 +1,29 @@
+<service name="subscription">
+   <description>
+        This is a subscription manager service
+   </description>
+    <parameter name="ServiceClass" locked="xsd:false">subscription</parameter>
+    <!--parameter name="loadServiceAtStartup" 
locked="xsd:false">true</parameter-->
+
+   <operation name="add_subscriber">
+           <!--messageReceiver class="axis2_receivers" /-->
+           <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/subscription/add_subscriber</parameter>
+   </operation>
+   <operation name="remove_subscriber">
+           <!--messageReceiver class="axis2_receivers" /-->
+           <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/subscription/remove_subscriber</parameter>
+   </operation>
+   <operation name="get_subscriber_list">
+           <!--messageReceiver class="axis2_receivers" /-->
+           <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/subscription/get_subscriber_list</parameter>
+   </operation>
+   <operation name="add_topic">
+           <!--messageReceiver class="axis2_receivers" /-->
+           <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/subscription/add_topic</parameter>
+   </operation>
+   <operation name="get_topic_list">
+           <!--messageReceiver class="axis2_receivers" /-->
+           <parameter name="wsamapping" 
>http://ws.apache.org/axis2/c/subscription/get_topic_list</parameter>
+   </operation>
+
+</service>

Added: webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c?view=auto&rev=552752
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c (added)
+++ webservices/savan/trunk/c/src/subs_mgr/subs_mgr.c Tue Jul  3 02:10:46 2007
@@ -0,0 +1,506 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axiom_xml_writer.h>
+#include <axiom_soap_envelope.h>
+#include <axiom_soap_body.h>
+#include <axis2_svc.h>
+#include <stdio.h>
+#include <savan_subscriber.h>
+#include <savan_util.h>
+#include <savan_constants.h>
+
+#include "savan_subs_mgr.h"
+
+static axis2_char_t *
+get_topic_from_url(
+    const axutil_env_t *env,
+    axis2_char_t *topic_url);
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+savan_subs_mgr_add_subscriber(
+    const axutil_env_t *env,
+    axiom_node_t *add_sub_node,
+    axis2_msg_ctx_t *msg_ctx)
+{
+    axis2_svc_t *subs_svc = NULL;
+    axis2_endpoint_ref_t *endto_epr = NULL;
+    axis2_endpoint_ref_t *notify_epr = NULL;
+    axutil_param_t *param = NULL;
+    axutil_hash_t *store = NULL;
+    axis2_char_t *topic_url = NULL;
+    axis2_char_t *topic = NULL;
+    savan_subs_mgr_info_t *sub_info = NULL;
+
+    savan_subscriber_t *subscriber = NULL;
+    axutil_qname_t *qname = NULL;
+    
+    axiom_node_t *sub_node = NULL;
+    axiom_node_t *id_node = NULL;
+    axiom_node_t *topic_node = NULL;
+    axiom_node_t *endto_node = NULL;
+    axiom_node_t *delivery_node = NULL;
+    axiom_node_t *notify_node = NULL;
+    axiom_node_t *filter_node = NULL;
+    axiom_node_t *expires_node = NULL;
+    
+    axiom_element_t *sub_elem = NULL;
+    axiom_element_t *id_elem = NULL;
+    axiom_element_t *topic_elem = NULL;
+    axiom_element_t *add_sub_elem = NULL;
+    axiom_element_t *endto_elem = NULL;
+    axiom_element_t *delivery_elem = NULL;
+    axiom_element_t *notify_elem = NULL;
+    axiom_element_t *expires_elem = NULL;
+    axiom_element_t *filter_elem = NULL;
+    
+    axis2_char_t *id = NULL;
+    axis2_char_t *endto = NULL;
+    axis2_char_t *notify = NULL;
+    axis2_char_t *expires = NULL;
+    axis2_char_t *filter = NULL;
+
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] Start:savan_subs_mgr_add_subscriber");
+    subs_svc = axis2_msg_ctx_get_svc(msg_ctx, env);
+    param = axis2_svc_get_param(subs_svc, env, SAVAN_SUBSCRIBER_LIST);
+    if (!param)
+    {
+        /* Store not found. Create and set it as a param */
+        savan_util_set_sub_store(subs_svc, env);
+        param = axis2_svc_get_param(subs_svc, env, SAVAN_SUBSCRIBER_LIST);
+    }
+    
+    store = (axutil_hash_t*)axutil_param_get_value(param, env);
+    if(!store)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
+            "subscriber store"); 
+        return NULL;
+    }
+    add_sub_elem = (axiom_element_t*)axiom_node_get_data_element(add_sub_node, 
env);
+    
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[ML] node:%s", 
axiom_node_to_string(add_sub_node, env));
+    /*Get topic element from node */
+    qname = axutil_qname_create(env, ELEM_NAME_TOPIC, SAVAN_NAMESPACE, NULL);
+    topic_elem = axiom_element_get_first_child_with_qname(add_sub_elem, env, 
qname,
+        add_sub_node, &topic_node);
+    axutil_qname_free(qname, env);
+    topic_url = axiom_element_get_text(topic_elem, env, topic_node);
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] Subscriber will be added to the topic:%s ", topic_url);
+    topic = get_topic_from_url(env, topic_url);
+    sub_info = axutil_hash_get(store, topic, AXIS2_HASH_KEY_STRING);
+    if(!sub_info)
+    {
+        sub_info = AXIS2_MALLOC(env->allocator, 
+            sizeof(struct savan_subs_mgr_info));
+        sub_info->list = axutil_hash_make(env);
+        axutil_hash_set(store, topic, AXIS2_HASH_KEY_STRING, sub_info);
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "[ML] Topic:%s is added to the store", topic);
+    }
+    subscriber = savan_subscriber_create(env);
+    if (!subscriber)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to create a"
+            "subscriber instance"); 
+        return NULL;
+    }
+    /* Set topic element */
+    savan_subscriber_set_topic(subscriber, env, topic_url);
+
+    /* Get Id element from AddSubscriber*/
+    qname = axutil_qname_create(env, ELEM_NAME_ID, SAVAN_NAMESPACE, NULL);
+    id_elem = axiom_element_get_first_child_with_qname(add_sub_elem, env, 
qname,
+        add_sub_node, &id_node);
+    axutil_qname_free(qname, env);
+   
+    id = axiom_element_get_text(id_elem, env, id_node);
+    savan_subscriber_set_id(subscriber, env, id);
+    id = savan_subscriber_get_id(subscriber, env);
+    /* Get subscriber element from Body */
+    qname = axutil_qname_create(env, ELEM_NAME_SUBSCRIBE, EVENTING_NAMESPACE, 
NULL);
+    sub_elem = axiom_element_get_first_child_with_qname(add_sub_elem, env, 
qname,
+        add_sub_node, &sub_node);
+    axutil_qname_free(qname, env);
+    
+    /* Now read each sub element of Subscribe element */
+        
+    /* EndTo */
+    qname = axutil_qname_create(env, ELEM_NAME_ENDTO, EVENTING_NAMESPACE, 
NULL);
+    endto_elem = axiom_element_get_first_child_with_qname(sub_elem, env, qname,
+        sub_node, &endto_node);
+    axutil_qname_free(qname, env);
+    
+    endto = axiom_element_get_text(endto_elem, env, endto_node);
+    
+    endto_epr = axis2_endpoint_ref_create(env, endto);
+    
+    savan_subscriber_set_end_to(subscriber, env, endto_epr);
+    
+    /* Get Delivery element and read NotifyTo */
+    qname = axutil_qname_create(env, ELEM_NAME_DELIVERY, EVENTING_NAMESPACE, 
NULL);
+    delivery_elem = axiom_element_get_first_child_with_qname(sub_elem, env, 
qname,
+        sub_node, &delivery_node);
+    axutil_qname_free(qname, env);
+    
+    qname = axutil_qname_create(env, ELEM_NAME_NOTIFYTO, EVENTING_NAMESPACE, 
NULL);
+    notify_elem = axiom_element_get_first_child_with_qname(delivery_elem, env, 
qname,
+        delivery_node, &notify_node);
+    axutil_qname_free(qname, env);
+    
+    notify = axiom_element_get_text(notify_elem, env, notify_node);
+    
+    notify_epr = axis2_endpoint_ref_create(env, notify);
+    
+    savan_subscriber_set_notify_to(subscriber, env, notify_epr);
+    
+    /* Expires */
+    qname = axutil_qname_create(env, ELEM_NAME_EXPIRES, EVENTING_NAMESPACE, 
NULL);
+    expires_elem = axiom_element_get_first_child_with_qname(sub_elem, env, 
qname,
+        sub_node, &expires_node);
+    axutil_qname_free(qname, env);
+    
+    expires = axiom_element_get_text(expires_elem, env, expires_node);
+    
+    savan_subscriber_set_expires(subscriber, env, expires);
+    
+    /* Filter */
+    qname = axutil_qname_create(env, ELEM_NAME_FILTER, EVENTING_NAMESPACE, 
NULL);
+    filter_elem = axiom_element_get_first_child_with_qname(sub_elem, env, 
qname,
+        sub_node, &filter_node);
+    axutil_qname_free(qname, env);
+    
+    filter = axiom_element_get_text(filter_elem, env, filter_node);
+    
+    savan_subscriber_set_filter(subscriber, env, filter);
+    if(sub_info->list)
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "[ML] Subscriber %s added to the topic:%s", id, topic_url);
+        axutil_hash_set(sub_info->list, id, AXIS2_HASH_KEY_STRING, subscriber);
+    }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] End:savan_subs_mgr_add_subscriber");
+    return NULL;   
+}
+
+AXIS2_EXTERN void * AXIS2_CALL
+savan_subs_mgr_remove_subscriber(
+    const axutil_env_t *env,
+    axiom_node_t *remove_sub_node,
+    axis2_msg_ctx_t *msg_ctx)
+{
+    axis2_svc_t *subs_svc = NULL;
+    axutil_param_t *param = NULL;
+    axutil_hash_t *store = NULL;
+    axis2_char_t *topic = NULL;
+    axis2_char_t *topic_url = NULL;
+    savan_subs_mgr_info_t *sub_info = NULL;
+
+    axutil_qname_t *qname = NULL;
+    
+    axiom_node_t *id_node = NULL;
+    axiom_node_t *topic_node = NULL;
+    
+    axiom_element_t *id_elem = NULL;
+    axiom_element_t *topic_elem = NULL;
+    axiom_element_t *remove_sub_elem = NULL;
+    
+    axis2_char_t *id = NULL;
+
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] Start:savan_subs_mgr_remove_subscriber");
+    subs_svc = axis2_msg_ctx_get_svc(msg_ctx, env);
+    param = axis2_svc_get_param(subs_svc, env, SAVAN_SUBSCRIBER_LIST);
+    if (!param)
+    {
+        /* Store not found. Create and set it as a param */
+        savan_util_set_sub_store(subs_svc, env);
+        param = axis2_svc_get_param(subs_svc, env, SAVAN_SUBSCRIBER_LIST);
+    }
+    
+    store = (axutil_hash_t*)axutil_param_get_value(param, env);
+    if(!store)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
+            "subscriber store"); 
+        return NULL;
+    }
+    remove_sub_elem = 
(axiom_element_t*)axiom_node_get_data_element(remove_sub_node, env);
+    
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[ML] node:%s", 
axiom_node_to_string(remove_sub_node, env));
+    /*Get topic element from node */
+    qname = axutil_qname_create(env, ELEM_NAME_TOPIC, SAVAN_NAMESPACE, NULL);
+    topic_elem = axiom_element_get_first_child_with_qname(remove_sub_elem, 
env, qname,
+        remove_sub_node, &topic_node);
+    axutil_qname_free(qname, env);
+    topic_url = axiom_element_get_text(topic_elem, env, topic_node);
+    topic = get_topic_from_url(env, topic_url);
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] Subscriber will be removed from the topic:%s ", topic);
+    sub_info = axutil_hash_get(store, topic, AXIS2_HASH_KEY_STRING);
+    if(!sub_info)
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "[ML] There are no subscribers for the ", topic_url);
+        return NULL;
+    }
+
+    /* Get Id element from RemoveSubscriber*/
+    qname = axutil_qname_create(env, ELEM_NAME_ID, SAVAN_NAMESPACE, NULL);
+    id_elem = axiom_element_get_first_child_with_qname(remove_sub_elem, env, 
qname,
+        remove_sub_node, &id_node);
+    axutil_qname_free(qname, env);
+    
+    id = axiom_element_get_text(id_elem, env, id_node);
+    
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] Removing subscriber with id %s from topic %s", id, topic_url);
+    
+    if(sub_info->list)
+    {
+        savan_subscriber_t *subscriber = NULL;
+        axutil_hash_set(sub_info->list, id, AXIS2_HASH_KEY_STRING, NULL);
+        subscriber = axutil_hash_get(sub_info->list, id, 
AXIS2_HASH_KEY_STRING);
+        if(subscriber)
+            savan_subscriber_free(subscriber, env);
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "[ML] Subscriber %s removed from the topic:%s", id, topic_url);
+    }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "[ML] End:savan_subs_mgr_remove_subscriber");
+    return NULL;   
+}
+
+AXIS2_EXTERN axiom_node_t *AXIS2_CALL
+savan_subs_mgr_get_subscriber_list(
+    const axutil_env_t *env,
+    axiom_node_t *node,
+    axis2_msg_ctx_t *msg_ctx)
+{
+
+    axis2_svc_t *subs_svc = NULL;
+    axutil_param_t *param = NULL;
+    axis2_char_t *topic_url = NULL;
+    axis2_char_t *topic = NULL;
+    savan_subs_mgr_info_t *sub_info = NULL;
+    axutil_hash_t *sub_list = NULL;
+    axutil_hash_t *store = NULL;
+    axutil_hash_index_t *hi = NULL;
+    axis2_char_t *sub_url = NULL;
+    axiom_namespace_t *ns = NULL;
+    axiom_namespace_t *ns1 = NULL;
+    axiom_node_t *subs_list_node = NULL;
+    axiom_node_t *topic_parent_node = NULL;
+    axiom_node_t *topic_node = NULL;
+    axiom_element_t* subs_list_elem = NULL;
+
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "Start:savan_subs_mgr_get_subscriber_list");
+    subs_svc = axis2_msg_ctx_get_svc(msg_ctx, env);
+    param = axis2_svc_get_param(subs_svc, env, SAVAN_SUBSCRIBER_LIST);
+    if (!param)
+    {
+        /* Store not found. Create and set it as a param */
+        savan_util_set_sub_store(subs_svc, env);
+        param = axis2_svc_get_param(subs_svc, env, SAVAN_SUBSCRIBER_LIST);
+    }
+    
+    store = (axutil_hash_t*)axutil_param_get_value(param, env);
+    if(!store)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[ML] Failed to extract the "
+            "subscriber store"); 
+        return NULL;
+    }
+
+    /* Expected request format is :-
+     * <ns1:Subscribers xmlns:ns1="http://ws.apache.org/savan";>
+     *      <Topic>topic_url</Topic>
+     *      <ns:Susbscriber 
xmlns:ns="http://schemas.xmlsoap.org/ws/2004/08/eventing";>
+     *      ...
+     *      </ns:Subscriber>
+     *      <ns:Susbscriber 
xmlns:ns="http://schemas.xmlsoap.org/ws/2004/08/eventing";>
+     *      ...
+     *      </ns:Subscriber>
+     * </ns1:Subscribers>
+     */
+    if (!node) /* 'Subscribers' node */
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SVC_SKEL_INPUT_OM_NODE_NULL, 
+            AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "Echo client ERROR: input parameter NULL");
+        return NULL;
+    }
+
+    topic_parent_node = axiom_node_get_first_element(node, env);
+    if (!topic_parent_node) 
+    {
+        AXIS2_ERROR_SET(env->error, 
+            AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+            "Echo client ERROR 1: invalid XML in request");
+        return NULL;
+    }
+
+    topic_node = axiom_node_get_first_child(topic_parent_node, env);
+    if (!topic_node) /* actual topic text */
+    {
+        AXIS2_ERROR_SET(env->error, 
+            AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "invalid XML in request");
+        return NULL;
+    }
+
+    if (axiom_node_get_node_type(topic_node, env) == AXIOM_TEXT)
+    {
+        axiom_text_t *topic_text = (axiom_text_t *)axiom_node_get_data_element(
+            topic_node, env);
+        if (topic_text && axiom_text_get_value(topic_text , env))
+        {
+            topic_url = (axis2_char_t *)axiom_text_get_value(topic_text, env);
+            topic = get_topic_from_url(env, topic_url);
+            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "Requested Topic:%s", 
topic);
+        }
+    }
+    else
+    {
+        AXIS2_ERROR_SET(env->error, 
+            AXIS2_ERROR_SVC_SKEL_INVALID_XML_FORMAT_IN_REQUEST, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Invalid XML in request");
+        return NULL;
+    }
+
+    /* Retrive subscribers for the topic */
+    sub_info = axutil_hash_get(store, topic, AXIS2_HASH_KEY_STRING);
+    if(sub_info)
+    {
+        sub_url = sub_info->url;
+        sub_list = sub_info->list;
+    }
+    /* create the body of the subscribers element */
+    ns = axiom_namespace_create (env, EVENTING_NAMESPACE, EVENTING_NS_PREFIX);
+    ns1 = axiom_namespace_create (env, SAVAN_NAMESPACE, SAVAN_NS_PREFIX);
+    subs_list_elem = axiom_element_create(env, NULL, ELEM_NAME_SUBSCRIBERS, 
ns1, 
+        &subs_list_node);
+    if(!sub_list)
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "No subscribers regirsterd for"
+            " the topic:%s", topic_url);
+        return subs_list_node;
+    }
+    for (hi = axutil_hash_first(sub_list, env); hi; hi =
+        axutil_hash_next(env, hi))
+    {
+        AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+            "subscribers not empty for topic :%s", topic_url);
+        void *val = NULL;
+        savan_subscriber_t * subscriber = NULL;
+        axutil_hash_this(hi, NULL, NULL, &val);
+        subscriber = (savan_subscriber_t *)val;
+
+        if (subscriber)
+        {
+            axiom_node_t *topic_node = NULL;
+            axiom_node_t *sub_node = NULL;
+            axiom_node_t *endto_node = NULL;
+            axiom_node_t *id_node = NULL;
+            axiom_node_t *delivery_node = NULL;
+            axiom_node_t *notify_node = NULL;
+            axiom_node_t *filter_node = NULL;
+            axiom_node_t *expires_node = NULL;
+            axiom_element_t* sub_elem = NULL;
+            axiom_element_t* id_elem = NULL;
+            axiom_element_t* topic_elem = NULL;
+            axiom_element_t* endto_elem = NULL;
+            axiom_element_t* delivery_elem = NULL;
+            axiom_element_t* notify_elem = NULL;
+            axiom_element_t* filter_elem = NULL;
+            axiom_element_t* expires_elem = NULL;
+            const axis2_char_t *endto = NULL;
+            const axis2_char_t *notify = NULL;
+            const axis2_char_t *filter = NULL;
+            const axis2_char_t *expires = NULL;
+            axis2_char_t *id = NULL;
+            axis2_char_t *topic = NULL;
+
+            axis2_endpoint_ref_t *endto_ref = 
savan_subscriber_get_end_to(subscriber, env);
+            endto = axis2_endpoint_ref_get_address(endto_ref, env);
+            axis2_endpoint_ref_t *notify_ref = 
savan_subscriber_get_notify_to(subscriber, env);
+            notify = axis2_endpoint_ref_get_address(notify_ref, env);
+            filter = savan_subscriber_get_filter(subscriber, env); 
+            expires = savan_subscriber_get_expires(subscriber, env);
+            id = savan_subscriber_get_id(subscriber, env);
+          
+            /* create the topic element */
+            topic_elem = axiom_element_create(env, subs_list_node, 
+                ELEM_NAME_TOPIC, ns1, &topic_node);
+            topic = savan_subscriber_get_topic(subscriber, env);
+            if(topic)
+                axiom_element_set_text(topic_elem, env, topic, topic_node); 
+            /* create the subscriber element */
+
+            sub_elem = axiom_element_create(env, subs_list_node, 
+                ELEM_NAME_SUBSCRIBE, ns, &sub_node);
+            
+            /* Id element */
+            id_elem = axiom_element_create(env, sub_node, ELEM_NAME_ID, ns1,
+                &id_node);
+            axiom_element_set_text(id_elem, env, id, id_node);
+
+            /* EndTo element */
+            endto_elem = axiom_element_create(env, sub_node, ELEM_NAME_ENDTO, 
ns,
+                &endto_node);
+            axiom_element_set_text(endto_elem, env, endto, endto_node);
+            
+            /* Delivery element */
+            delivery_elem = axiom_element_create(env, sub_node, 
+                ELEM_NAME_DELIVERY, ns, &delivery_node);
+                
+            notify_elem = axiom_element_create(env, delivery_node, 
+                ELEM_NAME_NOTIFYTO, ns, &notify_node);
+            axiom_element_set_text(notify_elem, env, notify, notify_node);
+            
+            /* Expires element */
+            expires_elem = axiom_element_create(env, sub_node, 
+                ELEM_NAME_EXPIRES, ns, &expires_node);
+            axiom_element_set_text(expires_elem, env, expires, expires_node);
+            /* Filter element */
+            filter_elem = axiom_element_create(env, sub_node, 
ELEM_NAME_FILTER, 
+                ns, &endto_node);
+            axiom_element_set_text(filter_elem, env, filter, filter_node);
+        }
+
+        val = NULL;
+    }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, 
+        "End:savan_subs_mgr_get_subscriber_list");
+    return subs_list_node;
+}
+
+static axis2_char_t *
+get_topic_from_url(
+    const axutil_env_t *env,
+    axis2_char_t *topic_url)
+{
+    axis2_char_t *topic = NULL;
+    topic  = axutil_strdup(env, axutil_rindex(topic_url, '/') + 1);
+    return topic;
+}
+

Added: webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c
URL: 
http://svn.apache.org/viewvc/webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c?view=auto&rev=552752
==============================================================================
--- webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c (added)
+++ webservices/savan/trunk/c/src/subs_mgr/subs_mgr_skel.c Tue Jul  3 02:10:46 
2007
@@ -0,0 +1,241 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include <axis2_svc_skeleton.h>
+#include <axutil_array_list.h>
+#include <axiom_element.h>
+#include <axiom_soap_envelope.h>
+#include <axiom_soap_header.h>
+#include <axiom_soap_body.h>
+#include <axiom_soap_fault.h>
+#include <axiom_stax_builder.h>
+#include <axis2_engine.h>
+#include <axis2_conf_ctx.h>
+#include <axis2_conf_init.h>
+#include <axutil_thread_pool.h>
+#include <axis2_util.h>
+#include <axis2_svc_client.h>
+#include <axis2_options.h>
+
+#include "savan_subs_mgr.h"
+
+int AXIS2_CALL
+savan_subs_mgr_free(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env);
+
+axis2_status_t AXIS2_CALL
+savan_subs_mgr_free_void_arg(
+    void *svc_skeleton,
+    const axutil_env_t *env);
+
+/*
+ * This method invokes the right service method 
+ */
+axiom_node_t* AXIS2_CALL 
+savan_subs_mgr_invoke(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env,
+    axiom_node_t *node,
+    axis2_msg_ctx_t *msg_ctx);
+            
+
+int AXIS2_CALL 
+savan_subs_mgr_init(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env);
+
+int AXIS2_CALL 
+savan_subs_mgr_init_with_conf(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env,
+    axis2_conf_t *conf);
+
+axiom_node_t* AXIS2_CALL
+savan_subs_mgr_on_fault(
+    axis2_svc_skeleton_t *svc_skeli, 
+    const axutil_env_t *env, 
+    axiom_node_t *node);
+
+static const axis2_svc_skeleton_ops_t savan_subs_mgr_skeleton_ops_var = {
+    savan_subs_mgr_init,
+    savan_subs_mgr_invoke,
+    savan_subs_mgr_on_fault,
+    savan_subs_mgr_free,
+    savan_subs_mgr_init_with_conf
+};
+
+/*Create function */
+axis2_svc_skeleton_t *
+savan_subs_mgr_create(
+    const axutil_env_t *env)
+{
+
+    axis2_svc_skeleton_t *svc_skeleton = NULL;
+
+       
+       AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "savan_subs_mgr service create 
called");
+
+       /* Allocate memory for the structs */
+    svc_skeleton = AXIS2_MALLOC(env->allocator, sizeof(axis2_svc_skeleton_t));
+
+    svc_skeleton->ops = &savan_subs_mgr_skeleton_ops_var;
+    svc_skeleton->func_array = NULL;
+
+    /* Assign function pointers */
+    
+    return svc_skeleton;
+}
+
+/* Initialize the service */
+int AXIS2_CALL
+savan_subs_mgr_init(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env)
+{
+    svc_skeleton->func_array = axutil_array_list_create(env, 0);
+    /* Add the implemented operation names of the service to
+     * the array list of functions
+     */
+    axutil_array_list_add(svc_skeleton->func_array, env, "add_subscriber");
+    axutil_array_list_add(svc_skeleton->func_array, env, "remove_subscriber");
+    axutil_array_list_add(svc_skeleton->func_array, env, 
"get_subscriber_list");
+    axutil_array_list_add(svc_skeleton->func_array, env, "add_topic");
+    axutil_array_list_add(svc_skeleton->func_array, env, "get_topic_list");
+    return AXIS2_SUCCESS;
+}
+
+int AXIS2_CALL 
+savan_subs_mgr_init_with_conf(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env,
+    axis2_conf_t *conf)
+{
+    savan_subs_mgr_init(svc_skeleton, env);
+    return AXIS2_SUCCESS;
+}
+
+/*
+ * This method invokes the right service method 
+ */
+axiom_node_t* AXIS2_CALL
+savan_subs_mgr_invoke(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env,
+    axiom_node_t *node,
+    axis2_msg_ctx_t *msg_ctx)
+{
+    /* Invoke the business logic.
+     * Depending on the function name invoke the correct impl method.
+     */
+    axis2_op_t *op = NULL;
+    axutil_qname_t *op_qname = NULL;
+    axis2_char_t *op_name = NULL;
+    
+    op = axis2_msg_ctx_get_op(msg_ctx, env);
+    if(op)
+    {
+        op_qname = (axutil_qname_t *)axis2_op_get_qname(op, env);
+        if(op_qname)
+            op_name = axutil_qname_get_localpart(op_qname, env);
+        if(op_name)
+        {
+            if (axutil_strcmp(op_name, "add_subscriber") == 0)
+                return savan_subs_mgr_add_subscriber(env, node, msg_ctx);
+            if (axutil_strcmp(op_name, "remove_subscriber") == 0)
+                return savan_subs_mgr_remove_subscriber(env, node, msg_ctx);
+            if (axutil_strcmp(op_name, "get_subscriber_list") == 0)
+                return savan_subs_mgr_get_subscriber_list(env, node, msg_ctx);
+            /*if (axutil_strcmp(op_name, "add_topic") == 0)
+                return savan_subs_mgr_add_topic(env, node, msg_ctx);
+            if (axutil_strcmp(op_name, "get_topic_list") == 0)
+                return savan_subs_mgr_get_topic_list(env, node, msg_ctx);*/
+        }
+    }
+    return NULL;
+}
+
+/* On fault, handle the fault */
+axiom_node_t* AXIS2_CALL
+savan_subs_mgr_on_fault(
+    axis2_svc_skeleton_t *svc_skeli, 
+    const axutil_env_t *env, 
+    axiom_node_t *node)
+{
+   /* Here we are just setting a simple error message inside an element 
+    * called 'EchoServiceError' 
+    */
+    axiom_node_t *error_node = NULL;
+    axiom_node_t* text_node = NULL;
+    axiom_element_t *error_ele = NULL;
+    error_ele = axiom_element_create(env, node, "TestServiceError", NULL, 
+        &error_node);
+    axiom_element_set_text(error_ele, env, "Test service failed ", 
+        text_node);
+    return error_node;
+}
+
+/* Free the resources used */
+int AXIS2_CALL
+savan_subs_mgr_free(
+    axis2_svc_skeleton_t *svc_skeleton,
+    const axutil_env_t *env)
+{
+    /* Free the function array */
+    if(svc_skeleton->func_array)
+    {
+        axutil_array_list_free(svc_skeleton->func_array, env);
+    }
+    
+    /* Free the service skeleton */
+    if(svc_skeleton)
+    {
+        AXIS2_FREE(env->allocator, svc_skeleton);
+    }
+
+    return AXIS2_SUCCESS; 
+}
+
+/**
+ * Following block distinguish the exposed part of the dll.
+ */
+AXIS2_EXPORT int 
+axis2_get_instance(
+    axis2_svc_skeleton_t **inst,
+    const axutil_env_t *env)
+{
+   *inst = savan_subs_mgr_create(env);
+    if(!(*inst))
+    {
+        return AXIS2_FAILURE;
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+AXIS2_EXPORT int 
+axis2_remove_instance(
+    axis2_svc_skeleton_t *inst,
+    const axutil_env_t *env)
+{
+    axis2_status_t status = AXIS2_FAILURE;
+    if (inst)
+    {
+        status = AXIS2_SVC_SKELETON_FREE(inst, env);
+    }
+    return status;
+}
+


Reply via email to