Cleaning code

This commit is contained in:
vemax78 2013-12-01 22:50:33 +01:00
parent b2b18fec33
commit e02815f576

View File

@ -36,7 +36,7 @@ static struct ac_backend_t g_ac_backend;
static int ac_backend_parsing_closewtpsession_event(const char* idevent, struct json_object* jsonparams) { static int ac_backend_parsing_closewtpsession_event(const char* idevent, struct json_object* jsonparams) {
int result = 0; int result = 0;
struct ac_session_t* session; struct ac_session_t* session;
struct json_object* jsonvalue; struct json_object* jsonwtpid;
/* Params CloseWTPSession Action /* Params CloseWTPSession Action
{ {
@ -44,30 +44,30 @@ static int ac_backend_parsing_closewtpsession_event(const char* idevent, struct
} }
*/ */
/* Get WTPId */ /* WTPId */
jsonvalue = json_object_object_get(jsonparams, "WTPId"); jsonwtpid = json_object_object_get(jsonparams, "WTPId");
if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_string)) { if (!jsonwtpid || (json_object_get_type(jsonwtpid) != json_type_string)) {
const char* wtpid = json_object_get_string(jsonvalue); return 0;
}
/* Get session */ /* Get session */
session = ac_search_session_from_wtpid(wtpid); session = ac_search_session_from_wtpid(json_object_get_string(jsonwtpid));
if (session) { if (session) {
struct ac_session_notify_event_t notify; struct ac_session_notify_event_t notify;
/* Notify Request to Complete Event */ /* Notify Request to Complete Event */
strcpy(notify.idevent, idevent); strcpy(notify.idevent, idevent);
notify.action = NOTIFY_ACTION_CHANGE_STATE; notify.action = NOTIFY_ACTION_CHANGE_STATE;
notify.session_state = CAPWAP_DEAD_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)); ac_session_send_action(session, AC_SESSION_ACTION_NOTIFY_EVENT, 0, (void*)&notify, sizeof(struct ac_session_notify_event_t));
/* */ /* Async close session */
capwap_logging_debug("Receive close wtp session for WTP %s", session->wtpid); capwap_logging_debug("Receive close wtp session for WTP %s", session->wtpid);
ac_session_send_action(session, AC_SESSION_ACTION_CLOSE, 0, NULL, 0);
/* Async close session */ /* */
ac_session_send_action(session, AC_SESSION_ACTION_CLOSE, 0, NULL, 0); ac_session_release_reference(session);
ac_session_release_reference(session); result = 1;
result = 1;
}
} }
return result; return result;
@ -77,7 +77,7 @@ static int ac_backend_parsing_closewtpsession_event(const char* idevent, struct
static int ac_backend_parsing_resetwtp_event(const char* idevent, struct json_object* jsonparams) { static int ac_backend_parsing_resetwtp_event(const char* idevent, struct json_object* jsonparams) {
int result = 0; int result = 0;
struct ac_session_t* session; struct ac_session_t* session;
struct json_object* jsonvalue; struct json_object* jsonwtpid;
struct json_object* jsonimage; struct json_object* jsonimage;
struct json_object* jsonvendor; struct json_object* jsonvendor;
struct json_object* jsondata; struct json_object* jsondata;
@ -92,52 +92,57 @@ static int ac_backend_parsing_resetwtp_event(const char* idevent, struct json_ob
} }
*/ */
/* Get WTPId */ /* WTPId */
jsonvalue = json_object_object_get(jsonparams, "WTPId"); jsonwtpid = json_object_object_get(jsonparams, "WTPId");
if (jsonvalue && (json_object_get_type(jsonvalue) == json_type_string)) { if (!jsonwtpid || (json_object_get_type(jsonwtpid) != json_type_string)) {
/* Get session */ return 0;
session = ac_search_session_from_wtpid(json_object_get_string(jsonvalue)); }
if (session) {
/* Get ImageIdentifier */
jsonimage = json_object_object_get(jsonparams, "ImageIdentifier");
if (jsonimage && (json_object_get_type(jsonimage) == json_type_object)) {
jsonvendor = json_object_object_get(jsonimage, "Vendor");
jsondata = json_object_object_get(jsonimage, "Data");
if (jsonvendor && jsondata && (json_object_get_type(jsonvendor) == json_type_int) && (json_object_get_type(jsondata) == json_type_string)) { /* ImageIdentifier */
const char* name = json_object_get_string(jsondata); jsonimage = json_object_object_get(jsonparams, "ImageIdentifier");
if (name && *name) { if (!jsonimage || (json_object_get_type(jsonimage) != json_type_object)) {
int length; return 0;
struct ac_notify_reset_t* reset; }
struct ac_session_notify_event_t notify;
/* Notification data */ jsonvendor = json_object_object_get(jsonimage, "Vendor");
length = sizeof(struct ac_notify_reset_t) + strlen(name) + 1; jsondata = json_object_object_get(jsonimage, "Data");
reset = (struct ac_notify_reset_t*)capwap_alloc(length); if (!jsonvendor || !jsondata || (json_object_get_type(jsonvendor) != json_type_int) || (json_object_get_type(jsondata) != json_type_string)) {
return 0;
}
/* */ /* Get session */
reset->vendor = (uint32_t)json_object_get_int(jsonvendor); session = ac_search_session_from_wtpid(json_object_get_string(jsonwtpid));
strcpy((char*)reset->name, name); if (session) {
const char* name = json_object_get_string(jsondata);
if (name && *name) {
int length;
struct ac_notify_reset_t* reset;
struct ac_session_notify_event_t notify;
/* Notify Request to Complete Event */ /* Notification data */
strcpy(notify.idevent, idevent); length = sizeof(struct ac_notify_reset_t) + strlen(name) + 1;
notify.action = NOTIFY_ACTION_CHANGE_STATE; reset = (struct ac_notify_reset_t*)capwap_alloc(length);
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); reset->vendor = (uint32_t)json_object_get_int(jsonvendor);
ac_session_send_action(session, AC_SESSION_ACTION_RESET_WTP, 0, (void*)reset, length); strcpy((char*)reset->name, name);
result = 1;
/* */ /* Notify Request to Complete Event */
capwap_free(reset); 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));
ac_session_release_reference(session); /* 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);
result = 1;
/* */
capwap_free(reset);
} }
ac_session_release_reference(session);
} }
return result; return result;