⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ne_props.c

📁 linux subdivision ying gai ke yi le ba
💻 C
📖 第 1 页 / 共 2 页
字号:
    int ps, p;    for (ps = 0; ps < set->numpstats; ps++) {	for (p = 0; p < set->pstats[ps].numprops; p++) {	    struct prop *prop = &set->pstats[ps].props[p];	    int ret = iterator(userdata, &prop->pname, prop->value, 			       &set->pstats[ps].status);	    if (ret)		return ret;	}    }    return 0;}const ne_status *ne_propset_status(const ne_prop_result_set *set,				      const ne_propname *pname){    struct propstat *pstat;        if (findprop(set, pname, &pstat, NULL)) {	/* TODO: it is tempting to return a dummy status object here	 * rather than NULL, which says "Property result was not given	 * by server."  but I'm not sure if this is best left to the	 * client.  */	return NULL;    } else {	return &pstat->status;    }}static void *start_response(void *userdata, const char *href){    ne_prop_result_set *set = ne_calloc(sizeof(*set));    ne_propfind_handler *hdl = userdata;    set->href = ne_strdup(href);    if (hdl->private_creator != NULL) {	set->private = hdl->private_creator(hdl->private_userdata, href);    }    hdl->current = set;    return set;}static void *start_propstat(void *userdata, void *response){    ne_prop_result_set *set = response;    int n;    struct propstat *pstat;    n = set->numpstats;    set->pstats = ne_realloc(set->pstats, sizeof(struct propstat) * (n+1));    set->numpstats = n+1;    pstat = &set->pstats[n];    memset(pstat, 0, sizeof(*pstat));        /* And return this as the new pstat. */    return &set->pstats[n];}static int startelm(void *userdata, int parent,                    const char *nspace, const char *name, const char **atts){    ne_propfind_handler *hdl = userdata;    struct propstat *pstat = ne_207_get_current_propstat(hdl->parser207);    struct prop *prop;    int n;    const char *lang;    /* Just handle all children of propstat and their descendants. */    if ((parent != NE_207_STATE_PROP && parent != ELM_flatprop)         || pstat == NULL)        return NE_XML_DECLINE;    if (parent == ELM_flatprop) {        /* collecting the flatprop value. */        hdl->depth++;        if (hdl->value->used < MAX_FLATPROP_LEN)            ne_buffer_concat(hdl->value, "<", name, ">", NULL);        return ELM_flatprop;    }            /* Add a property to this propstat */    n = pstat->numprops;    pstat->props = ne_realloc(pstat->props, sizeof(struct prop) * (n + 1));    pstat->numprops = n+1;    /* Fill in the new property. */    prop = &pstat->props[n];    prop->pname.name = prop->name = ne_strdup(name);    if (nspace[0] == '\0') {	prop->pname.nspace = prop->nspace = NULL;    } else {	prop->pname.nspace = prop->nspace = ne_strdup(nspace);    }    prop->value = NULL;    NE_DEBUG(NE_DBG_XML, "Got property #%d: {%s}%s.\n", n, 	     NSPACE(prop->nspace), prop->name);    /* This is under discussion at time of writing (April '01), and it     * looks like we need to retrieve the xml:lang property from any     * element here or above.     *     * Also, I think we might need attribute namespace handling here.  */    lang = ne_xml_get_attr(hdl->parser, atts, NULL, "xml:lang");    if (lang != NULL) {	prop->lang = ne_strdup(lang);	NE_DEBUG(NE_DBG_XML, "Property language is %s\n", prop->lang);    } else {	prop->lang = NULL;    }    hdl->depth = 0;    return ELM_flatprop;}static int endelm(void *userdata, int state,                  const char *nspace, const char *name){    ne_propfind_handler *hdl = userdata;    struct propstat *pstat = ne_207_get_current_propstat(hdl->parser207);    int n;    if (hdl->depth > 0) {        /* nested. */        if (hdl->value->used < MAX_FLATPROP_LEN)            ne_buffer_concat(hdl->value, "</", name, ">", NULL);        hdl->depth--;    } else {        /* end of the current property value */        n = pstat->numprops - 1;        pstat->props[n].value = ne_buffer_finish(hdl->value);        hdl->value = ne_buffer_create();    }    return 0;}static void end_propstat(void *userdata, void *pstat_v, 			 const ne_status *status,			 const char *description){    struct propstat *pstat = pstat_v;    /* Nothing to do if no status was given. */    if (!status) return;    /* If we get a non-2xx response back here, we wipe the value for     * each of the properties in this propstat, so the caller knows to     * look at the status instead. It's annoying, since for each prop     * we will have done an unnecessary strdup("") above, but there is     * no easy way round that given the fact that we don't know     * whether we've got an error or not till after we get the     * property element.     *     * Interestingly IIS breaks the 2518 DTD and puts the status     * element first in the propstat. This is useful since then we     * *do* know whether each subsequent empty prop element means, but     * we can't rely on that here. */    if (status->klass != 2) {	int n;		for (n = 0; n < pstat->numprops; n++) {	    ne_free(pstat->props[n].value);	    pstat->props[n].value = NULL;	}    }    /* copy the status structure, and dup the reason phrase. */    pstat->status = *status;    pstat->status.reason_phrase = ne_strdup(status->reason_phrase);}/* Frees up a results set */static void free_propset(ne_prop_result_set *set){    int n;        for (n = 0; n < set->numpstats; n++) {	int m;	struct propstat *p = &set->pstats[n];	for (m = 0; m < p->numprops; m++) {	    NE_FREE(p->props[m].nspace);	    ne_free(p->props[m].name);	    NE_FREE(p->props[m].lang);	    NE_FREE(p->props[m].value);	}	if (p->status.reason_phrase)	    ne_free(p->status.reason_phrase);	if (p->props)	    ne_free(p->props);    }    if (set->pstats)	ne_free(set->pstats);    ne_free(set->href);    ne_free(set);}static void end_response(void *userdata, void *resource,			 const ne_status *status,			 const char *description){    ne_propfind_handler *handler = userdata;    ne_prop_result_set *set = resource;    /* Pass back the results for this resource. */    if (handler->callback && set->numpstats > 0)	handler->callback(handler->userdata, set->href, set);    /* Clean up the propset tree we've just built. */    free_propset(set);    handler->current = NULL;}ne_propfind_handler *ne_propfind_create(ne_session *sess, const char *uri, int depth){    ne_propfind_handler *ret = ne_calloc(sizeof(ne_propfind_handler));    ret->parser = ne_xml_create();    ret->parser207 = ne_207_create(ret->parser, ret);    ret->sess = sess;    ret->body = ne_buffer_create();    ret->request = ne_request_create(sess, "PROPFIND", uri);    ret->value = ne_buffer_create();    ne_add_depth_header(ret->request, depth);    ne_207_set_response_handlers(ret->parser207, 				  start_response, end_response);    ne_207_set_propstat_handlers(ret->parser207, start_propstat,				  end_propstat);    /* The start of the request body is fixed: */    ne_buffer_concat(ret->body, 		    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" EOL 		    "<propfind xmlns=\"DAV:\">", NULL);    return ret;}/* Destroy a propfind handler */void ne_propfind_destroy(ne_propfind_handler *handler){    ne_buffer_destroy(handler->value);    if (handler->current)        free_propset(handler->current);    ne_207_destroy(handler->parser207);    ne_xml_destroy(handler->parser);    ne_buffer_destroy(handler->body);    ne_request_destroy(handler->request);    ne_free(handler);    }int ne_simple_propfind(ne_session *sess, const char *href, int depth,			const ne_propname *props,			ne_props_result results, void *userdata){    ne_propfind_handler *hdl;    int ret;    hdl = ne_propfind_create(sess, href, depth);    if (props != NULL) {	ret = ne_propfind_named(hdl, props, results, userdata);    } else {	ret = ne_propfind_allprop(hdl, results, userdata);    }	    ne_propfind_destroy(hdl);        return ret;}int ne_propnames(ne_session *sess, const char *href, int depth,		  ne_props_result results, void *userdata){    ne_propfind_handler *hdl;    int ret;    hdl = ne_propfind_create(sess, href, depth);    ne_buffer_zappend(hdl->body, "<propname/></propfind>");    ret = propfind(hdl, results, userdata);    ne_propfind_destroy(hdl);    return ret;}void ne_propfind_set_private(ne_propfind_handler *hdl,			      ne_props_create_complex creator,			      void *userdata){    hdl->private_creator = creator;    hdl->private_userdata = userdata;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -