annotate extensions/app_test/atst_cli.c @ 98:d5951258be1b

Some cleanups
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 08 Dec 2009 11:10:17 +0900
parents 3910804c84db
children bc07ebb58e98
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 * *
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2009, WIDE Project and NICT *
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
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 #include "app_test.h"
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
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 static struct session_handler * atst_cli_reg = NULL;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 struct atst_mess_info {
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 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 static void atst_cb_ans(void * data, struct msg ** msg)
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 struct atst_mess_info * mi = NULL;
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
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 CHECK_FCT_DO( fd_sess_state_retrieve( atst_cli_reg, sess, &mi ), return );
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 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 CHECK_FCT_DO( fd_msg_search_avp ( *msg, atst_avp, &avp), return );
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 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 CHECK_FCT_DO( fd_msg_search_avp ( *msg, atst_res_code, &avp), return );
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 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 CHECK_FCT_DO( fd_msg_search_avp ( *msg, atst_origin_host, &avp), return );
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 );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 fprintf(stderr, "From '%.*s' ", hdr->avp_value->os.len, hdr->avp_value->os.data);
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 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 CHECK_FCT_DO( fd_msg_search_avp ( *msg, atst_origin_realm, &avp), return );
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 );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 fprintf(stderr, "('%.*s') ", hdr->avp_value->os.len, hdr->avp_value->os.data);
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 */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
138 static void atst_cli_test_message(void)
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;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 struct atst_mess_info * mi = NULL;
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 */
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
149 CHECK_FCT_DO( fd_msg_new( atst_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 */
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
152 CHECK_FCT_DO( fd_sess_new( &sess, fd_g_config->cnf_diamid, "app_test", 8 ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 /* Create the random value to store with the session */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 mi = malloc(sizeof(struct atst_mess_info));
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156 if (mi == NULL) {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 fd_log_debug("malloc failed: %s", strerror(errno));
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
158 goto out;
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 }
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 mi->randval = (int32_t)random();
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163 /* Now set all AVPs values */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 /* Session-Id */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 char * sid;
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
168 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
169 CHECK_FCT_DO( fd_msg_avp_new ( atst_sess_id, 0, &avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 val.os.data = sid;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 val.os.len = strlen(sid);
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
172 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
173 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
174
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175 }
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 /* Set the Destination-Realm AVP */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
178 {
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
179 CHECK_FCT_DO( fd_msg_avp_new ( atst_dest_realm, 0, &avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
180 val.os.data = (unsigned char *)(atst_conf->dest_realm);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
181 val.os.len = strlen(atst_conf->dest_realm);
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
182 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
183 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
184 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
186 /* Set the Destination-Host AVP if needed*/
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
187 if (atst_conf->dest_host) {
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
188 CHECK_FCT_DO( fd_msg_avp_new ( atst_dest_host, 0, &avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
189 val.os.data = (unsigned char *)(atst_conf->dest_host);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
190 val.os.len = strlen(atst_conf->dest_host);
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
191 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
192 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
193 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
194
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
195 /* Set Origin-Host & Origin-Realm */
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
196 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
197
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
199 /* Set the Test-AVP AVP */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
200 {
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
201 CHECK_FCT_DO( fd_msg_avp_new ( atst_avp, 0, &avp ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
202 val.i32 = mi->randval;
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
203 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
204 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
205 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
206
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
207 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
208
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
209 /* Store this value in the session */
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
210 CHECK_FCT_DO( fd_sess_state_store ( atst_cli_reg, sess, &mi ), goto out );
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
211
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
212 /* Log sending the message */
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
213 fprintf(stderr, "SEND %x to '%s' (%s)\n", mi->randval, atst_conf->dest_realm, atst_conf->dest_host?:"-" );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
214 fflush(stderr);
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 /* Send the request */
98
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
217 CHECK_FCT_DO( fd_msg_send( &req, atst_cb_ans, mi ), goto out );
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
218
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
219 out:
d5951258be1b Some cleanups
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 93
diff changeset
220 TRACE_DEBUG(FULL, "Client function terminated");
93
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
221 return;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
222 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
223
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
224 int atst_cli_init(void)
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
225 {
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
226 CHECK_FCT( fd_sess_handler_create(&atst_cli_reg, free) );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
227
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
228 CHECK_FCT( atst_sig_init(atst_cli_test_message) );
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
229
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
230 return 0;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
231 }
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
232
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
233 void atst_cli_fini(void)
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 (void) fd_sess_handler_destroy(&atst_cli_reg);
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
236
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
237 atst_sig_fini();
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
238
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
239 return;
3910804c84db Ported the app_test application
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
240 };
"Welcome to our mercurial repository"