int epr_delete_selector(epr_t *epr, const char *name) { int i,k; int count; Selector *selectors; if(epr == NULL || name == NULL) return 0; count = epr->refparams.selectorset.count; selectors = epr->refparams.selectorset.selectors; for(i =0; i < count; i++) { if(strcmp(name, selectors[i].name) == 0) break; } if(i == count) return -1; u_free(selectors[i].name); if(selectors[i].type == 0) { u_free(selectors[i].value); } else { epr_destroy((epr_t *)selectors[i].value); } for(k = i; k < count-1; k++) { memcpy(&selectors[k], &selectors[k+1], sizeof(Selector)); } epr->refparams.selectorset.selectors = u_realloc(selectors, (count-1)*sizeof(Selector)); epr->refparams.selectorset.count--; return 0; }
int WsManTest_EventPoll_EP(WsEventThreadContextH threadcntx) { int retval = 0; WsNotificationInfoH notificationinfo = u_malloc(sizeof(*notificationinfo)); if(notificationinfo == NULL) return -1; notificationinfo->headerOpaqueData = ws_xml_create_doc( XML_NS_OPENWSMAN"/test", "EventTopics"); WsXmlNodeH node = ws_xml_get_doc_root(notificationinfo->headerOpaqueData); if(node) { ws_xml_set_node_text(node, "openwsman.event.test"); } notificationinfo->EventAction = u_strdup(XML_NS_OPENWSMAN"/EventReport"); notificationinfo->EventContent = ws_xml_create_doc( XML_NS_OPENWSMAN"/test", "TestReport"); if(notificationinfo->EventContent == NULL) return retval; node = ws_xml_get_doc_root(notificationinfo->EventContent); time_t timest = time(0); struct tm tm; localtime_r(×t, &tm); ws_xml_add_child_format(node, XML_NS_OPENWSMAN"/test", "EventTime","%u-%u%u-%u%uT%u%u:%u%u:%u%u", tm.tm_year + 1900, (tm.tm_mon + 1)/10, (tm.tm_mon + 1)%10, tm.tm_mday/10, tm.tm_mday%10, tm.tm_hour/10, tm.tm_hour%10, tm.tm_min/10, tm.tm_min%10, tm.tm_sec/10, tm.tm_sec%10); EventPoolOpSetH opset = threadcntx->soap->eventpoolOpSet; if(threadcntx->subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL) retval = opset->addpull(threadcntx->subsInfo->subsId, notificationinfo); else retval = opset->add(threadcntx->subsInfo->subsId, notificationinfo); if(retval) { u_free(notificationinfo->EventAction); ws_xml_destroy_doc(notificationinfo->EventContent); ws_xml_destroy_doc(notificationinfo->headerOpaqueData); u_free(notificationinfo); } return 0; }
/* * Class: sunw_util_AZJni_SendStringClass * Method: sendString * Signature: (Ljava/lang/String;Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_sunw_util_AZJni_00024SendStringClass_sendString (JNIEnv* env, jclass, jstring nameWindow, jstring chars) { DbgMsg("Enter from java"); char* nameWindow2 = ToAnsi( (WCHAR*)env->GetStringChars( nameWindow, NULL ) ); char* chars2 = ToAnsi( (WCHAR*)env->GetStringChars( chars, NULL ) ); SendKeys( nameWindow2, chars2 ); u_free(nameWindow2); u_free(chars2); }
void mystruct_free (void *val) { mystruct_t *mystruct = (mystruct_t *) val; if (val == NULL) return; u_free(mystruct->a); u_free(mystruct->b); u_free(mystruct); }
/** * \brief Free a buffer * * Release all resources and free the given buffer object. * * \param ubuf buffer object * * \return \c 0 on success, not zero on failure */ int u_buf_free(u_buf_t *ubuf) { dbg_err_if(ubuf == NULL); if(ubuf->data) u_free(ubuf->data); u_free(ubuf); return 0; err: return ~0; }
char *epr_to_string(epr_t *epr) { int i, len; char *buf, *ptr; Selector *p = NULL; if (epr == NULL) return NULL; /* calculate buffer size */ len = strlen(epr->refparams.uri); p = epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { len += (strlen(p->name) + 1); /* (?|&)key */ if (p->type == 0) len += (strlen(p->value) + 1); /* =value */ else { char *value = epr_to_string((epr_t *)p->value); if (value) { len += (strlen(value) + 1); /* =value */ u_free(value); } } p++; } buf = u_malloc(len + 1); strcpy(buf, epr->refparams.uri); ptr = buf + strlen(buf); p = epr->refparams.selectorset.selectors; for(i = 0; i < epr->refparams.selectorset.count; i++) { if (i == 0) *ptr++ = '?'; else *ptr++ = '&'; strcpy(ptr, p->name); ptr += strlen(p->name); *ptr++ = '='; if (p->type == 0) { strcpy(ptr, p->value); ptr += strlen(p->value); } else { char *value = epr_to_string((epr_t *)p->value); if (value) { strcpy(ptr, value); ptr += strlen(value); u_free(value); } } p++; } *ptr++ = 0; return buf; }
void key_value_destroy(key_value_t *kv, int part_of_array) { u_free(kv->key); if (kv->type == 0) u_free(kv->v.text); else epr_destroy(kv->v.epr); if (part_of_array == 0) { u_free(kv); } }
static int test_codec (u_test_case_t *tc) { size_t i; char *s = NULL; u_json_t *jo = NULL; const char *tv[] = { /* Empty object. */ "{ }", /* Empty array. */ "[ ]", /* Nesting. */ "[ { }, { }, [ [ ], { } ] ]", /* ASCII String. */ "{ \"ascii\": \"This is an ASCII string.\" }", /* UNICODE String. */ "{ \"unicode\": \"This is a \\uDEAD\\uBEEF.\" }", /* UTF-8 String. */ "{ \"utf8\": \"蘊\" }", /* Integer. */ "{ \"int\": 12439084123 }", /* Exp. */ "{ \"exp\": -12439084123E+1423 }", /* Frac. */ "{ \"frac\": 12439084123.999e-1423 }", /* Boolean. */ "[ true, false ]", /* Null. */ "{ \"NullMatrix\": [ [ null, null ], [ null, null ] ] }", NULL }; for (i = 0; tv[i] != NULL; i++) { u_test_err_if (u_json_decode(tv[i], &jo)); u_test_err_if (u_json_encode(jo, &s)); u_test_err_ifm (strcmp(s, tv[i]), "%s and %s differ !", tv[i], s); u_free(s), s = NULL; u_json_free(jo), jo = NULL; } return U_TEST_SUCCESS; err: if (s) u_free(s); if (jo) u_json_free(jo); return U_TEST_FAILURE; }
static int test_build_simple_object (u_test_case_t *tc) { char *s = NULL; u_json_t *root = NULL, *tmp = NULL; const char *ex = "{ \"num\": 999, \"string\": \".\", \"null\": null, \"bool\": true }"; /* { ... } */ u_test_err_if (u_json_new_object(NULL, &root)); /* "num": "999" */ u_test_err_if (u_json_new_int("num", 999, &tmp)); u_test_err_if (u_json_add(root, tmp)); tmp = NULL; /* "string": "." */ u_test_err_if (u_json_new_string("string", ".", &tmp)); u_test_err_if (u_json_add(root, tmp)); tmp = NULL; /* "null": null */ u_test_err_if (u_json_new_null("null", &tmp)); u_test_err_if (u_json_add(root, tmp)); tmp = NULL; /* "bool": true */ u_test_err_if (u_json_new_bool("bool", 1, &tmp)); u_test_err_if (u_json_add(root, tmp)); tmp = NULL; u_test_err_if (u_json_encode(root, &s)); u_test_err_ifm (strcmp(ex, s), "expecting \'%s\', got \'%s\'", ex, s); u_json_free(root); u_free(s); return U_TEST_SUCCESS; err: if (root) u_json_free(root); if (tmp) u_json_free(tmp); if (s) u_free(s); return U_TEST_FAILURE; }
static void debug_message_handler(const char *str, debug_level_e level, void *user_data) { if (log_pid == 0) log_pid = getpid(); if ( is_debug > 0) { struct tm *tm; time_t now; char timestr[128]; char *log_msg; //int p; time(&now); tm = localtime(&now); //strftime(timestr, 128, "%b %e %T", tm); log_msg = u_strdup_printf("%s [%d] %s\n", timestr, log_pid, str); //if ((p = // write(STDERR_FILENO, log_msg, strlen(log_msg))) < 0) // fprintf(stderr, "Failed writing to log file\n"); //fsync(STDERR_FILENO); u_free(log_msg); } }
static int print_events(WsXmlDocH indoc, void *data) { FILE *f = stdout; const char *filename = output_file; struct tm *tm; time_t now; char timestr[128]; char *log_msg; time(&now); tm = localtime(&now); // strftime(timestr, 128, "%b %e %T", tm); if (filename) { f = fopen(filename, "a+"); if (f == NULL) { error("Could not open file for writing"); return -1; } } if(f == stdout) log_msg = u_strdup_printf("\t\t\033[22;32mAt %s received:\033[m \n\n",timestr); else log_msg = u_strdup_printf("At %s received:\n\n", timestr); //fprintf(f, "%s", log_msg); // ws_xml_dump_node_tree(f, ws_xml_get_doc_root(indoc)); { WsXmlNodeH node; WsXmlNodeH class_node; char* class_name; int child_count; int i; node = ws_xml_get_soap_body (indoc); class_node = ws_xml_get_child (node, 0, NULL, NULL); class_name = ws_xml_get_node_local_name (class_node); printf ("\n%s\n", class_name); child_count = ws_xml_get_child_count (class_node); for (i = 0; i < child_count; i++) { WsXmlNodeH child_node; WsXmlAttrH attr; char* node_name; child_node = ws_xml_get_child (class_node, i, NULL, NULL); attr = ws_xml_get_node_attr (child_node, 0); node_name = ws_xml_get_attr_value (attr); printf ("%-25s - %s\n", ws_xml_get_node_local_name (child_node), ws_xml_get_node_text (child_node)); } } fflush(f); if (f != stdout) { fclose(f); } u_free(log_msg); return 0; }
static void accept_events_call(WsmanMessage *wsman_msg,char* ip_addr) { char *buf = NULL; char *messageid; int len; WsXmlDocH ackdoc = NULL; WsXmlDocH in_doc = wsman_build_inbound_envelope(wsman_msg); WsXmlNodeH header = ws_xml_get_soap_header(in_doc); WsXmlNodeH acknode = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_ACKREQUESTED); if(acknode) { ackdoc = ws_xml_create_envelope(); messageid = ws_xml_get_node_text(ws_xml_get_child(header, 0, XML_NS_ADDRESSING, WSA_MESSAGE_ID)); header = ws_xml_get_soap_header(ackdoc); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_TO, WSA_TO_ANONYMOUS); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_RELATES_TO, messageid); ws_xml_add_child(header, XML_NS_ADDRESSING, WSA_ACTION, WSMAN_ACTION_ACK); ws_xml_dump_memory_enc(ackdoc, &buf, &len, wsman_msg->charset); u_buf_set(wsman_msg->response, buf, len); ws_xml_destroy_doc(ackdoc); u_free(buf); } if(listener->eventf) listener->eventf(in_doc, listener->data,ip_addr); ws_xml_destroy_doc(in_doc); }
void wsman_get_fragment_type(char *fragstr, int *fragment_flag, char **element, int *index) { char *p, *p1, *p2, *dupstr; *fragment_flag = 0; *element = NULL; *index = 0; if(fragstr == NULL) return; dupstr = u_strdup(fragstr); p = strstr(dupstr, "/text()"); if(p) { *p = '\0'; *fragment_flag = 2; *element = u_strdup(dupstr); } else { if((p1 = strstr(dupstr, "[")) && (p2 = strstr(dupstr, "]"))) { *element = u_strndup(dupstr, p1 - dupstr); *p2 = '\0'; *index = atoi(p1+1); *fragment_flag = 3; } else { *element = u_strdup(dupstr); *fragment_flag = 1; } } u_free(dupstr); }
epr_t *epr_from_string(const char* str) { char *p; char *uri; hash_t *selectors; hash_t *selectors_new; hnode_t *hn; hscan_t hs; selector_entry *entry; epr_t *epr; p = strchr(str, '?'); uri = u_strndup(str, p - str); selectors = u_parse_query(p + 1); selectors_new = hash_create2(HASHCOUNT_T_MAX, 0, 0); hash_scan_begin(&hs, selectors); while ((hn = hash_scan_next(&hs))) { entry = u_malloc(sizeof(selector_entry)); entry->type = 0; entry->entry.text = (char *)hnode_get(hn); hash_alloc_insert(selectors_new, hnode_getkey(hn), entry); } epr = epr_create(uri, selectors_new, NULL); hash_free(selectors_new); hash_free(selectors); u_free(uri); return epr; }
/** * Destroy XML document * @param doc XML document */ void ws_xml_destroy_doc(WsXmlDocH doc) { if (doc) { xml_parser_destroy_doc(doc); u_free(doc); } }
static void identify_test(void) { WsXmlDocH response; static int i = 0; char *xp = NULL; wsmc_reinit_conn(cl); options = wsmc_options_init(); response = wsmc_action_identify(cl, options); CU_ASSERT_TRUE(wsmc_get_response_code(cl) == tests[i].final_status); CU_ASSERT_PTR_NOT_NULL(response); if (response == NULL) { goto RETURN; } if (tests[i].value1 != NULL) { xp = ws_xml_get_xpath_value(response, tests[i].expr1); CU_ASSERT_PTR_NOT_NULL(xp); if (xp) { CU_ASSERT_STRING_EQUAL(xp, tests[i].value1 ); } } RETURN: if (response) { ws_xml_destroy_doc(response); } u_free(xp); wsmc_options_destroy(options); i++; }
/** * Create XML document * @param soap SOAP handler * @param rootNsUri Root Namespace URI * @param rootName Root node name * @return XML document */ WsXmlDocH ws_xml_create_doc( const char *rootNsUri, const char *rootName) { WsXmlDocH wsDoc = (WsXmlDocH) u_zalloc(sizeof(*wsDoc)); WsXmlNodeH rootNode; WsXmlNsH ns; char prefix[12]; if (wsDoc == NULL) { error("No memory"); return NULL; } if (!xml_parser_create_doc(wsDoc, rootName) ) { error("xml_parser_create_doc failed"); u_free(wsDoc); return NULL; } if (rootNsUri == NULL) { return wsDoc; } rootNode = ws_xml_get_doc_root((WsXmlDocH) wsDoc); ws_xml_make_default_prefix(rootNode, rootNsUri, prefix, sizeof(prefix)); ns = xml_parser_ns_add(rootNode, rootNsUri, prefix); if (ns == NULL) { error("xml_parser_ns_add failed"); ws_xml_destroy_doc(wsDoc); return NULL; } ws_xml_set_node_name(rootNode, rootNsUri, NULL); return wsDoc; }
static void create_indication_event(WsXmlDocH indoc, WsSubscribeInfo *subsInfo, EventPoolOpSetH opset) { int count, i; int retval; WsNotificationInfoH notificationinfo = NULL; WsXmlNodeH node = ws_xml_get_doc_root(indoc); node = ws_xml_get_child(node, 0, NULL, CIMXML_MESSAGE); WsXmlNodeH tmp = ws_xml_get_child(node, 0, NULL, CIMXML_MULTIEXPREQ); if(tmp) { count = ws_xml_get_child_count(tmp); i = 0; while(i < count) { node = ws_xml_get_child(tmp, i, NULL, CIMXML_SIMPLEEXPREQ); notificationinfo = create_notification_entity(subsInfo, node); if(notificationinfo == NULL) { i++; continue; } if(subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL) retval = opset->addpull(subsInfo->subsId, notificationinfo); else retval = opset->add(subsInfo->subsId, notificationinfo); if(retval) { u_free(notificationinfo->EventAction); ws_xml_destroy_doc(notificationinfo->EventContent); u_free(notificationinfo); } i++; } } else { tmp = ws_xml_get_child(node, 0, NULL, CIMXML_SIMPLEEXPREQ); notificationinfo = create_notification_entity(subsInfo, tmp); if(subsInfo->deliveryMode == WS_EVENT_DELIVERY_MODE_PULL) retval = opset->addpull(subsInfo->subsId, notificationinfo); else retval = opset->add(subsInfo->subsId, notificationinfo); if(retval) { u_free(notificationinfo->EventAction); ws_xml_destroy_doc(notificationinfo->EventContent); u_free(notificationinfo); } } }
void wsmc_options_destroy(client_opt_t * op) { if (op->selectors) { hash_free(op->selectors); } if (op->properties) { hash_free(op->properties); } u_free(op->fragment); u_free(op->cim_ns); u_free(op->delivery_uri); u_free(op->reference); u_free(op); return; }
static void wsman_free_method_hnode(hnode_t * n, void *dummy) { if (strcmp(METHOD_ARGS_KEY, (char *)hnode_getkey(n)) == 0) { wsman_free_method_list((list_t *)hnode_get(n)); } u_free(n); }
static void enumeration_test(void) { char *enumContext = NULL; static int i = 0; char *selectors = NULL; wsmc_reinit_conn(cl); options = wsmc_options_init(); options->flags = tests[i].flags; if (tests[i].selectors) { selectors = u_strdup_printf(tests[i].selectors, host, host, host); wsmc_add_selectors_from_str(options, selectors); } options->max_elements = tests[i].max_elements; WsXmlDocH enum_response = wsmc_action_enumerate(cl, (char *)tests[i].resource_uri, options, NULL); CU_ASSERT_TRUE(wsmc_get_response_code(cl) == tests[i].final_status); if (wsmc_get_response_code(cl) != tests[i].final_status) { if (verbose) { printf("\nExpected = %d\nReturned = %ld ", tests[i].final_status, wsmc_get_response_code(cl)); } goto RETURN; } CU_ASSERT_PTR_NOT_NULL(enum_response); if (enum_response) { enumContext = wsmc_get_enum_context(enum_response); } else { goto RETURN; } check_response_header(enum_response, wsmc_get_response_code(cl), ENUM_ACTION_ENUMERATERESPONSE); //if (i==11) ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(enum_response)); handle_filters(enum_response, filters); handle_filters(enum_response, tests[i].common_filters); handle_filters(enum_response, tests[i].filters); RETURN: u_free(selectors); if (enumContext) { wsmc_action_release(cl, (char *)tests[i].resource_uri, options, enumContext); } if (enum_response) { ws_xml_destroy_doc(enum_response); } wsmc_options_destroy(options); i++; // decrease executed test number }
/** * \brief Free a buffer * * Release all resources and free the given buffer object. * * \param ubuf buffer object * * \retval 0 on success * \retval ~0 on error */ int u_buf_free (u_buf_t *ubuf) { dbg_return_if (ubuf == NULL, ~0); U_FREE(ubuf->data); u_free(ubuf); return 0; }
static int test_build_nested_object (u_test_case_t *tc) { int i; char *s = NULL; u_json_t *array = NULL, *root = NULL, *tmp = NULL; const char *ex = "{ \"array\": [ null, null, null ] }"; /* Nested array of null's. */ u_test_err_if (u_json_new_array("array", &array)); for (i= 0; i < 3 ; i++) { u_test_err_if (u_json_new_null(NULL, &tmp)); u_test_err_if (u_json_add(array, tmp)); tmp = NULL; } /* TODO add nested simple object. */ /* Top level container. */ u_test_err_if (u_json_new_object(NULL, &root)); u_test_err_if (u_json_add(root, array)); array = NULL; u_test_err_if (u_json_encode(root, &s)); u_test_err_ifm (strcmp(ex, s), "expecting \'%s\', got \'%s\'", ex, s); u_json_free(root); u_free(s); return U_TEST_SUCCESS; err: if (root) u_json_free(root); if (array) u_json_free(array); if (tmp) u_json_free(tmp); if (s) u_free(s); return U_TEST_FAILURE; }
static void destroy_node_private_data(void *_data) { iWsNode *data = (iWsNode *) _data; if (data) { // ??? TBD data->nsQNameList; if (data->valText) xmlFree(data->valText); u_free(data); } }
/** * \brief Free a string * * Release all resources allocated to the supplied ::u_string_t object \p s * * \param s the ::u_string_t object that will be destroyed * * \retval 0 always */ int u_string_free (u_string_t *s) { if (s) { if (s->data_sz) U_FREE(s->data); u_free(s); } return 0; }
int epr_add_selector_epr(epr_t *epr, const char *name, epr_t *added_epr) { int r; selector_entry *entry; entry = u_malloc(sizeof(selector_entry)); entry->type = 1; entry->entry.eprp = added_epr; r = epr_add_selector(epr, name, entry); u_free(entry); return r; }
int epr_add_selector_text(epr_t *epr, const char *name, const char *text) { int r; selector_entry *entry; entry = u_malloc(sizeof(selector_entry)); entry->type = 0; entry->entry.text = (char *)text; r = epr_add_selector(epr, name, entry); u_free(entry); return r; }
static void myXmlErrorReporting (void *ctx, const char* msg, ...) { va_list args; char *string; va_start(args, msg); string = u_strdup_vprintf (msg, args); warning (string); va_end(args); u_free(string); }
static void plugin_free(WsManPlugin *self) { message( "Un-loading plugins: %s", self->p_name ); if( self->p_handle && self->cleanup ) { (*self->cleanup)( self->p_handle, self->data ); } if(self->p_name) u_free(self->p_name); if( self->p_handle ) dlclose( self->p_handle ); }
void ec_resource_free(ec_res_t *res) { if (res) { ec_rep_t *rep; while ((rep = TAILQ_FIRST(&res->reps)) != NULL) (void) ec_rep_del(res, rep); u_free(res); } return; }