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

📄 nua_publish.c

📁 Sofia SIP is an open-source SIP User-Agent library, compliant with the IETF RFC3261 specification.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of the Sofia-SIP package * * Copyright (C) 2006 Nokia Corporation. * * Contact: Pekka Pessi <pekka.pessi@nokia.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * *//**@CFILE nua_publish.c * @brief PUBLISH and publications * * @sa @RFC3903 * * @author Pekka Pessi <Pekka.Pessi@nokia.com> * * @date Created: Wed Mar  8 17:01:32 EET 2006 ppessi */#include "config.h"#include <stddef.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <assert.h>#include <sofia-sip/string0.h>#include <sofia-sip/sip_protos.h>#include <sofia-sip/sip_status.h>#include "nua_stack.h"/* ====================================================================== *//* Publish usage */struct publish_usage {  sip_etag_t *pu_etag;  int pu_published;};static char const *nua_publish_usage_name(nua_dialog_usage_t const *du);static int nua_publish_usage_add(nua_handle_t *nh,				  nua_dialog_state_t *ds,				  nua_dialog_usage_t *du);static void nua_publish_usage_remove(nua_handle_t *nh,				     nua_dialog_state_t *ds,				     nua_dialog_usage_t *du,				     nua_client_request_t *cr,				     nua_server_request_t *sr);static void nua_publish_usage_refresh(nua_handle_t *nh,				      nua_dialog_state_t *ds,				      nua_dialog_usage_t *du,				      sip_time_t now);static int nua_publish_usage_shutdown(nua_handle_t *nh,				      nua_dialog_state_t *ds,				      nua_dialog_usage_t *du);static nua_usage_class const nua_publish_usage[1] = {  {    sizeof (struct publish_usage),    sizeof nua_publish_usage,    nua_publish_usage_add,    nua_publish_usage_remove,    nua_publish_usage_name,    nua_base_usage_update_params,    NULL,    nua_publish_usage_refresh,    nua_publish_usage_shutdown,  }};staticchar const *nua_publish_usage_name(nua_dialog_usage_t const *du){  return "publish";}staticint nua_publish_usage_add(nua_handle_t *nh,			   nua_dialog_state_t *ds,			   nua_dialog_usage_t *du){  if (ds->ds_has_publish)    return -1;			/* There can be only one */  ds->ds_has_publish = 1;  return 0;}staticvoid nua_publish_usage_remove(nua_handle_t *nh,			      nua_dialog_state_t *ds,			      nua_dialog_usage_t *du,			      nua_client_request_t *cr,			      nua_server_request_t *sr){  struct publish_usage *pu = NUA_DIALOG_USAGE_PRIVATE(du);  su_free(nh->nh_home, pu->pu_etag);  ds->ds_has_publish = 0;	/* There can be only one */}/* ======================================================================== *//* PUBLISH *//**@fn \ * void nua_publish(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...); * * Send PUBLISH request to publication server. * * Request status will be delivered to the application using #nua_r_publish * event. When successful the publication will be updated periodically until * nua_unpublish() is called or handle is destroyed. Note that the periodic * updates and unpublish do not include the original message body nor the @b * Content-Type header. Instead, the periodic update will include the * @SIPIfMatch header, which was generated from the latest @SIPETag * header received in response to @b PUBLISH request. * * The handle used for publication cannot be used for any other purposes. * * @param nh              Pointer to operation handle * @param tag, value, ... List of tagged parameters * * @return *    nothing * * @par Related Tags: *    NUTAG_URL() \n *    Tags of nua_set_hparams() \n *    Header tags defined in <sofia-sip/sip_tag.h> * * @par Events: *    #nua_r_publish * * @sa #nua_r_publish, @RFC3903, @SIPIfMatch, * nua_unpublish(), #nua_r_unpublish, #nua_i_publish *//** @NUA_EVENT nua_r_publish * * Response to an outgoing PUBLISH. * * The PUBLISH request may be sent explicitly by nua_publish() or implicitly * by NUA state machine. * * @param status status code of PUBLISH request *               (if the request is retried, @a status is 100, the @a *               sip->sip_status->st_status contain the real status code *               from the response message, e.g., 302, 401, or 407) * @param phrase a short textual description of @a status code * @param nh     operation handle associated with the publication * @param hmagic application context associated with the handle * @param sip    response to PUBLISH request or NULL upon an error *               (status code is in @a status and  *                descriptive message in @a phrase parameters) * @param tags   empty * * @sa nua_publish(), @RFC3903, @SIPETag, @Expires, * nua_unpublish(), #nua_r_unpublish, #nua_i_publish * * @END_NUA_EVENT *//**@fn \void nua_unpublish(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...); * * Send un-PUBLISH request to publication server. Un-PUBLISH request is just * a PUBLISH request with @Expires set to 0. It is possible to un-publish a * publication not associated with the handle by providing correct ETag in * SIPTAG_IF_MATCH() or SIPTAG_IF_MATCH_STR() tags. * * Response to the un-PUBLISH request will be delivered to the application * using #nua_r_unpublish event. * * The handle used for publication cannot be used for any other purposes. * * @param nh              Pointer to operation handle * @param tag, value, ... List of tagged parameters * * @return *    nothing * * @par Related Tags: *    NUTAG_URL() \n *    SIPTAG_IF_MATCH(), SIPTAG_IF_MATCH_STR() \n *    SIPTAG_EVENT(), SIPTAG_EVENT_STR() \n *    Tags of nua_set_hparams() \n *    Other header tags defined in <sofia-sip/sip_tag.h> except SIPTAG_EXPIRES() or SIPTAG_EXPIRES_STR() * * @par Events: *    #nua_r_unpublish *  * @sa #nua_r_unpublish, @RFC3903, @SIPIfMatch,  * #nua_i_publish, nua_publish(), #nua_r_publish *//** @NUA_EVENT nua_r_unpublish * * Response to an outgoing un-PUBLISH. * * @param status response status code *               (if the request is retried, @a status is 100, the @a *               sip->sip_status->st_status contain the real status code *               from the response message, e.g., 302, 401, or 407) * @param phrase a short textual description of @a status code * @param nh     operation handle associated with the publication * @param hmagic application context associated with the handle * @param sip    response to PUBLISH request or NULL upon an error *               (status code is in @a status and  *                descriptive message in @a phrase parameters) * @param tags   empty * * @sa nua_unpublish(), @RFC3903, @SIPETag, @Expires, * nua_publish(), #nua_r_publish, #nua_i_publish * * @END_NUA_EVENT */static int nua_publish_client_template(nua_client_request_t *cr,				       msg_t **return_msg,				       tagi_t const *tags);static int nua_publish_client_init(nua_client_request_t *cr,				   msg_t *, sip_t *,				   tagi_t const *tags);static int nua_publish_client_request(nua_client_request_t *cr,				      msg_t *, sip_t *,				      tagi_t const *tags);static int nua_publish_client_check_restart(nua_client_request_t *cr,					    int status, char const *phrase,					    sip_t const *sip);static int nua_publish_client_response(nua_client_request_t *cr,				       int status, char const *phrase,				       sip_t const *sip);static nua_client_methods_t const nua_publish_client_methods = {  SIP_METHOD_PUBLISH,		/* crm_method, crm_method_name */  0,				/* crm_extra */  {				/* crm_flags */    /* create_dialog */ 0,    /* in_dialog */ 0,    /* target refresh */ 0  },  nua_publish_client_template,	/* crm_template */  nua_publish_client_init,	/* crm_init */  nua_publish_client_request,	/* crm_send */  nua_publish_client_check_restart, /* crm_check_restart */  nua_publish_client_response,	/* crm_recv */  NULL,				/* crm_preliminary */  NULL,				/* crm_report */  NULL,				/* crm_complete */};/**@internal Send PUBLISH. */

⌨️ 快捷键说明

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