hash_t * wsman_get_selectors_from_epr(WsContextH cntx, WsXmlNodeH epr_node) { WsXmlNodeH selector, node, epr; selector_entry *sentry; int index = 0; hash_t *h = hash_create2(HASHCOUNT_T_MAX, 0, 0); node = ws_xml_get_child(epr_node, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET); if (!node) { debug("no SelectorSet defined"); hash_destroy(h); return NULL; } while ((selector = ws_xml_get_child(node, index++, XML_NS_WS_MAN, WSM_SELECTOR))) { char *attrVal = ws_xml_find_attr_value(selector, XML_NS_WS_MAN, WSM_NAME); if (attrVal == NULL) attrVal = ws_xml_find_attr_value(selector, NULL, WSM_NAME); if (attrVal && !hash_lookup(h, attrVal)) { sentry = u_malloc(sizeof(*sentry)); epr = ws_xml_get_child(selector, 0, XML_NS_ADDRESSING, WSA_EPR); if (epr) { debug("epr: %s", attrVal); sentry->type = 1; sentry->entry.eprp = epr_deserialize(selector, XML_NS_ADDRESSING, WSA_EPR, 1); if (!hash_alloc_insert(h, attrVal, sentry)) { error("hash_alloc_insert failed"); } } else { debug("text: %s", attrVal); sentry->type = 0; sentry->entry.text = ws_xml_get_node_text(selector); if (!hash_alloc_insert(h, attrVal, sentry)) { error("hash_alloc_insert failed"); } } } } if (!hash_isempty(h)) return h; hash_destroy(h); return NULL; }
static int section_add_pair( CamConfigSection *section, char *key, char *value ) { char *keydup, *valdup; hnode_t *hnode; if( (hnode = hash_lookup( section->entryhash, key )) != NULL ){ if( (valdup = strdup( value )) == NULL ) return -1; /* Replacing an existing value */ free( hnode_get( hnode ) ); hnode_put( hnode, valdup ); return 0; } if( (keydup = strdup( key )) == NULL ) return -1; if( (valdup = strdup( value )) == NULL ){ free( keydup ); return -1; } if( !hash_alloc_insert( section->entryhash, keydup, valdup )){ free( keydup ); free( valdup ); return -1; } return 0; }
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; }
CP_C_API cp_status_t cp_define_symbol(cp_context_t *context, const char *name, void *ptr) { cp_status_t status = CP_OK; CHECK_NOT_NULL(context); CHECK_NOT_NULL(name); CHECK_NOT_NULL(ptr); if (context->plugin == NULL) { cpi_fatalf(_("Only plug-ins can define context specific symbols.")); } cpi_lock_context(context); cpi_check_invocation(context, CPI_CF_LOGGER | CPI_CF_LISTENER, __func__); do { char *n; // Create a symbol hash if necessary if (context->plugin->defined_symbols == NULL) { if ((context->plugin->defined_symbols = hash_create(HASHCOUNT_T_MAX, (int (*)(const void *, const void *)) strcmp, NULL)) == NULL) { status = CP_ERR_RESOURCE; break; } } // Check for a previously defined symbol if (hash_lookup(context->plugin->defined_symbols, name) != NULL) { status = CP_ERR_CONFLICT; break; } // Insert the symbol into the symbol hash n = strdup(name); if (n == NULL || !hash_alloc_insert(context->plugin->defined_symbols, n, ptr)) { free(n); status = CP_ERR_RESOURCE; break; } } while (0); // Report error if (status != CP_OK) { switch (status) { case CP_ERR_RESOURCE: cpi_errorf(context, N_("Plug-in %s could not define symbol %s due to insufficient memory."), context->plugin->plugin->identifier, name); break; case CP_ERR_CONFLICT: cpi_errorf(context, N_("Plug-in %s tried to redefine symbol %s."), context->plugin->plugin->identifier, name); break; default: break; } } cpi_unlock_context(context); return status; }
static void ekhtml_parser_startendcb_add(ekhtml_parser_t *parser, const char *tag, ekhtml_starttag_cb_t startcb, ekhtml_endtag_cb_t endcb, int isStart) { ekhtml_tag_container *cont; ekhtml_string_t lookup_str; char *newtag, *cp; unsigned int taglen; hnode_t *hn; if(!tag){ if(isStart) parser->startcb_unk = startcb; else parser->endcb_unk = endcb; return; } newtag = strdup(tag); for(cp=newtag; *cp; cp++) *cp = toupper(*cp); taglen = cp - newtag; /* First see if the container already exists */ lookup_str.str = newtag; lookup_str.len = taglen; if((hn = hash_lookup(parser->startendcb, &lookup_str))){ cont = hnode_get(hn); free(newtag); if(isStart) cont->startfunc = startcb; else cont->endfunc = endcb; } else { ekhtml_string_t *set_str; cont = malloc(sizeof(*cont)); if(isStart){ cont->startfunc = startcb; cont->endfunc = NULL; } else { cont->startfunc = NULL; cont->endfunc = endcb; } set_str = malloc(sizeof(*set_str)); *set_str = lookup_str; hash_alloc_insert(parser->startendcb, set_str, cont); } }
/* add key,value VALUE pair to hash_t* * (used as callback for value2hash) */ static int add_i( VALUE key, VALUE value, hash_t *h ) { if (key != Qundef) { const char *k = as_string( key ); const char *v = as_string( value ); if (!hash_lookup( h, k ) ) { if ( !hash_alloc_insert( h, k, v ) ) { rb_raise( rb_eException, "hash_alloc_insert failed" ); } } } return 0; }
static int check_for_duplicate_selectors(op_t * op) { WsXmlNodeH header, node, selector; int retval = 0, index = 0; hash_t *h; header = wsman_get_soap_header_element( op->in_doc, NULL, NULL); if ((node = ws_xml_get_child(header, 0, XML_NS_WS_MAN, WSM_SELECTOR_SET)) == NULL) { // No selectors return 0; } h = hash_create(HASHCOUNT_T_MAX, 0, 0); if (h == NULL) { generate_op_fault(op, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS); error("could not create hash"); return 1; } while ((selector = ws_xml_get_child(node, index++, XML_NS_WS_MAN, WSM_SELECTOR))) { char *attrVal = ws_xml_find_attr_value(selector, NULL, WSM_NAME); if (!attrVal) continue; if (hash_lookup(h, attrVal)) { generate_op_fault(op, WSMAN_INVALID_SELECTORS, WSMAN_DETAIL_DUPLICATE_SELECTORS); debug("Selector %s duplicated", attrVal); retval = 1; break; } if (!hash_alloc_insert(h, attrVal, ws_xml_get_node_text(selector))) { generate_op_fault(op, WSMAN_INTERNAL_ERROR, OWSMAN_NO_DETAILS); retval = 1; error("hash_alloc_insert failed"); break; } } hash_free_nodes(h); hash_destroy(h); return retval; }
void wsmc_add_selector(client_opt_t * options, const char *key, const char *value) { if (options->selectors == NULL) options->selectors = hash_create(HASHCOUNT_T_MAX, 0, 0); if (!hash_lookup(options->selectors, key)) { if (!hash_alloc_insert(options->selectors, (char *)key, (char *)value)) { error( "hash_alloc_insert failed"); } } else { error( "duplicate not added to hash"); } }
/** * The caller owns the key, and this function will duplicate it * if needed. This function owns the value and will destroy it * if there's an error. */ void Request_set(Request *req, bstring key, bstring val, int replace) { hnode_t *n = hash_lookup(req->headers, key); struct bstrList *val_list = NULL; int rc = 0; int i = 0; if(n == NULL) { // make a new bstring list to use as our storage val_list = bstrListCreate(); rc = bstrListAlloc(val_list, MAX_DUPE_HEADERS); check(rc == BSTR_OK, "Couldn't allocate space for header values."); val_list->entry[0] = val; val_list->qty = 1; hash_alloc_insert(req->headers, bstrcpy(key), val_list); } else { val_list = hnode_get(n); check(val_list != NULL, "Malformed request, missing bstrlist in node. Tell Zed: %s=%s", bdata(key), bdata(val)); if(replace) { // destroy ALL old ones and put this in their place for(i = 0; i < val_list->qty; i++) { bdestroy(val_list->entry[i]); } val_list->entry[0] = val; val_list->qty = 1; } else { check(val_list->qty < MAX_DUPE_HEADERS, "Header %s duplicated more than %d times allowed.", bdata(key), MAX_DUPE_HEADERS); val_list->entry[val_list->qty++] = val; } } return; error: bdestroy(val); return; }
static int add_to_hash(hash_t *hash, bstring key, bstring val) { struct bstrList *val_list = NULL; int rc = 0; // make a new bstring list to use as our storage val_list = bstrListCreate(); rc = bstrListAlloc(val_list, 1); check(rc == BSTR_OK, "Couldn't allocate space in hash."); val_list->entry[0] = val; val_list->qty = 1; hash_alloc_insert(hash, bstrcpy(key), val_list); return 0; error: return -1; }
void Register_connect(int fd, int conn_type) { assert(registrations && "Call Register_init."); debug("Registering %d ident.", fd); hnode_t *hn = hash_lookup(registrations, (void *)(intptr_t)fd); if(hn) hash_delete_free(registrations, hn); check(hash_alloc_insert(registrations, (void *)(intptr_t)fd, (void *)(intptr_t)conn_type), "Cannot register fd, out of space."); debug("Currently registered idents: %d", (int)hash_count(registrations)); return; error: taskexitall(1); }
/** * Associates the composed state <code>nS</code> with its source states * <code>nSX</code> (left operand) and <code>nSY</code> (right operand) and * with its epsilon filter mode <code>nFlagXY</code>. * * @param _this Pointer to composed (destination) automaton instance * @param nS Unit relative composed (destination) state index * @param nSX Unit relative source state index in left operand (<code>itSrc1</code>) * @param nSY Unit relative source state index in right operand (<code>itSrc2</code>) * @param nFlagXY Epsilon filter mode, one of the <code>CPS_EFLT_XXX</code> constants * @see Cps_FindState CFst_Cps_FindState * @see Cps_AddSdAux CFst_Cps_AddSdAux * @see Cps_DelSdAux CFst_Cps_DelSdAux */ void CGEN_PRIVATE CFst_Cps_SetSdAux ( CFst* _this, FST_ITYPE nS, FST_ITYPE nSX, FST_ITYPE nSY, BYTE nFlagXY ) { IFCHECKEX(2) printf("\n nS=%ld: Set [X=%ld, Y=%ld, Flg=%d]",(long)nS,(long)nSX,(long)nSY,(int)nFlagXY); /* Store state's auxiliary info */ /* TODO: replace by SD_SX, SD_SY and SD_FLAGYX macros */ *(FST_ITYPE*)(CData_XAddr(AS(CData,_this->sd),nS,_this->m_nIcSdAux )) = nSX; *(FST_ITYPE*)(CData_XAddr(AS(CData,_this->sd),nS,_this->m_nIcSdAux+1)) = nSY; *(BYTE* )(CData_XAddr(AS(CData,_this->sd),nS,_this->m_nIcSdAux+2)) = nFlagXY; /* Insert state into state hashmap for reverse lookup */ hash_alloc_insert((hash_t*)_this->m_lpCpsHash,(void*)(long)nS,(void*)(long)nS); }
CP_C_API cp_status_t cp_register_ploader(cp_context_t *ctx, cp_plugin_loader_t *loader) { cp_status_t status = CP_OK; hash_t *loader_plugins = NULL; CHECK_NOT_NULL(ctx); CHECK_NOT_NULL(loader); cpi_lock_context(ctx); cpi_check_invocation(ctx, CPI_CF_ANY, __func__); do { if ((loader_plugins = hash_create(HASHCOUNT_T_MAX, (int (*)(const void *, const void *)) strcmp, NULL)) == NULL) { status = CP_ERR_RESOURCE; break; } if (!hash_alloc_insert(ctx->env->loaders_to_plugins, loader, loader_plugins)) { status = CP_ERR_RESOURCE; break; } } while (0); // Report error or success if (status != CP_OK) { cpi_errorf(ctx, N_("The plug-in loader %p could not be registered due to insufficient memory."), (void *) loader); } else { cpi_debugf(ctx, N_("The plug-in loader %p was registered."), (void *) loader); } cpi_unlock_context(ctx); // Release resources if (status != CP_OK) { if (loader_plugins != NULL) { assert(hash_isempty(loader_plugins)); hash_destroy(loader_plugins); } } return status; }
static inline void Command_option(Command *cmd, struct params *p) { bstring key = match_release(p, TKOPTION, 0); check(key, "Should have matched an option."); bstring value = NULL; int next = peek(p); if(next == TKOPTION || next == -1) { // simple true/false setting value = bfromcstr(""); } else { // it's not an option so it's some value we want value = match(p, next); } hash_alloc_insert(cmd->options, bdata(key), value); return; error: cmd->error = 1; return; }
CP_C_API void * cp_resolve_symbol(cp_context_t *context, const char *id, const char *name, cp_status_t *error) { cp_status_t status = CP_OK; int error_reported = 1; hnode_t *node; void *symbol = NULL; symbol_info_t *symbol_info = NULL; symbol_provider_info_t *provider_info = NULL; cp_plugin_t *pp = NULL; CHECK_NOT_NULL(context); CHECK_NOT_NULL(id); CHECK_NOT_NULL(name); // Resolve the symbol cpi_lock_context(context); cpi_check_invocation(context, CPI_CF_LOGGER | CPI_CF_LISTENER | CPI_CF_STOP, __func__); do { // Allocate space for symbol hashes, if necessary if (context->resolved_symbols == NULL) { context->resolved_symbols = hash_create(HASHCOUNT_T_MAX, cpi_comp_ptr, cpi_hashfunc_ptr); } if (context->symbol_providers == NULL) { context->symbol_providers = hash_create(HASHCOUNT_T_MAX, cpi_comp_ptr, cpi_hashfunc_ptr); } if (context->resolved_symbols == NULL || context->symbol_providers == NULL) { status = CP_ERR_RESOURCE; break; } // Look up the symbol defining plug-in node = hash_lookup(context->env->plugins, id); if (node == NULL) { cpi_warnf(context, N_("Symbol %s in unknown plug-in %s could not be resolved."), name, id); status = CP_ERR_UNKNOWN; break; } pp = hnode_get(node); // Make sure the plug-in has been started if ((status = cpi_start_plugin(context, pp)) != CP_OK) { printf("Symbol %s in plug-in %s could not be resolved because the plug-in could not be started.\n", name, id); cpi_errorf(context, N_("Symbol %s in plug-in %s could not be resolved because the plug-in could not be started."), name, id); error_reported = 1; break; } // Check for a context specific symbol if (pp->defined_symbols != NULL && (node = hash_lookup(pp->defined_symbols, name)) != NULL) { symbol = hnode_get(node); } // Fall back to global symbols, if necessary if (symbol == NULL && pp->runtime_lib != NULL) { symbol = DLSYM(pp->runtime_lib, name); } if (symbol == NULL) { const char *error = DLERROR(); if (error == NULL) { error = _("Unspecified error."); } cpi_warnf(context, N_("Symbol %s in plug-in %s could not be resolved: %s"), name, id, error); status = CP_ERR_UNKNOWN; break; } // Lookup or initialize symbol provider information if ((node = hash_lookup(context->symbol_providers, pp)) != NULL) { provider_info = hnode_get(node); } else { if ((provider_info = malloc(sizeof(symbol_provider_info_t))) == NULL) { status = CP_ERR_RESOURCE; break; } memset(provider_info, 0, sizeof(symbol_provider_info_t)); provider_info->plugin = pp; provider_info->imported = (context->plugin == NULL || cpi_ptrset_contains(context->plugin->imported, pp)); if (!hash_alloc_insert(context->symbol_providers, pp, provider_info)) { status = CP_ERR_RESOURCE; break; } } // Lookup or initialize symbol information if ((node = hash_lookup(context->resolved_symbols, symbol)) != NULL) { symbol_info = hnode_get(node); } else { if ((symbol_info = malloc(sizeof(symbol_info_t))) == NULL) { status = CP_ERR_RESOURCE; break; } memset(symbol_info, 0, sizeof(symbol_info_t)); symbol_info->provider_info = provider_info; if (!hash_alloc_insert(context->resolved_symbols, symbol, symbol_info)) { status = CP_ERR_RESOURCE; break; } } // Add dependencies (for plug-in) if (provider_info != NULL && !provider_info->imported && provider_info->usage_count == 0) { if (!cpi_ptrset_add(context->plugin->imported, pp)) { status = CP_ERR_RESOURCE; break; } if (!cpi_ptrset_add(pp->importing, context->plugin)) { cpi_ptrset_remove(context->plugin->imported, pp); status = CP_ERR_RESOURCE; break; } cpi_debugf(context, "A dynamic dependency was created from plug-in %s to plug-in %s.", context->plugin->plugin->identifier, pp->plugin->identifier); } // Increase usage counts symbol_info->usage_count++; provider_info->usage_count++; if (cpi_is_logged(context, CP_LOG_DEBUG)) { char owner[64]; /* TRANSLATORS: First %s is the context owner */ cpi_debugf(context, "%s resolved symbol %s defined by plug-in %s.", cpi_context_owner(context, owner, sizeof(owner)), name, id); } } while (0); // Clean up if (symbol_info != NULL && symbol_info->usage_count == 0) { if ((node = hash_lookup(context->resolved_symbols, symbol)) != NULL) { hash_delete_free(context->resolved_symbols, node); } free(symbol_info); } if (provider_info != NULL && provider_info->usage_count == 0) { if ((node = hash_lookup(context->symbol_providers, pp)) != NULL) { hash_delete_free(context->symbol_providers, node); } free(provider_info); } // Report insufficient memory error if (status == CP_ERR_RESOURCE && !error_reported) { cpi_errorf(context, N_("Symbol %s in plug-in %s could not be resolved due to insufficient memory."), name, id); } cpi_unlock_context(context); // Return error code if (error != NULL) { *error = status; } // Return symbol return symbol; }
CP_C_API cp_status_t cp_scan_plugins(cp_context_t *context, int flags) { hash_t *avail_plugins = NULL; list_t *started_plugins = NULL; cp_plugin_info_t **plugins = NULL; char *pdir_path = NULL; int pdir_path_size = 0; int plugins_stopped = 0; cp_status_t status = CP_OK; CHECK_NOT_NULL(context); cpi_lock_context(context); cpi_check_invocation(context, CPI_CF_ANY, __func__); cpi_debug(context, N_("Plug-in scan is starting.")); do { lnode_t *lnode; hscan_t hscan; hnode_t *hnode; // Create a hash for available plug-ins if ((avail_plugins = hash_create(HASHCOUNT_T_MAX, (int (*)(const void *, const void *)) strcmp, NULL)) == NULL) { status = CP_ERR_RESOURCE; break; } // Scan plug-in directories for available plug-ins lnode = list_first(context->env->plugin_dirs); while (lnode != NULL) { const char *dir_path; DIR *dir; dir_path = lnode_get(lnode); dir = opendir(dir_path); if (dir != NULL) { int dir_path_len; struct dirent *de; dir_path_len = strlen(dir_path); if (dir_path[dir_path_len - 1] == CP_FNAMESEP_CHAR) { dir_path_len--; } errno = 0; while ((de = readdir(dir)) != NULL) { if (de->d_name[0] != '\0' && de->d_name[0] != '.') { int pdir_path_len = dir_path_len + 1 + strlen(de->d_name) + 1; cp_plugin_info_t *plugin; cp_status_t s; hnode_t *hnode; // Allocate memory for plug-in descriptor path if (pdir_path_size <= pdir_path_len) { char *new_pdir_path; if (pdir_path_size == 0) { pdir_path_size = 128; } while (pdir_path_size <= pdir_path_len) { pdir_path_size *= 2; } new_pdir_path = realloc(pdir_path, pdir_path_size * sizeof(char)); if (new_pdir_path == NULL) { cpi_errorf(context, N_("Could not check possible plug-in location %s%c%s due to insufficient system resources."), dir_path, CP_FNAMESEP_CHAR, de->d_name); status = CP_ERR_RESOURCE; // continue loading plug-ins from other directories continue; } pdir_path = new_pdir_path; } // Construct plug-in descriptor path strcpy(pdir_path, dir_path); pdir_path[dir_path_len] = CP_FNAMESEP_CHAR; strcpy(pdir_path + dir_path_len + 1, de->d_name); // Try to load a plug-in plugin = cp_load_plugin_descriptor(context, pdir_path, &s); if (plugin == NULL) { status = s; // continue loading plug-ins from other directories continue; } // Insert plug-in to the list of available plug-ins if ((hnode = hash_lookup(avail_plugins, plugin->identifier)) != NULL) { cp_plugin_info_t *plugin2 = hnode_get(hnode); if (cpi_vercmp(plugin->version, plugin2->version) > 0) { hash_delete_free(avail_plugins, hnode); cp_release_info(context, plugin2); hnode = NULL; } } if (hnode == NULL) { if (!hash_alloc_insert(avail_plugins, plugin->identifier, plugin)) { cpi_errorf(context, N_("Plug-in %s version %s could not be loaded due to insufficient system resources."), plugin->identifier, plugin->version); cp_release_info(context, plugin); status = CP_ERR_RESOURCE; // continue loading plug-ins from other directories continue; } } } errno = 0; } if (errno) { cpi_errorf(context, N_("Could not read plug-in directory %s: %s"), dir_path, strerror(errno)); status = CP_ERR_IO; // continue loading plug-ins from other directories } closedir(dir); } else { cpi_errorf(context, N_("Could not open plug-in directory %s: %s"), dir_path, strerror(errno)); status = CP_ERR_IO; // continue loading plug-ins from other directories } lnode = list_next(context->env->plugin_dirs, lnode); } // Copy the list of started plug-ins, if necessary if ((flags & CP_SP_RESTART_ACTIVE) && (flags & (CP_SP_UPGRADE | CP_SP_STOP_ALL_ON_INSTALL))) { int i; cp_status_t s; if ((plugins = cp_get_plugins_info(context, &s, NULL)) == NULL) { status = s; break; } if ((started_plugins = list_create(LISTCOUNT_T_MAX)) == NULL) { status = CP_ERR_RESOURCE; break; } for (i = 0; plugins[i] != NULL; i++) { cp_plugin_state_t state; state = cp_get_plugin_state(context, plugins[i]->identifier); if (state == CP_PLUGIN_STARTING || state == CP_PLUGIN_ACTIVE) { char *pid; if ((pid = strdup(plugins[i]->identifier)) == NULL) { status = CP_ERR_RESOURCE; break; } if ((lnode = lnode_create(pid)) == NULL) { free(pid); status = CP_ERR_RESOURCE; break; } list_append(started_plugins, lnode); } } cpi_release_info(context, plugins); plugins = NULL; } // Install/upgrade plug-ins hash_scan_begin(&hscan, avail_plugins); while ((hnode = hash_scan_next(&hscan)) != NULL) { cp_plugin_info_t *plugin; cp_plugin_t *ip = NULL; hnode_t *hn2; int s; plugin = hnode_get(hnode); hn2 = hash_lookup(context->env->plugins, plugin->identifier); if (hn2 != NULL) { ip = hnode_get(hn2); } // Unload the installed plug-in if it is to be upgraded if (ip != NULL && (flags & CP_SP_UPGRADE) && ((ip->plugin->version == NULL && plugin->version != NULL) || (ip->plugin->version != NULL && plugin->version != NULL && cpi_vercmp(plugin->version, ip->plugin->version) > 0))) { if ((flags & (CP_SP_STOP_ALL_ON_UPGRADE | CP_SP_STOP_ALL_ON_INSTALL)) && !plugins_stopped) { plugins_stopped = 1; cp_stop_plugins(context); } s = cp_uninstall_plugin(context, plugin->identifier); assert(s == CP_OK); ip = NULL; } // Install the plug-in, if to be installed if (ip == NULL) { if ((flags & CP_SP_STOP_ALL_ON_INSTALL) && !plugins_stopped) { plugins_stopped = 1; cp_stop_plugins(context); } if ((s = cp_install_plugin(context, plugin)) != CP_OK) { status = s; break; } } // Remove the plug-in from the hash hash_scan_delfree(avail_plugins, hnode); cp_release_info(context, plugin); } // Restart stopped plug-ins if necessary if (started_plugins != NULL) { lnode = list_first(started_plugins); while (lnode != NULL) { char *pid; int s; pid = lnode_get(lnode); s = cp_start_plugin(context, pid); if (s != CP_OK) { status = s; } lnode = list_next(started_plugins, lnode); } } } while (0); // Report error switch (status) { case CP_OK: cpi_debug(context, N_("Plug-in scan has completed successfully.")); break; case CP_ERR_RESOURCE: cpi_error(context, N_("Could not scan plug-ins due to insufficient system resources.")); break; default: cpi_error(context, N_("Could not scan plug-ins.")); break; } cpi_unlock_context(context); // Release resources if (pdir_path != NULL) { free(pdir_path); } if (avail_plugins != NULL) { hscan_t hscan; hnode_t *hnode; hash_scan_begin(&hscan, avail_plugins); while ((hnode = hash_scan_next(&hscan)) != NULL) { cp_plugin_info_t *p = hnode_get(hnode); hash_scan_delfree(avail_plugins, hnode); cp_release_info(context, p); } hash_destroy(avail_plugins); } if (started_plugins != NULL) { list_process(started_plugins, NULL, cpi_process_free_ptr); list_destroy(started_plugins); } if (plugins != NULL) { cp_release_info(context, plugins); } return status; }
static void test_serialize1(void) { hash_t *selectors_filter = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry1 = NULL; entry1 = u_malloc(sizeof(selector_entry)*4); entry1[0].type = 0; entry1[0].entry.text = "OperatingSystemFilter0"; entry1[1].type = 0; entry1[1].entry.text = "localhost.localdomain"; entry1[2].type = 0; entry1[2].entry.text = "CIM_IndicationFilter"; entry1[3].type = 0; entry1[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors_filter, "Name", &entry1[0]); hash_alloc_insert(selectors_filter, "SystemName", &entry1[1]); hash_alloc_insert(selectors_filter, "CreationClassName", &entry1[2]); hash_alloc_insert(selectors_filter, "SystemCreationClassName", &entry1[3]); epr_t *epr_filter = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationFilter", selectors_filter, NULL); if(epr_filter == NULL) { printf("epr_create filter failed!\n"); return; } hash_t *selectors_handler = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry2 = u_malloc(sizeof(selector_entry)*4); entry2[0].type = 0; entry2[0].entry.text = "OperatingSystemHandler0"; entry2[1].type = 0; entry2[1].entry.text = "localhost.localdomain"; entry2[2].type = 0; entry2[2].entry.text = "CIM_IndicationHandlerCIMXML"; entry2[3].type = 0; entry2[3].entry.text = "CIM_ComputerSystem"; hash_alloc_insert(selectors_handler, "Name", &entry2[0]); hash_alloc_insert(selectors_handler, "SystemName", &entry2[1]); hash_alloc_insert(selectors_handler, "CreationClassName", &entry2[2]); hash_alloc_insert(selectors_handler, "SystemCreationClassName", &entry2[3]); epr_t *epr_handler = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationHandlerCIMXML", selectors_handler, NULL); if(epr_handler == NULL) { printf("epr_create handler failed!\n"); return; } hash_t *selectors_subscription = hash_create(HASHCOUNT_T_MAX, 0, 0); selector_entry *entry3 = NULL; entry3 = u_malloc(sizeof(selector_entry)*2); entry3[0].type = 1; entry3[0].entry.eprp = epr_filter; entry3[1].type = 1; entry3[1].entry.eprp = epr_handler; hash_alloc_insert(selectors_subscription, "Filter", &entry3[1]); hash_alloc_insert(selectors_subscription, "Handler", &entry3[1]); epr_t *epr_subscription = epr_create("http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/CIM_IndicationSubscription", selectors_subscription, NULL); if(epr_subscription == NULL) { printf("epr_create subscription failed!\n"); return; } epr_t *epr_cpy = epr_copy(epr_subscription); //test epr_copy WsXmlDocH doc = ws_xml_create_envelope(); WsXmlNodeH header = ws_xml_get_soap_header(doc); epr_serialize(header,NULL,NULL,epr_cpy,0); ws_xml_dump_doc(stdout, doc); epr_destroy(epr_filter); epr_destroy(epr_handler); epr_destroy(epr_subscription); epr_destroy(epr_cpy); hash_free(selectors_filter); hash_free(selectors_handler); hash_free(selectors_subscription); u_free(entry1); u_free(entry2); u_free(entry3); ws_xml_destroy_doc(doc); printf("\033[22;32mtest serialize epr successfully!\033[m\n\n"); }
hash_t * wsman_get_method_args(WsContextH cntx, const char *resource_uri) { char *input = NULL; WsXmlDocH doc = cntx->indoc; hash_t *h = hash_create(HASHCOUNT_T_MAX, 0, 0); hash_set_allocator(h, NULL, wsman_free_method_hnode, NULL); if (doc) { WsXmlNodeH in_node; WsXmlNodeH body = ws_xml_get_soap_body(doc); char *mn = wsman_get_method_name(cntx); input = u_strdup_printf("%s_INPUT", mn); in_node = ws_xml_get_child(body, 0, resource_uri, input); if (!in_node) { char *xsd = u_strdup_printf("%s.xsd", resource_uri); in_node = ws_xml_get_child(body, 0, xsd, input); u_free(xsd); } if (in_node) { WsXmlNodeH arg, epr; int index = 0; list_t *arglist = list_create(LISTCOUNT_T_MAX); lnode_t *argnode; while ((arg = ws_xml_get_child(in_node, index++, NULL, NULL))) { char *key = ws_xml_get_node_local_name(arg); selector_entry *sentry = u_malloc(sizeof(*sentry)); methodarglist_t *nodeval = u_malloc(sizeof(methodarglist_t)); epr = ws_xml_get_child(arg, 0, XML_NS_ADDRESSING, WSA_REFERENCE_PARAMETERS); nodeval->key = u_strdup(key); nodeval->arraycount = 0; argnode = lnode_create(nodeval); if (epr) { debug("epr: %s", key); sentry->type = 1; sentry->entry.eprp = epr_deserialize(arg, NULL, NULL, 1); //wsman_get_epr(cntx, arg, key, XML_NS_CIM_CLASS); } else { debug("text: %s", key); sentry->type = 0; sentry->entry.text = u_strdup(ws_xml_get_node_text(arg)); } nodeval->data = sentry; list_append(arglist, argnode); } if (!hash_alloc_insert(h, METHOD_ARGS_KEY, arglist)) { error("hash_alloc_insert failed"); wsman_free_method_list(arglist); } } u_free(mn); u_free(input); } else { error("error: xml document is NULL"); } if (!hash_isempty(h)) return h; hash_destroy(h); return NULL; }