nua_message.c 5.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*
 * 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_message.c
 * @brief MESSAGE method
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Wed Mar  8 17:01:22 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"

/* ======================================================================== */
/* MESSAGE */

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/** Send an instant message. 
 *
 * Send an instant message using SIP MESSAGE method.
 *
 * @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
 *    Tags in <sip_tag.h>
 *
 * @par Events:
 *    #nua_r_message
 *
69
 * @sa #nua_i_message, @RFC3428
70 71
 */

72 73 74 75
static int nua_message_client_init(nua_client_request_t *cr, 
				   msg_t *, sip_t *,
				   tagi_t const *tags);

76
static nua_client_methods_t const nua_message_client_methods = {
77 78 79 80 81 82 83 84 85 86 87 88 89
  SIP_METHOD_MESSAGE,
  0,
  { 
    /* create_dialog */ 0,
    /* in_dialog */ 0,
    /* target refresh */ 0
  },
  /* nua_message_client_template */ NULL,
  nua_message_client_init,
  /*nua_message_client_request*/ NULL,
  /* nua_message_client_check_restart */ NULL,
  /*nua_message_client_response*/ NULL
};
90 91

int 
92 93 94 95
nua_stack_message(nua_t *nua,
		  nua_handle_t *nh,
		  nua_event_t e,
		  tagi_t const *tags)
96
{ 
97
  return nua_client_create(nh, e, &nua_message_client_methods, tags);
98 99
}

100 101 102
static int nua_message_client_init(nua_client_request_t *cr, 
				   msg_t *msg, sip_t *sip,
				   tagi_t const *tags)
103
{
104 105 106
  if (NH_PGET(cr->cr_owner, win_messenger_enable))
    cr->cr_contactize = 1;
  return 0;
107 108
}

109
/** @NUA_EVENT nua_r_message
110
 *
111
 * Response to an outgoing @b MESSAGE request.
112
 *
113 114 115 116 117 118 119
 * @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 message
 * @param hmagic application context associated with the handle
120
 * @param sip    response to MESSAGE request or NULL upon an error
121 122
 *               (status code is in @a status and 
 *                descriptive message in @a phrase parameters)
123 124 125
 * @param tags   empty
 *
 * @sa nua_message(), #nua_i_message, @RFC3428
126 127
 *
 * @END_NUA_EVENT
128 129
 */

130
/** @NUA_EVENT nua_i_message
131
 *
132
 * @brief Incoming @b MESSAGE request.
133
 *
134 135 136 137
 * The @b MESSAGE request does not create a dialog. If the incoming @b
 * MESSAGE request is not assiciated with an existing dialog the stack
 * creates a new handle for it. If the handle @a nh is not bound, you should
 * probably destroy it after responding to the MESSAGE request.
138
 *
139 140 141 142
 * @param status status code of response sent automatically by stack
 * @param phrase a short textual description of @a status code
 * @param nh     operation handle associated with the message
 * @param hmagic application context associated with the handle
143 144 145 146
 *               (maybe NULL if outside session)
 * @param sip    incoming MESSAGE request
 * @param tags   empty
 *
147 148 149
 * @sa nua_message(), #nua_r_message, @RFC3428, @RFC3862
 *
 * @END_NUA_EVENT
150 151
 */

152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
int nua_message_server_init(nua_server_request_t *sr);
int nua_message_server_params(nua_server_request_t *, tagi_t const *);

nua_server_methods_t const nua_message_server_methods = 
  {
    SIP_METHOD_MESSAGE,
    nua_i_message,		/* Event */
    { 
      0,			/* Do not create dialog */
      0,			/* Can be initial request */
      0,			/* Perhaps a target refresh request? */
      0,			/* Do not add contact by default */
    },
    nua_message_server_init,
    nua_base_server_preprocess,
    nua_message_server_params,
    nua_base_server_respond,
    nua_base_server_report,
  };

int nua_message_server_init(nua_server_request_t *sr)
173
{
174 175
  if (!NH_PGET(sr->sr_owner, message_enable))
    return SR_STATUS1(sr, SIP_403_FORBIDDEN);
176

177 178
  return 0;
}
179

180 181 182 183 184
int nua_message_server_params(nua_server_request_t *sr,
			      tagi_t const *tags)
{
  if (NH_PGET(sr->sr_owner, win_messenger_enable))
    sr->sr_add_contact = 1;
185

186
  return 0;
187
}