/*! * \internal * \brief Adds a path header to an outgoing 2XX response * * \param endpoint The endpoint to which the INVITE response is to be sent * \param contact The contact to which the INVITE response is to be sent * \param tdata The outbound INVITE response */ static void path_outgoing_response(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, pjsip_tx_data *tdata) { struct pjsip_status_line status = tdata->msg->line.status; pj_str_t path_dup; pjsip_generic_string_hdr *path_hdr; pjsip_contact_hdr *contact_hdr; RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup); pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL); const pj_str_t REGISTER_METHOD = {"REGISTER", 8}; if (!endpoint || !pj_stristr(®ISTER_METHOD, &cseq->method.name) || !PJSIP_IS_STATUS_IN_CLASS(status.code, 200)) { return; } contact_hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL); if (!contact_hdr) { return; } aor = find_aor(endpoint, contact_hdr->uri); if (!aor || !aor->support_path || add_supported(tdata) || path_get_string(tdata->pool, contact, &path_dup)) { return; } path_hdr = pjsip_generic_string_hdr_create(tdata->pool, &PATH_NAME, &path_dup); if (!path_hdr) { return; } pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)path_hdr); }
/*! * \internal * \brief Adds a Route header to an outgoing request if * path information is available. * * \param endpoint The endpoint with which this request is associated * \param contact The contact to which this request is being sent * \param tdata The outbound request */ static void path_outgoing_request(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, pjsip_tx_data *tdata) { RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup); if (!endpoint) { return; } aor = find_aor(endpoint, tdata->msg->line.req.uri); if (!aor || !aor->support_path) { return; } if (add_supported(tdata)) { return; } if (contact && !ast_strlen_zero(contact->path)) { ast_sip_set_outbound_proxy(tdata, contact->path); } }
static dav_prop_insert dav_acl_insert_prop(const dav_resource *resource, int propid, dav_prop_insert what, apr_text_header *phdr) { const char *value = NULL; const char *s = NULL; apr_pool_t *p = resource->pool; const dav_liveprop_spec *info; int global_ns, rc; if (!resource->exists) return DAV_PROP_INSERT_NOTDEF; /* ### we may want to respond to DAV_PROPID_resourcetype for PRIVATE ### resources. need to think on "proper" interaction with mod_dav */ switch (propid) { case ACL_PROPID_acl: if (what == DAV_PROP_INSERT_VALUE) { /* request_rec *r = resource->hooks->get_request_rec(resource) */; xmlBufferPtr buf = NULL; const char *pch = NULL; xmlDocPtr doc; xmlNodePtr node; rc = dav_acl_get_acl(resource, &pch, &rc); if (rc < 0) return DAV_PROP_INSERT_NOTDEF; doc = xmlParseMemory(pch, rc); node = doc && doc->children ? doc->children : NULL; buf = xmlBufferCreate(); xmlNodeDump(buf, doc, node, 0, 1); xmlFreeDoc(doc); apr_text_append(p, phdr, apr_psprintf (p, "%s" DEBUG_CR, buf->content)); /* we inserted whatever was asked for */ xmlBufferFree(buf); return what; } break; case ACL_PROPID_acl_restrictions: value = "<D:required-principal>" "<D:authenticated/>" "<D:unauthenticated/>" "<D:self/>" "<D:all/>" "<D:href/>" "<D:property><D:owner/></D:property>" "<D:property><D:group/></D:property>" "</D:required-principal>"; break; case ACL_PROPID_supported_privilege_set: if (what == DAV_PROP_INSERT_VALUE) { xmlBufferPtr buf = NULL; xmlDocPtr doc = xmlNewDoc((const xmlChar *) XML_VERSION); xmlNsPtr ns; xmlNodePtr cur, child, node; int acl, cups; dav_acl_get_aggregated(resource, &acl, &cups); doc->children = xmlNewDocNode(doc, NULL, (const xmlChar *) "root", NULL); xmlSetNs(doc->children, ns = xmlNewNs(doc->children, (const xmlChar *) "DAV:", (const xmlChar *) "D")); node = xmlNewChild(doc->children, ns, (const xmlChar *) "supported-privilege-set", NULL); cur = add_supported(node, ns, "all", 0, "All privileges"); child = add_supported(cur, ns, "read", 0, "Read"); add_supported(acl ? child : cur, ns, "read-acl", 0, "Read ACL"); add_supported(cups ? child : cur, ns, "read-current-user-privilege-set", 0, "Read Current User"); child = add_supported(cur, ns, "write", 0, "Write"); add_supported(child, ns, "write-acl", 0, "Write ACL"); add_supported(child, ns, "write-content", 0, "Write content"); add_supported(child, ns, "write-properties", 0, "Write properties"); if (resource->collection) { add_supported(child, ns, "bind", 0, "Create a collection"); add_supported(child, ns, "unbind", 0, "Remove a collection"); } add_supported(cur, ns, "unlock", 0, "Unlock"); buf = xmlBufferCreate(); xmlNodeDump(buf, doc, node, 0, 1); xmlFreeDoc(doc); apr_text_append(p, phdr, apr_psprintf(p, "%s" DEBUG_CR, buf->content)); /* we inserted whatever was asked for */ xmlBufferFree(buf); return what; } break; case ACL_PROPID_group_membership: value = dav_acl_get_group_membership(resource); if (value == NULL) return DAV_PROP_INSERT_NOTDEF; break; case ACL_PROPID_owner: value = dav_acl_get_owner(resource); if (value == NULL) return DAV_PROP_INSERT_NOTDEF; break; case ACL_PROPID_alternate_uri_set: value = ""; /* may be empty */ break; case ACL_PROPID_inherited_acl_set: value = ""; /* not supported because of complexity... */ break; case ACL_PROPID_current_user_privilege_set: value = dav_acl_get_privs(resource); break; case ACL_PROPID_principal_collection_set: { request_rec *r = resource->hooks->get_request_rec(resource); const char *pcsz = dav_acl_get_principals(r); value = apr_psprintf(p, "<D:href>%s/</D:href>", pcsz ? pcsz : ""); } break; case ACL_PROPID_current_user_principal: value = dav_acl_get_auth_principal(resource); if (value) value = apr_psprintf(p, "<D:href>%s</D:href>", value); else value = "<D:unauthenticated/>"; break; default: /* ### what the heck was this property? */ return DAV_PROP_INSERT_NOTDEF; } /* assert: value != NULL */ /* get the information and global NS index for the property */ global_ns = dav_get_liveprop_info(propid, &dav_acl_liveprop_group, &info); /* assert: info != NULL && info->name != NULL */ if (what == DAV_PROP_INSERT_VALUE) s = apr_psprintf(p, "<lp%d:%s>%s</lp%d:%s>" DEBUG_CR, global_ns, info->name, value, global_ns, info->name); else if (what == DAV_PROP_INSERT_NAME) s = apr_psprintf(p, "<lp%d:%s/>" DEBUG_CR, global_ns, info->name); else /* assert: what == DAV_PROP_INSERT_SUPPORTED */ s = apr_psprintf(p, "<D:supported-live-property D:name=\"%s\" " "D:namespace=\"%s\"/>" DEBUG_CR, info->name, dav_acl_namespace_uris[info->ns]); apr_text_append(p, phdr, s); /* we inserted whatever was asked for */ return what; }