Management SOAP Comet Notify Event

This commit is contained in:
vemax78 2013-11-24 23:02:09 +01:00
parent d303f057f0
commit 91bc075d6a
5 changed files with 98 additions and 17 deletions

View File

@ -1,4 +1,5 @@
#include "ac.h"
#include "capwap_dfa.h"
#include "ac_backend.h"
#include "ac_soap.h"
#include "ac_session.h"
@ -32,7 +33,7 @@ struct ac_backend_t {
static struct ac_backend_t g_ac_backend;
/* */
static int ac_backend_parsing_closewtpsession_event(struct json_object* jsonparams) {
static int ac_backend_parsing_closewtpsession_event(const char* idevent, struct json_object* jsonparams) {
int result = 0;
struct ac_session_t* session;
struct json_object* jsonvalue;
@ -51,10 +52,19 @@ static int ac_backend_parsing_closewtpsession_event(struct json_object* jsonpara
/* Get session */
session = ac_search_session_from_wtpid(wtpid);
if (session) {
struct ac_session_notify_event_t notify;
/* Notify Request to Complete Event */
strcpy(notify.idevent, idevent);
notify.action = NOTIFY_ACTION_CHANGE_STATE;
notify.session_state = CAPWAP_DEAD_STATE;
ac_session_send_action(session, AC_SESSION_ACTION_NOTIFY_EVENT, 0, (void*)&notify, sizeof(struct ac_session_notify_event_t));
/* */
capwap_logging_debug("Receive close wtp session for WTP %s", session->wtpid);
/* Close session */
ac_session_close(session);
/* Async close session */
ac_session_send_action(session, AC_SESSION_ACTION_CLOSE, 0, NULL, 0);
ac_session_release_reference(session);
result = 1;
}
@ -64,7 +74,7 @@ static int ac_backend_parsing_closewtpsession_event(struct json_object* jsonpara
}
/* */
static int ac_backend_parsing_resetwtp_event(struct json_object* jsonparams) {
static int ac_backend_parsing_resetwtp_event(const char* idevent, struct json_object* jsonparams) {
int result = 0;
struct ac_session_t* session;
struct json_object* jsonvalue;
@ -99,6 +109,7 @@ static int ac_backend_parsing_resetwtp_event(struct json_object* jsonparams) {
if (name && *name) {
int length;
struct ac_notify_reset_t* reset;
struct ac_session_notify_event_t notify;
/* Notification data */
length = sizeof(struct ac_notify_reset_t) + strlen(name) + 1;
@ -108,6 +119,12 @@ static int ac_backend_parsing_resetwtp_event(struct json_object* jsonparams) {
reset->vendor = (uint32_t)json_object_get_int(jsonvendor);
strcpy((char*)reset->name, name);
/* Notify Request to Complete Event */
strcpy(notify.idevent, idevent);
notify.action = NOTIFY_ACTION_CHANGE_STATE;
notify.session_state = CAPWAP_DEAD_STATE;
ac_session_send_action(session, AC_SESSION_ACTION_NOTIFY_EVENT, 0, (void*)&notify, sizeof(struct ac_session_notify_event_t));
/* Notify Action */
capwap_logging_debug("Receive reset request for WTP %s", session->wtpid);
ac_session_send_action(session, AC_SESSION_ACTION_RESET_WTP, 0, (void*)reset, length);
@ -127,28 +144,28 @@ static int ac_backend_parsing_resetwtp_event(struct json_object* jsonparams) {
}
/* */
static int ac_backend_parsing_addwlan_event(struct json_object* jsonparams) {
static int ac_backend_parsing_addwlan_event(const char* idevent, struct json_object* jsonparams) {
int result = 0;
return result;
}
/* */
static int ac_backend_parsing_updatewlan_event(struct json_object* jsonparams) {
static int ac_backend_parsing_updatewlan_event(const char* idevent, struct json_object* jsonparams) {
int result = 0;
return result;
}
/* */
static int ac_backend_parsing_deletewlan_event(struct json_object* jsonparams) {
static int ac_backend_parsing_deletewlan_event(const char* idevent, struct json_object* jsonparams) {
int result = 0;
return result;
}
/* */
static int ac_backend_soap_update_event(int idevent, int status) {
static int ac_backend_soap_update_event(const char* idevent, int status) {
int result = 0;
char buffer[256];
struct ac_soap_request* request;
@ -168,7 +185,7 @@ static int ac_backend_soap_update_event(int idevent, int status) {
request = ac_soapclient_create_request("updateBackendEvent", SOAP_NAMESPACE_URI);
if (request) {
ac_soapclient_add_param(request, "xs:string", "idsession", g_ac_backend.backendsessionid);
ac_soapclient_add_param(request, "xs:int", "idevent", capwap_itoa(idevent, buffer));
ac_soapclient_add_param(request, "xs:string", "idevent", idevent);
ac_soapclient_add_param(request, "xs:int", "status", capwap_itoa(status, buffer));
g_ac_backend.soaprequest = ac_soapclient_prepare_request(request, server);
}
@ -223,8 +240,8 @@ static void ac_backend_parsing_event(struct json_object* jsonitem) {
/* Get EventID */
jsonvalue = json_object_object_get(jsonitem, "EventID");
if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_int)) {
int idevent = json_object_get_int(jsonvalue);
if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_string)) {
const char* idevent = json_object_get_string(jsonvalue);
/* Get Action */
jsonvalue = json_object_object_get(jsonitem, "Action");
@ -237,15 +254,15 @@ static void ac_backend_parsing_event(struct json_object* jsonitem) {
/* Parsing params according to the action */
if (!strcmp(action, "CloseWTPSession")) {
result = ac_backend_parsing_closewtpsession_event(jsonvalue);
result = ac_backend_parsing_closewtpsession_event(idevent, jsonvalue);
} else if (!strcmp(action, "ResetWTP")) {
result = ac_backend_parsing_resetwtp_event(jsonvalue);
result = ac_backend_parsing_resetwtp_event(idevent, jsonvalue);
} else if (!strcmp(action, "AddWLAN")) {
result = ac_backend_parsing_addwlan_event(jsonvalue);
result = ac_backend_parsing_addwlan_event(idevent, jsonvalue);
} else if (!strcmp(action, "UpdateWLAN")) {
result = ac_backend_parsing_updatewlan_event(jsonvalue);
result = ac_backend_parsing_updatewlan_event(idevent, jsonvalue);
} else if (!strcmp(action, "DeleteWLAN")) {
result = ac_backend_parsing_deletewlan_event(jsonvalue);
result = ac_backend_parsing_deletewlan_event(idevent, jsonvalue);
}
/* Notify result action */

View File

@ -532,6 +532,7 @@ static struct ac_session_t* ac_create_session(struct sockaddr_storage* wtpaddres
session->packets = capwap_list_create();
session->requestfragmentpacket = capwap_list_create();
session->responsefragmentpacket = capwap_list_create();
session->notifyevent = capwap_list_create();
session->mtu = g_ac.mtu;
session->state = CAPWAP_IDLE_STATE;

View File

@ -13,6 +13,11 @@ static int ac_session_action_execute(struct ac_session_t* session, struct ac_ses
int result = AC_ERROR_ACTION_SESSION;
switch (action->action) {
case AC_SESSION_ACTION_CLOSE: {
result = CAPWAP_ERROR_CLOSE;
break;
}
case AC_SESSION_ACTION_RESET_WTP: {
struct capwap_imageidentifier_element imageidentifier;
struct ac_notify_reset_t* reset = (struct ac_notify_reset_t*)action->data;
@ -45,6 +50,17 @@ static int ac_session_action_execute(struct ac_session_t* session, struct ac_ses
break;
}
case AC_SESSION_ACTION_NOTIFY_EVENT: {
struct capwap_list_item* item;
/* Copy event into queue */
item = capwap_itemlist_create(sizeof(struct ac_session_notify_event_t));
memcpy(item->item, action->data, sizeof(struct ac_session_notify_event_t));
capwap_itemlist_insert_after(session->notifyevent, NULL, item);
break;
}
}
return result;
@ -301,6 +317,7 @@ static void ac_session_destroy(struct ac_session_t* session) {
capwap_list_free(session->requestfragmentpacket);
capwap_list_free(session->responsefragmentpacket);
capwap_list_free(session->notifyevent);
/* Free DFA resource */
capwap_array_free(session->dfa.acipv4list.addresses);
@ -470,6 +487,8 @@ static void ac_session_run(struct ac_session_t* session) {
/* Change WTP state machine */
void ac_dfa_change_state(struct ac_session_t* session, int state) {
struct capwap_list_item* search;
ASSERT(session != NULL);
if (state != session->state) {
@ -480,6 +499,30 @@ void ac_dfa_change_state(struct ac_session_t* session, int state) {
#endif
session->state = state;
/* Search into notify event*/
search = session->notifyevent->first;
while (search != NULL) {
struct ac_session_notify_event_t* notify = (struct ac_session_notify_event_t*)search->item;
if ((notify->action == NOTIFY_ACTION_CHANGE_STATE) && (notify->session_state == state)) {
char buffer[4];
struct ac_soap_response* response;
/* */
capwap_itoa(SOAP_EVENT_STATUS_COMPLETE, buffer);
response = ac_soap_updatebackendevent(session, notify->idevent, capwap_itoa(SOAP_EVENT_STATUS_COMPLETE, buffer));
if (response) {
ac_soapclient_free_response(response);
}
/* Remove notify event */
capwap_itemlist_free(capwap_itemlist_remove(session->notifyevent, search));
break;
}
search = search->next;
}
}
}

View File

@ -19,8 +19,10 @@ struct ac_session_control {
};
/* */
#define AC_SESSION_ACTION_CLOSE 0
#define AC_SESSION_ACTION_RESET_WTP 1
#define AC_SESSION_ACTION_ESTABLISHED_SESSION_DATA 2
#define AC_SESSION_ACTION_NOTIFY_EVENT 3
/* */
struct ac_session_action {
@ -30,6 +32,21 @@ struct ac_session_action {
char data[0];
};
/* */
#define NOTIFY_ACTION_CHANGE_STATE 0
#define NOTIFY_ACTION_RECEIVE_REQUEST_MESSAGEELEMENT 1
#define NOTIFY_ACTION_RECEIVE_RESPONSE_MESSAGEELEMENT 1
struct ac_session_notify_event_t {
char idevent[65];
int action;
union {
unsigned long session_state;
uint16_t message_element_type;
};
};
/* */
struct ac_session_t;
struct ac_session_data_t;
@ -95,6 +112,8 @@ struct ac_session_t {
struct capwap_list* action;
struct capwap_list* packets;
struct capwap_list* notifyevent;
unsigned char localseqnumber;
unsigned char remoteseqnumber;
unsigned short fragmentid;
@ -165,5 +184,6 @@ struct ac_soap_response* ac_session_send_soap_request(struct ac_session_t* sessi
#define ac_soap_runningwtpsession(s, wtpid) ac_session_send_soap_request((s), "runningWTPSession", 1, "xs:string", "idwtp", wtpid)
#define ac_soap_teardownwtpsession(s, wtpid) ac_session_send_soap_request((s), "teardownWTPSession", 1, "xs:string", "idwtp", wtpid)
#define ac_soap_checkwtpsession(s, wtpid) ac_session_send_soap_request((s), "checkWTPSession", 1, "xs:string", "idwtp", wtpid)
#define ac_soap_updatebackendevent(s, idevent, status) ac_session_send_soap_request((s), "updateBackendEvent", 2, "xs:string", "idevent", idevent, "xs:int", "status", status)
#endif /* __AC_SESSION_HEADER__ */

View File

@ -81,7 +81,7 @@
</wsdl:message>
<wsdl:message name="updateBackendEvent">
<wsdl:part name="idsession" type="xs:string"/>
<wsdl:part name="idevent" type="xs:int"/>
<wsdl:part name="idevent" type="xs:string"/>
<wsdl:part name="status" type="xs:int"/>
</wsdl:message>
<wsdl:message name="updateBackendEventResponse"/>