8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libsip / common / sip_xaction_ui.c
blobbc60dfb07dc2b44d4a70132ac7a1f4ae5596a6eb
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 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <assert.h>
31 #include <errno.h>
32 #include <strings.h>
33 #include <pthread.h>
34 #include <sip.h>
36 #include "sip_msg.h"
37 #include "sip_miscdefs.h"
38 #include "sip_xaction.h"
41 * Hold transaction
43 void
44 sip_hold_trans(sip_transaction_t sip_trans)
46 sip_xaction_t *_trans;
48 if (sip_trans == NULL)
49 return;
50 _trans = (sip_xaction_t *)sip_trans;
51 (void) pthread_mutex_lock(&((_trans)->sip_xaction_mutex));
52 SIP_XACTION_REFCNT_INCR(_trans);
53 (void) pthread_mutex_unlock(&((_trans)->sip_xaction_mutex));
57 * Release transaction
59 void
60 sip_release_trans(sip_transaction_t sip_trans)
62 sip_xaction_t *_trans;
64 if (sip_trans == NULL)
65 return;
66 _trans = (sip_xaction_t *)sip_trans;
67 SIP_XACTION_REFCNT_DECR(_trans);
71 * Given a message get the client/server transaction. The caller is
72 * responsible for doing a sip_release_trans().
74 const struct sip_xaction *
75 sip_get_trans(sip_msg_t sip_msg, int which, int *error)
77 if (error != NULL)
78 *error = 0;
79 if (sip_msg == NULL) {
80 if (error != NULL)
81 *error = EINVAL;
82 return (NULL);
84 return ((sip_transaction_t)sip_xaction_get(NULL, sip_msg, B_FALSE,
85 which, NULL));
89 * Get the last response sent for this transaction
91 const struct sip_message *
92 sip_get_trans_resp_msg(sip_transaction_t sip_trans, int *error)
94 sip_xaction_t *_trans;
96 if (error != NULL)
97 *error = 0;
98 if (sip_trans == NULL) {
99 if (error != NULL)
100 *error = EINVAL;
101 return (NULL);
103 _trans = (sip_xaction_t *)sip_trans;
104 if ((_trans->sip_xaction_last_msg != NULL) &&
105 !sip_msg_is_request((sip_msg_t)_trans->sip_xaction_last_msg,
106 error)) {
107 return (_trans->sip_xaction_last_msg);
108 } else if (!sip_msg_is_request((sip_msg_t)
109 _trans->sip_xaction_orig_msg, error)) {
110 return (_trans->sip_xaction_orig_msg);
112 return (NULL);
116 * Get the SIP message that created this transaction
118 const struct sip_message *
119 sip_get_trans_orig_msg(sip_transaction_t sip_trans, int *error)
121 if (error != NULL)
122 *error = 0;
123 if (sip_trans == NULL) {
124 if (error != NULL)
125 *error = EINVAL;
126 return (NULL);
128 return (((sip_xaction_t *)sip_trans)->sip_xaction_orig_msg);
132 * Get the connection object that was used to send the last message for this
133 * transaction.
135 const struct sip_conn_object *
136 sip_get_trans_conn_obj(sip_transaction_t sip_trans, int *error)
138 if (error != NULL)
139 *error = 0;
140 if (sip_trans == NULL) {
141 if (error != NULL)
142 *error = EINVAL;
143 return (NULL);
145 return (((sip_xaction_t *)sip_trans)->sip_xaction_conn_obj);
149 * Get the transaction method
151 sip_method_t
152 sip_get_trans_method(sip_transaction_t sip_trans, int *error)
154 if (error != NULL)
155 *error = 0;
157 if (sip_trans == NULL) {
158 if (error != NULL)
159 *error = EINVAL;
160 return (-1);
162 return (((sip_xaction_t *)sip_trans)->sip_xaction_method);
166 * Get the transaction id. Caller frees string
168 char *
169 sip_get_trans_branchid(sip_transaction_t trans, int *error)
171 sip_xaction_t *xaction = (sip_xaction_t *)trans;
172 char *bid;
174 if (error != NULL)
175 *error = 0;
176 if (xaction == NULL || xaction->sip_xaction_branch_id == NULL) {
177 if (error != NULL)
178 *error = EINVAL;
179 return (NULL);
181 bid = malloc(strlen(xaction->sip_xaction_branch_id) + 1);
182 if (bid == NULL) {
183 if (error != NULL)
184 *error = ENOMEM;
185 return (NULL);
187 (void) strncpy(bid, xaction->sip_xaction_branch_id,
188 strlen(xaction->sip_xaction_branch_id));
189 bid[strlen(xaction->sip_xaction_branch_id)] = '\0';
190 return (bid);
194 * Get the transaction state
197 sip_get_trans_state(sip_transaction_t trans, int *error)
199 sip_xaction_t *xaction = (sip_xaction_t *)trans;
201 if (error != NULL)
202 *error = 0;
203 if (xaction == NULL) {
204 if (error != NULL)
205 *error = EINVAL;
206 return (NULL);
208 return (xaction->sip_xaction_state);