annotate extensions/test_app/ta_cli.c @ 706:4ffbc9f1e922

Large UNTESTED commit with the following changes: * Improved DiameterIdentity handling (esp. interationalization issues), and improve efficiency of some string operations in peers, sessions, and dictionary modules (closes #7) * Cleanup in the session module to free only unreferenced sessions (#16) * Removed fd_cpu_flush_cache(), replaced by more robust alternatives. * Improved peer state machine algorithm to counter SCTP multistream race condition.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 09 Feb 2011 15:26:58 +0900
parents 2e94ef0515d7
children 4a9f08d6b6ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
662
2e94ef0515d7 Updated copyright information
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 658
diff changeset
5 * Copyright (c) 2011, WIDE Project and NICT *
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* Create and send a message, and receive it */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 /* Note that we use both sessions and the argument to answer callback to pass the same value.
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39 * This is just for the purpose of checking everything went OK.
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
42 #include "test_app.h"
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
44 #include <stdio.h>
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
45
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
46 static struct session_handler * ta_cli_reg = NULL;
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
48 struct ta_mess_info {
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 int32_t randval; /* a random value to store in Test-AVP */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50 struct timespec ts; /* Time of sending the message */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51 } ;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 /* Cb called when an answer is received */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
54 static void ta_cb_ans(void * data, struct msg ** msg)
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 {
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
56 struct ta_mess_info * mi = NULL;
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 struct timespec ts;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 struct session * sess;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59 struct avp * avp;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 struct avp_hdr * hdr;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), return );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 /* Search the session, retrieve its data */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 int new;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &sess, &new), return );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68 ASSERT( new == 0 );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
70 CHECK_FCT_DO( fd_sess_state_retrieve( ta_cli_reg, sess, &mi ), return );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 TRACE_DEBUG( INFO, "%p %p", mi, data);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 ASSERT( (void *)mi == data );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 /* Now log content of the answer */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 fprintf(stderr, "RECV ");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78 /* Value of Test-AVP */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
79 CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_avp, &avp), return );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 if (avp) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 fprintf(stderr, "%x (%s) ", hdr->avp_value->i32, (hdr->avp_value->i32 == mi->randval) ? "Ok" : "PROBLEM");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 } else {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 fprintf(stderr, "no_Test-AVP ");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 /* Value of Result Code */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
88 CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_res_code, &avp), return );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 if (avp) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90 CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 fprintf(stderr, "Status: %d ", hdr->avp_value->i32);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92 } else {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 fprintf(stderr, "no_Result-Code ");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96 /* Value of Origin-Host */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
97 CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_origin_host, &avp), return );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 if (avp) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
406
345f3541df81 Fix a few additional warnings on 64bits arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
100 fprintf(stderr, "From '%.*s' ", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 } else {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102 fprintf(stderr, "no_Origin-Host ");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 /* Value of Origin-Realm */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
106 CHECK_FCT_DO( fd_msg_search_avp ( *msg, ta_origin_realm, &avp), return );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 if (avp) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108 CHECK_FCT_DO( fd_msg_avp_hdr( avp, &hdr ), return );
406
345f3541df81 Fix a few additional warnings on 64bits arch
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 403
diff changeset
109 fprintf(stderr, "('%.*s') ", (int)hdr->avp_value->os.len, hdr->avp_value->os.data);
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110 } else {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
111 fprintf(stderr, "no_Origin-Realm ");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
112 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
113
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
114 /* Now compute how long it took */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
115 if (ts.tv_nsec > mi->ts.tv_nsec) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 fprintf(stderr, "in %d.%06ld sec",
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 (int)(ts.tv_sec - mi->ts.tv_sec),
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 (long)(ts.tv_nsec - mi->ts.tv_nsec) / 1000);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 } else {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 fprintf(stderr, "in %d.%06ld sec",
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 (int)(ts.tv_sec + 1 - mi->ts.tv_sec),
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122 (long)(1000000000 + ts.tv_nsec - mi->ts.tv_nsec) / 1000);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 fprintf(stderr, "\n");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 fflush(stderr);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128 /* Free the message */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129 CHECK_FCT_DO(fd_msg_free(*msg), return);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
130 *msg = NULL;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
132 free(mi);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
133
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
134 return;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
135 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
136
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
137 /* Create a test message */
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 639
diff changeset
138 static void ta_cli_test_message()
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
139 {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
140 struct msg * req = NULL;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
141 struct avp * avp;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
142 union avp_value val;
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
143 struct ta_mess_info * mi = NULL, *svg;
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 struct session *sess = NULL;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 TRACE_DEBUG(FULL, "Creating a new message for sending.");
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148 /* Create the request from template */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
149 CHECK_FCT_DO( fd_msg_new( ta_cmd_r, MSGFL_ALLOC_ETEID, &req ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151 /* Create a new session */
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
152 #define TEST_APP_SID_OPT "app_test"
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
153 CHECK_FCT_DO( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 /* Create the random value to store with the session */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
156 mi = malloc(sizeof(struct ta_mess_info));
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 if (mi == NULL) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158 fd_log_debug("malloc failed: %s", strerror(errno));
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
159 goto out;
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
160 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 mi->randval = (int32_t)random();
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 /* Now set all AVPs values */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 /* Session-Id */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 {
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
168 os0_t sid;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
169 size_t sidlen;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
170 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid, &sidlen ), goto out );
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
171 CHECK_FCT_DO( fd_msg_avp_new ( ta_sess_id, 0, &avp ), goto out );
706
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
172 val.os.data = sid;
4ffbc9f1e922 Large UNTESTED commit with the following changes:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 662
diff changeset
173 val.os.len = sidlen;
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
174 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
175 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_FIRST_CHILD, avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
177 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
179 /* Set the Destination-Realm AVP */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 {
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
181 CHECK_FCT_DO( fd_msg_avp_new ( ta_dest_realm, 0, &avp ), goto out );
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
182 val.os.data = (unsigned char *)(ta_conf->dest_realm);
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
183 val.os.len = strlen(ta_conf->dest_realm);
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
184 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
185 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
188 /* Set the Destination-Host AVP if needed*/
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
189 if (ta_conf->dest_host) {
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
190 CHECK_FCT_DO( fd_msg_avp_new ( ta_dest_host, 0, &avp ), goto out );
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
191 val.os.data = (unsigned char *)(ta_conf->dest_host);
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
192 val.os.len = strlen(ta_conf->dest_host);
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
193 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
194 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
196
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 /* Set Origin-Host & Origin-Realm */
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
198 CHECK_FCT_DO( fd_msg_add_origin ( req, 0 ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199
127
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
200 /* Set the User-Name AVP if needed*/
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
201 if (ta_conf->user_name) {
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
202 CHECK_FCT_DO( fd_msg_avp_new ( ta_user_name, 0, &avp ), goto out );
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
203 val.os.data = (unsigned char *)(ta_conf->user_name);
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
204 val.os.len = strlen(ta_conf->user_name);
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
205 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
206 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
8ee43cf85a5f Added User-Name AVP in test_app extension
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 121
diff changeset
207 }
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
208
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 /* Set the Test-AVP AVP */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
210 {
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
211 CHECK_FCT_DO( fd_msg_avp_new ( ta_avp, 0, &avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 val.i32 = mi->randval;
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
213 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
214 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_LAST_CHILD, avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
215 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
216
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
217 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &mi->ts), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
218
99
bc07ebb58e98 Fix segfault
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 98
diff changeset
219 /* Keep a pointer to the session data for debug purpose, in real life we would not need it */
bc07ebb58e98 Fix segfault
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 98
diff changeset
220 svg = mi;
bc07ebb58e98 Fix segfault
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 98
diff changeset
221
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 /* Store this value in the session */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
223 CHECK_FCT_DO( fd_sess_state_store ( ta_cli_reg, sess, &mi ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 /* Log sending the message */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
226 fprintf(stderr, "SEND %x to '%s' (%s)\n", svg->randval, ta_conf->dest_realm, ta_conf->dest_host?:"-" );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227 fflush(stderr);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229 /* Send the request */
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
230 CHECK_FCT_DO( fd_msg_send( &req, ta_cb_ans, svg ), goto out );
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
231
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
232 out:
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 return;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
234 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
235
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
236 int ta_cli_init(void)
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237 {
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 406
diff changeset
238 CHECK_FCT( fd_sess_handler_create(&ta_cli_reg, free, NULL) );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
239
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 639
diff changeset
240 CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.cli", ta_cli_test_message ) );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
241
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
242 return 0;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
243 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
244
120
d7acdc46134d Renamed several extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 99
diff changeset
245 void ta_cli_fini(void)
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
246 {
658
f198d16fa7f4 Initial commit for 1.1.0:
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 639
diff changeset
247 // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
248
639
95a784729cac Added new opaque pointer to fd_sess_handler_create and fd_disp_register for usability. Bumped API version number.
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 406
diff changeset
249 CHECK_FCT_DO( fd_sess_handler_destroy(&ta_cli_reg, NULL), /* continue */ );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
250
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
251 return;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
252 };
"Welcome to our mercurial repository"