//close the ".ini" file void close_ini(ini_file_t **ini_file) { ini_file_t *doc = *ini_file; ini_selection_t *sec_tmp = NULL; ini_comment_t *comm_tmp = NULL; ini_item_t *item_tmp = NULL; if((NULL == ini_file) || (NULL == doc)) { return; } if(doc->selections) { while(NULL != doc->selections) { sec_tmp = doc->selections; doc->selections = doc->selections->next; while(NULL != sec_tmp->comments) { comm_tmp = sec_tmp->comments; sec_tmp->comments = sec_tmp->comments->next; gn_free((void**)(&(comm_tmp->desc))); gn_free((void**)(&comm_tmp)); } while(NULL != sec_tmp->ini_items) { item_tmp = sec_tmp->ini_items; sec_tmp->ini_items = sec_tmp->ini_items->next; while(NULL != item_tmp->comments) { comm_tmp = item_tmp->comments; item_tmp->comments = item_tmp->comments->next; gn_free((void**)(&(comm_tmp->desc))); gn_free((void**)(&comm_tmp)); } gn_free((void**)(&(item_tmp->name))); gn_free((void**)(&(item_tmp->value))); gn_free((void**)(&item_tmp)); } gn_free((void**)(&(sec_tmp->selection))); gn_free((void**)(&sec_tmp)); } } fclose(doc->fd); gn_free((void**)ini_file); *ini_file = NULL; }
void free_selections(ini_selection_t* selection_p) { ini_selection_t* sec_tmp = selection_p; ini_comment_t *comm_tmp = NULL; ini_item_t *item_tmp = NULL; if(NULL == sec_tmp) { return ; } while(NULL != sec_tmp->ini_items) { item_tmp = sec_tmp->ini_items; sec_tmp->ini_items = sec_tmp->ini_items->next; while(NULL != item_tmp->comments) { comm_tmp = item_tmp->comments; item_tmp->comments = item_tmp->comments->next; gn_free((void**)(&(comm_tmp->desc))); gn_free((void**)(&comm_tmp)); } gn_free((void**)(&(item_tmp->name))); gn_free((void**)(&(item_tmp->value))); gn_free((void**)(&item_tmp)); } gn_free((void**)(&(sec_tmp->selection))); gn_free((void**)(&sec_tmp)); }
static int answer_to_connection(void *cls, struct MHD_Connection *connection, const INT1 *url, const char *method, const INT1 *version, const INT1 *upload_data, size_t *upload_data_size, void **con_cls) { INT4 ret = 0; UINT4 idx = 0; if (NULL == *con_cls) { struct connection_info *conn_info = (struct connection_info *)gn_malloc(sizeof(struct connection_info)); if(NULL == conn_info) { return MHD_NO; } conn_info->connection_time = g_cur_sys_time.tv_sec; *con_cls = (void *)conn_info; return MHD_YES; } if (0 == strcmp(method, "GET")) { LOG_PROC("INFO", "Restful[%s]: [%s]", method, url); g_rest_reply = proc_rest_msg(method, url, upload_data); //todo ÅÐ¿Õ ret = send_page(connection, g_rest_reply, MHD_HTTP_OK); //»Ø¸´ÏûÏ¢ memset((char *) upload_data, 0x0, *upload_data_size); //Çå¿Õ»º³åÇø *upload_data_size = 0; upload_data = NULL; free(g_rest_reply); return ret; } if (0 == strcmp(method, "POST") || 0 == strcmp(method, "DELETE") || 0 == strcmp(method, "PUT") || 0 == strcmp(method, "PATCH") || 0 == strcmp(method, "HEAD")) { struct connection_info *conn_info = *con_cls; conn_info->connection_type = HTTP_POST; if (*upload_data_size) { if(is_json(upload_data, *upload_data_size)) { INT1 *tmp = (char*) upload_data; for (idx = *upload_data_size; idx > 0; --idx) { if ('}' == tmp[idx]) { tmp[idx + 1] = '\0'; break; } } LOG_PROC("INFO", "Restful[%s]: [%s] %s\n", method, url, upload_data); g_rest_reply = proc_rest_msg(method, url, upload_data); memset((char *) upload_data, 0x0, *upload_data_size); //Çå¿Õ»º³åÇø *upload_data_size = 0; } else { if(conn_info->connection_time - g_cur_sys_time.tv_sec > HTTP_TIMEOUT) { memset((char *) upload_data, 0x0, *upload_data_size); //Çå¿Õ»º³åÇø *upload_data_size = 0; return MHD_NO; } } return MHD_YES; } else { ret = send_page(connection, g_rest_reply, MHD_HTTP_OK); memset((char *) upload_data, 0x0, *upload_data_size); //Çå¿Õ»º³åÇø *upload_data_size = 0; upload_data = NULL; gn_free((void **)&g_rest_reply); return ret; } } return ret; }