1 /*	$Id: libarms_resource.h 20800 2012-01-19 05:13:45Z m-oki $	*/
2 
3 /*
4  * Copyright (c) 2012, Internet Initiative Japan, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __LIBARMS_RESOURCE_H__
31 #define __LIBARMS_RESOURCE_H__
32 
33 #ifdef HAVE_SIGNAL
34 #include <signal.h>
35 #endif
36 #include <time.h>
37 
38 #include <libarms.h>
39 #include <libarms_param.h>
40 #include <lsconfig.h>
41 #include <armsd_conf.h> /* for ACMI */
42 #include <libhb.h>
43 
44 #define MAX_METHOD_INFO 5
45 /*
46  * Global Resource repository for libarms
47  */
48 typedef struct arms_context {
49 	/* Library configurations */
50 	time_t timeout;			/* Global timeout value */
51 	size_t fragment;		/* Data fragment size */
52 	arms_callback_tbl_t callbacks;	/* Callback functions */
53 	void *udata;			/* User data for callbacks */
54 
55 	/* Certifications */
56 	char root_ca_cert[ARMS_MAX_PEM_LEN];
57 	char sa_cert[ARMS_MAX_PEM_LEN];
58 	char sa_key[ARMS_MAX_PEM_LEN];
59 
60 	/* Client ID */
61 	distribution_id_t dist_id;
62 	char version[ARMS_MAX_VER_LEN + 1];
63 	char description[ARMS_MAX_DESC_LEN + 1];
64 	char error_reason[ARMS_MAX_DESC_LEN];
65 
66 	/* LS Access Info */
67 	ls_config_t *lsconf;
68 
69 	/* RS Access Info */
70 	char rs_endpoint[128];
71 	char *rs_pull_url[MAX_RS_INFO];		/* for method-query dst */
72 	int rs_pull_1st;
73 	int last_line;
74 
75 	/* LS and RS preshared key */
76 	char ls_preshared_key[64+1];
77 	char rs_preshared_key[64+1];
78 
79 	/* SA Access Info */
80 	int line_af;
81 	int sa_af;
82 	char sa_address[128];
83 	char push_endpoint[128];  /* XXX: */
84 	/* endpoint information */
85 	int server_port;
86 
87 	/* proposals */
88 	int proposed_push_port;
89 	int proposed_push_timeout;
90 
91 	int confirm_id;
92 
93 	/* push method information */
94 	int nmethods;
95 	int method_info[MAX_METHOD_INFO];
96 	int cur_method;
97 
98 	/* push information */
99 	char *rs_push_address[MAX_RS_INFO];	/* for start-req src */
100 	char *rs_tunnel_url[MAX_RS_INFO];	/* for ssl tunnel */
101 	int rs_tunnel_1st;
102 	int tunnel_echo_interval;
103 
104 	/* heartbeat info */
105 	int num_of_hbt;
106 	arms_hbt_info_t hbt_info[MAX_HBT_INFO];
107 	hb_context_t hb_ctx;
108 	int hb_running;
109 
110 	/* Configutaion DB */
111 	ACMI *acmi;
112 
113 	/* HTTP version (0=HTTP/1.0, 1=HTTP/1.1) */
114 	int http_preferred_version;
115 
116 	/* HTTP proxy server information */
117 	int proxy_is_available;
118 	char proxy_url[128];
119 
120 #ifdef HAVE_SIGNAL
121 	struct sigaction oldact;	/* signal() management */
122 #endif
123 	char *trigger;			/* Trigger inrfomation */
124 	int result;			/* Result information */
125 	struct timeval app_timeout;	/* app_event_cb timeout value */
126 
127 	size_t bufsiz[1];
128 } libarms_res_t;
129 
130 /* like distid2str, but buffer is statically allocated. */
131 char *strdistid(distribution_id_t *src);
132 
133 /* 1234-5678-9abc-def0:... */
134 int distid2str(distribution_id_t *src, char *dst, int len);
135 
136 /* 123456789abcdef... */
137 int distid2hex(distribution_id_t *src, char *dst, int len);
138 
139 
140 arms_context_t *arms_alloc_context(void);
141 arms_context_t *arms_get_context(void);
142 void arms_free_context(void);
143 
144 void arms_sleep(unsigned int);
145 
146 void arms_free_hbtinfo(arms_context_t *);
147 void arms_free_rsinfo(arms_context_t *);
148 void arms_free_rs_tunnel_url(arms_context_t *);
149 
150 struct timeval;
151 int arms_ls_pull(arms_context_t *, const char *, struct timeval *);
152 int arms_rs_pull(arms_context_t *, const char *, struct timeval *);
153 
154 int arms_is_running_configure(arms_context_t *);
155 
156 void arms_hb_start_loop(arms_context_t *);
157 
158 #endif /* __LIBARMS_RESOURCE_H__ */
159