Exemple #1
0
Request *Request_create()
{
    Request *req = calloc(sizeof(Request), 1);
    check_mem(req);

    req->parser.http_field = header_field_cb;
    req->parser.request_method = request_method_cb;
    req->parser.request_uri = uri_cb;
    req->parser.fragment = fragment_cb;
    req->parser.request_path = path_cb;
    req->parser.query_string = query_string_cb;
    req->parser.http_version = http_version_cb;
    req->parser.header_done = header_done_cb;

    req->headers = hash_create(MAX_HEADER_COUNT, (hash_comp_t)bstrcmp, bstr_hash_fun);
    check_mem(req->headers);
    hash_set_allocator(req->headers, req_alloc_hash, req_free_hash, NULL);

    req->parser.data = req;  // for the http callbacks

    return req;

error:
    Request_destroy(req);
    return NULL;
}
Exemple #2
0
static inline int Command_parse(struct params *p, Command *cmd)
{
    int next = 0;

    // TODO: refactor this, but for now command takes over the tokens until it's done
    memcpy(cmd->tokens, p->tokens, MAX_TOKENS);
    cmd->token_count = p->token_count;

    cmd->options = hash_create(HASHCOUNT_T_MAX, 0, 0);
    check_mem(cmd->options);
    hash_set_allocator(cmd->options, cmd_hnode_alloc, cmd_hnode_free, NULL);

    cmd->extra = list_create(LISTCOUNT_T_MAX);
    check_mem(cmd->extra);

    next = peek(p);
    if(next == TKIDENT || next == TKBLOB) {
        cmd->progname = match(p, next);
        check(cmd->progname, "No program name given in command.");
    } else {
        sentinel("Expected the name of the program you're running not: %s",
                bdata(match(p, next)));
    }

    cmd->name = match(p, TKIDENT);
    check(cmd->name, "No command name given.  Use m2sh help to figure out what's available.");

    for(next = peek(p); next != -1 && !cmd->error; next = peek(p)) {
        if(next == TKOPTION) {
            Command_option(cmd, p);
        } else {
            Command_extra(cmd, next, p);
        }
    }

    check(p->curtk == p->token_count, "Didn't parse the whole command line, only: %d of %d", p->curtk, p->token_count);

    return 0;

error:
    cmd->error = 1;
    return -1;
}
Exemple #3
0
/**
 * Adds three auxiliary components to the state table of this instance. These
 * components are used by {@link -compose CFst_Compose} and
 * {@link -best_n CFst_BestN} to associate a composed state with its source
 * states and an epsilon filter mode. The method sets the field
 * {@link ic_sd_aux m_nIcSdAux} to the first component added.
 *
 * @param _this Pointer to automaton instance
 * @see Cps_DelSdAux CFst_Cps_DelSdAux
 * @see Cps_SetSdAux CFst_Cps_SetSdAux
 * @see Cps_FindState CFst_Cps_FindState
 */
void CGEN_PRIVATE CFst_Cps_AddSdAux(CFst* _this)
{
  /* Add auxiliary components to state table */
  CData_AddComp(AS(CData,_this->sd),"X"  ,DLP_TYPE(FST_ITYPE));
  CData_AddComp(AS(CData,_this->sd),"Y"  ,DLP_TYPE(FST_ITYPE));
  CData_AddComp(AS(CData,_this->sd),"Flg",T_BYTE             );

  DLPASSERT((_this->m_nIcSdAux = CData_FindComp(AS(CData,_this->sd),"X"  ))>=0);
  DLPASSERT(                     CData_FindComp(AS(CData,_this->sd),"Y"  ) >=0);
  DLPASSERT(                     CData_FindComp(AS(CData,_this->sd),"Flg") >=0);

  /* Initialize hash node pool */
  DLPASSERT(_this->m_lpCpsHnpool   ==NULL);
  DLPASSERT(_this->m_nCpsHnpoolSize==0   );
  _this->m_lpCpsHnpool    = (void**)dlp_calloc(100,sizeof(hnode_t*));
  _this->m_nCpsHnpoolSize = 0;
  dlp_memset(_this->m_lpCpsKeybuf,0,3*sizeof(FST_ITYPE));

  /* Initialize composed state hash map */
  DLPASSERT(_this->m_lpCpsHash==NULL);
  _this->m_lpCpsHash = hash_create(HASHCOUNT_T_MAX,CFst_Cps_HashCmp,CFst_Cps_HashFn,_this);
  hash_set_allocator((hash_t*)_this->m_lpCpsHash,CFst_Cps_HashAllocNode,CFst_Cps_HashFreeNode,_this);
}
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;
}