dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libsip / common / sip_xaction_ui.c
blob33b0ed45029f4f1612a4787333223da1676afffb
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <stdlib.h>
28 #include <assert.h>
29 #include <errno.h>
30 #include <strings.h>
31 #include <pthread.h>
32 #include <sip.h>
34 #include "sip_msg.h"
35 #include "sip_miscdefs.h"
36 #include "sip_xaction.h"
39 * Hold transaction
41 void
42 sip_hold_trans(sip_transaction_t sip_trans)
44 sip_xaction_t *_trans;
46 if (sip_trans == NULL)
47 return;
48 _trans = (sip_xaction_t *)sip_trans;
49 (void) pthread_mutex_lock(&((_trans)->sip_xaction_mutex));
50 SIP_XACTION_REFCNT_INCR(_trans);
51 (void) pthread_mutex_unlock(&((_trans)->sip_xaction_mutex));
55 * Release transaction
57 void
58 sip_release_trans(sip_transaction_t sip_trans)
60 sip_xaction_t *_trans;
62 if (sip_trans == NULL)
63 return;
64 _trans = (sip_xaction_t *)sip_trans;
65 SIP_XACTION_REFCNT_DECR(_trans);
69 * Given a message get the client/server transaction. The caller is
70 * responsible for doing a sip_release_trans().
72 const struct sip_xaction *
73 sip_get_trans(sip_msg_t sip_msg, int which, int *error)
75 if (error != NULL)
76 *error = 0;
77 if (sip_msg == NULL) {
78 if (error != NULL)
79 *error = EINVAL;
80 return (NULL);
82 return ((sip_transaction_t)sip_xaction_get(NULL, sip_msg, B_FALSE,
83 which, NULL));
87 * Get the last response sent for this transaction
89 const struct sip_message *
90 sip_get_trans_resp_msg(sip_transaction_t sip_trans, int *error)
92 sip_xaction_t *_trans;
94 if (error != NULL)
95 *error = 0;
96 if (sip_trans == NULL) {
97 if (error != NULL)
98 *error = EINVAL;
99 return (NULL);
101 _trans = (sip_xaction_t *)sip_trans;
102 if ((_trans->sip_xaction_last_msg != NULL) &&
103 !sip_msg_is_request((sip_msg_t)_trans->sip_xaction_last_msg,
104 error)) {
105 return (_trans->sip_xaction_last_msg);
106 } else if (!sip_msg_is_request((sip_msg_t)
107 _trans->sip_xaction_orig_msg, error)) {
108 return (_trans->sip_xaction_orig_msg);
110 return (NULL);
114 * Get the SIP message that created this transaction
116 const struct sip_message *
117 sip_get_trans_orig_msg(sip_transaction_t sip_trans, int *error)
119 if (error != NULL)
120 *error = 0;
121 if (sip_trans == NULL) {
122 if (error != NULL)
123 *error = EINVAL;
124 return (NULL);
126 return (((sip_xaction_t *)sip_trans)->sip_xaction_orig_msg);
130 * Get the connection object that was used to send the last message for this
131 * transaction.
133 const struct sip_conn_object *
134 sip_get_trans_conn_obj(sip_transaction_t sip_trans, int *error)
136 if (error != NULL)
137 *error = 0;
138 if (sip_trans == NULL) {
139 if (error != NULL)
140 *error = EINVAL;
141 return (NULL);
143 return (((sip_xaction_t *)sip_trans)->sip_xaction_conn_obj);
147 * Get the transaction method
149 sip_method_t
150 sip_get_trans_method(sip_transaction_t sip_trans, int *error)
152 if (error != NULL)
153 *error = 0;
155 if (sip_trans == NULL) {
156 if (error != NULL)
157 *error = EINVAL;
158 return (-1);
160 return (((sip_xaction_t *)sip_trans)->sip_xaction_method);
164 * Get the transaction id. Caller frees string
166 char *
167 sip_get_trans_branchid(sip_transaction_t trans, int *error)
169 sip_xaction_t *xaction = (sip_xaction_t *)trans;
170 char *bid;
172 if (error != NULL)
173 *error = 0;
174 if (xaction == NULL || xaction->sip_xaction_branch_id == NULL) {
175 if (error != NULL)
176 *error = EINVAL;
177 return (NULL);
179 bid = malloc(strlen(xaction->sip_xaction_branch_id) + 1);
180 if (bid == NULL) {
181 if (error != NULL)
182 *error = ENOMEM;
183 return (NULL);
185 (void) strncpy(bid, xaction->sip_xaction_branch_id,
186 strlen(xaction->sip_xaction_branch_id));
187 bid[strlen(xaction->sip_xaction_branch_id)] = SIP_NUL;
188 return (bid);
192 * Get the transaction state
195 sip_get_trans_state(sip_transaction_t trans, int *error)
197 sip_xaction_t *xaction = (sip_xaction_t *)trans;
199 if (error != NULL)
200 *error = 0;
201 if (xaction == NULL) {
202 if (error != NULL)
203 *error = EINVAL;
204 return (0);
206 return (xaction->sip_xaction_state);