Example #1
0
void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) {
    belle_http_request_listener_callbacks_t cbs = { 0 };
    belle_http_request_listener_t *l;
    belle_generic_uri_t *uri;
    belle_http_request_t *req;
    belle_sip_memory_body_handler_t *bh;
    const char *data;
    LinphoneContent *content;
    linphone_xml_rpc_request_ref(request);

    uri = belle_generic_uri_parse(session->url);
    if (!uri) {
        ms_error("Could not send request, URL %s is invalid", session->url);
        process_io_error_from_post_xml_rpc_request(request, NULL);
        return;
    }
    req = belle_http_request_create("POST", uri, belle_sip_header_content_type_create("text", "xml"), NULL);
    if (!req) {
        belle_sip_object_unref(uri);
        process_io_error_from_post_xml_rpc_request(request, NULL);
    }
    content = linphone_content_new();
    linphone_content_set_type(content, "text");
    linphone_content_set_subtype(content, "xml");
    linphone_content_set_string_buffer(content, linphone_xml_rpc_request_get_content(request));
    data = linphone_xml_rpc_request_get_content(request);
    bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, NULL);
    belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh));
    cbs.process_response = process_response_from_post_xml_rpc_request;
    cbs.process_io_error = process_io_error_from_post_xml_rpc_request;
    cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request;
    l = belle_http_request_listener_create_from_callbacks(&cbs, request);
    belle_http_provider_send_request(session->core->http_provider, req, l);
    linphone_content_unref(content);
}
Example #2
0
void linphone_friend_list_update_subscriptions(LinphoneFriendList *list, LinphoneProxyConfig *cfg, bool_t only_when_registered) {
	const bctbx_list_t *elem;
	if (list->rls_uri != NULL) {
		if (list->enable_subscriptions) {
			LinphoneAddress *address = linphone_address_new(list->rls_uri);
			char *xml_content = create_resource_list_xml(list);
			if ((address != NULL) && (xml_content != NULL) && (linphone_friend_list_has_subscribe_inactive(list) == TRUE)) {
				unsigned char digest[16];
				bctbx_md5((unsigned char *)xml_content, strlen(xml_content), digest);
				if ((list->event != NULL) && (list->content_digest != NULL) && (memcmp(list->content_digest, digest, sizeof(digest)) == 0)) {
					/* The content has not changed, only refresh the event. */
					linphone_event_refresh_subscribe(list->event);
				} else {
					LinphoneContent *content;
					int expires = lp_config_get_int(list->lc->config, "sip", "rls_presence_expires", 3600);
					list->expected_notification_version = 0;
					if (list->content_digest != NULL) ms_free(list->content_digest);
					list->content_digest = ms_malloc(sizeof(digest));
					memcpy(list->content_digest, digest, sizeof(digest));
					if (list->event != NULL) {
						linphone_event_terminate(list->event);
						linphone_event_unref(list->event);
					}
					list->event = linphone_core_create_subscribe(list->lc, address, "presence", expires);
					linphone_event_ref(list->event);
					linphone_event_set_internal(list->event, TRUE);
					linphone_event_add_custom_header(list->event, "Require", "recipient-list-subscribe");
					linphone_event_add_custom_header(list->event, "Supported", "eventlist");
					linphone_event_add_custom_header(list->event, "Accept", "multipart/related, application/pidf+xml, application/rlmi+xml");
					linphone_event_add_custom_header(list->event, "Content-Disposition", "recipient-list");
					content = linphone_core_create_content(list->lc);
					linphone_content_set_type(content, "application");
					linphone_content_set_subtype(content, "resource-lists+xml");
					linphone_content_set_string_buffer(content, xml_content);
					if (linphone_core_content_encoding_supported(list->lc, "deflate")) {
						linphone_content_set_encoding(content, "deflate");
						linphone_event_add_custom_header(list->event, "Accept-Encoding", "deflate");
					}
					linphone_event_send_subscribe(list->event, content);
					linphone_content_unref(content);
					linphone_event_set_user_data(list->event, list);
				}
			}
			if (address != NULL) linphone_address_unref(address);
			if (xml_content != NULL) ms_free(xml_content);
		} else {
			ms_message("Friends list [%p] subscription update skipped since subscriptions not enabled yet", list);
		}
	} else if (list->enable_subscriptions) {
		for (elem = list->friends; elem != NULL; elem = elem->next) {
			LinphoneFriend *lf = (LinphoneFriend *)elem->data;
			linphone_friend_update_subscribes(lf, cfg, only_when_registered);
		}
	}
}