1 /* $Id: libarms.h 20975 2012-02-01 05:29:20Z 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 /* 31 * ARMS Client Library 32 */ 33 #ifndef __LIBARMS_H__ 34 #define __LIBARMS_H__ 35 #ifdef __cplusplus 36 extern "C" { 37 #endif /* __cplusplus */ 38 39 /* ARMS Global Parameters: Only for reference, DON'T CHANGE */ 40 41 /* 42 * API spec. 43 * 1: initial version. pull only. 44 * 2: push operation supported. 45 * 3: app_event_cb supported. 46 * 4: 'next' parameter in command_cb supported. 47 * 5: need to call arms_push_method_query before arms_event_loop 48 * - binary support (upper compatible with 5. no change version) 49 * 6: get_status_cb request parameter is added. 50 * -: ipv6 support and some information function is added. 51 * 7: store_statistics_cb supported. 52 */ 53 #define ARMS_API_VERSION 7 54 55 /* 56 * library version 57 */ 58 #define ARMS_LIB_VERSION_MAJOR 5 59 #define ARMS_LIB_VERSION_MINOR 01 60 #define ARMS_LIB_VERSION_DESC "Release" 61 62 /* 63 * compatibility macro. 64 */ 65 #define ARMS_LIBPULL_VERSION ARMS_API_VERSION 66 #define ARMS_LIBPULL_VERSION_MAJOR ARMS_LIB_VERSION_MAJOR 67 #define ARMS_LIBPULL_VERSION_MINOR ARMS_LIB_VERSION_MINOR 68 #define ARMS_LIBPULL_VERSION_DESC ARMS_LIB_VERSION_DESC 69 70 /* 71 * ARMS prococol related macro. 72 */ 73 74 /* 75 * about major version of the protocol: 76 * 1: pull only (initial release) 77 * 2: push support 78 * 3: https-tunnel support (not used) 79 * 4: binary data support 80 */ 81 #define ARMS_PROTOCOL_VERSION_MAJOR 4 82 #define ARMS_PROTOCOL_VERSION_MINOR 0 83 #define ARMS_PROTOCOL_VERSION ARMS_PROTOCOL_VERSION_MAJOR 84 85 #define ARMS_MAX_TIMEOUT 60 * 60 * 24 * 1 /* 1 day */ 86 #define ARMS_DEFAULT_TIMEOUT 60 * 60 * 6 /* 6 hours */ 87 #define ARMS_MIN_TIMEOUT 60 /* 60 sec. */ 88 #define ARMS_MAX_LINE 5 /* number of line config */ 89 #define ARMS_MAX_PEM_LEN 5 * 1024 /* bytes */ 90 #define ARMS_MAX_DESC_LEN 32 /* bytes */ 91 #define ARMS_MAX_VER_LEN 32 /* bytes */ 92 #define ARMS_DISTID_LEN 128 / 8 /* bytes */ 93 94 /* SSL/TCP/IP level timeout value (sec) */ 95 #define ARMS_WAIT_FOR_SENDING 30 96 97 /* PPPoE Parameters */ 98 #define MAX_PPP_ID 36 99 #define MAX_PPP_PASS 36 100 101 /* Mobile Parameters */ 102 #define MAX_MOBILE_TEL_LEN 40 103 #define MAX_MOBILE_APN_LEN 100 104 #define MAX_MOBILE_PDP_LEN 8 /* "ppp" or "ip" */ 105 #define MAX_MOBILE_PPP_ID 128 106 #define MAX_MOBILE_PPP_PASS 128 107 108 /* Result */ 109 #define ARMS_RV_TYPE_SHIFT(t) ((t)<<24) 110 #define ARMS_RV_DATA_MASK(rv) ((rv)&0x00ffffff) 111 #define ARMS_RV_TYPE_ERROR 0 112 #define ARMS_RV_TYPE_BYTES 1 113 #define ARMS_RESULT_BYTES(n) (ARMS_RV_TYPE_SHIFT(ARMS_RV_TYPE_BYTES) |\ 114 ARMS_RV_DATA_MASK(n)) 115 116 #define ARMS_RV_TYPE(rv) (((rv)&0xff000000)>>24) 117 #define ARMS_RESULT_IS_ERROR(n) ((n) != 0 &&\ 118 ARMS_RV_TYPE(n) != ARMS_RV_TYPE_BYTES) 119 #define ARMS_RESULT_IS_BYTES(n) (ARMS_RV_TYPE(n) == ARMS_RV_TYPE_BYTES) 120 121 /* Error Code */ 122 #define ARMS_ERR_LVL_MASK 0xff00 123 #define ARMS_ERR_CODE_MASK 0x00ff 124 #define ARMS_ERR_LVL(code) ( ((code) & ARMS_ERR_LVL_MASK) >> 8) 125 #define ARMS_ERR_TYPE(code) ( ((code) & ARMS_ERR_CODE_MASK) ) 126 #define ARMS_ERR_CODE(lvl, type) ( ((lvl) << 8) | (type) ) 127 /* Error Level */ 128 #define ARMS_ELVL_NOERR 0 129 #define ARMS_ELVL_LOW 1 130 #define ARMS_ELVL_MID 2 131 #define ARMS_ELVL_HIGH 3 132 #define ARMS_ELVL_FATAL 4 133 /* Error Type */ 134 #define ARMS_EUNDEF 0 135 /* protocol errors */ 136 #define ARMS_EPROTO_MAXRETRY 101 137 #define ARMS_EPROTO_DONTRETRY 102 138 #define ARMS_EPROTO_TIMEOUT 103 139 #define ARMS_EPROTO_REBOOT 104 140 #define ARMS_EPROTO_PULL 105 141 #define ARMS_EPROTO_UPDATE 106 142 #define ARMS_EPROTO_PUSH 108 143 144 /* line errors */ 145 #define ARMS_ELINE_TIMEOUT 201 146 #define ARMS_ELINE_AUTH 202 147 148 /* library errors */ 149 #define ARMS_ELIB_CALLBACK 251 150 #define ARMS_ELIB_INVAL 252 151 #define ARMS_ELIB_SYSTEM 253 152 #define ARMS_ELIB_SIZE 254 153 #define ARMS_ELIB_NOCHANGE 255 154 #define ARMS_ELIB_EXIST 256 155 156 /* heartbeat errors */ 157 158 /* Protocol error(library -> application) */ 159 #define ARMS_EFATAL \ 160 ARMS_ERR_CODE(ARMS_ELVL_FATAL, ARMS_EUNDEF) 161 #define ARMS_ETIMEOUT \ 162 ARMS_ERR_CODE(ARMS_ELVL_LOW, ARMS_EPROTO_TIMEOUT) 163 #define ARMS_EMAXRETRY \ 164 ARMS_ERR_CODE(ARMS_ELVL_MID, ARMS_EPROTO_MAXRETRY) 165 #define ARMS_EDONTRETRY \ 166 ARMS_ERR_CODE(ARMS_ELVL_FATAL, ARMS_EPROTO_DONTRETRY) 167 #define ARMS_ECALLBACK \ 168 ARMS_ERR_CODE(ARMS_ELVL_FATAL, ARMS_ELIB_CALLBACK) 169 #define ARMS_ESYSTEM \ 170 ARMS_ERR_CODE(ARMS_ELVL_FATAL, ARMS_ELIB_SYSTEM) 171 #define ARMS_EINVAL \ 172 ARMS_ERR_CODE(ARMS_ELVL_FATAL, ARMS_ELIB_INVAL) 173 #define ARMS_EREBOOT \ 174 ARMS_ERR_CODE(ARMS_ELVL_NOERR, ARMS_EPROTO_REBOOT) 175 #define ARMS_EPULL \ 176 ARMS_ERR_CODE(ARMS_ELVL_NOERR, ARMS_EPROTO_PULL) 177 #define ARMS_ESIZE \ 178 ARMS_ERR_CODE(ARMS_ELVL_NOERR, ARMS_ELIB_SIZE) 179 #define ARMS_ENOCHANGE \ 180 ARMS_ERR_CODE(ARMS_ELVL_NOERR, ARMS_ELIB_NOCHANGE) 181 #define ARMS_EPUSH \ 182 ARMS_ERR_CODE(ARMS_ELVL_NOERR, ARMS_EPROTO_PUSH) 183 #define ARMS_EEXIST \ 184 ARMS_ERR_CODE(ARMS_ELVL_FATAL, ARMS_ELIB_EXIST) 185 186 187 /* Log Code */ 188 #define ARMS_LOG_OLD_ST_MASK 0xff0000 189 #define ARMS_LOG_NEW_ST_MASK 0x00ff00 190 #define ARMS_LOG_TYPE_MASK 0x0000ff 191 #define ARMS_LOG_OLD_ST(code) ( ((code) & ARMS_LOG_OLD_ST_MASK) >> 16) 192 #define ARMS_LOG_NEW_ST(code) ( ((code) & ARMS_LOG_NEW_ST_MASK) >> 8) 193 #define ARMS_LOG_TYPE(code) ( ((code) & ARMS_LOG_TYPE_MASK) ) 194 #define ARMS_LOG_CODE(old_st, new_st, type) \ 195 ( ((old_st) << 16) | ((new_st) << 8) | (type) ) 196 197 /* State */ 198 #define ARMS_ST_INITIAL 0 199 #define ARMS_ST_LSPULL 1 200 #define ARMS_ST_RSPULL 2 201 #define ARMS_ST_PULLDONE 3 202 #define ARMS_ST_BOOT_FAIL 4 203 204 #define ARMS_ST_PUSH_INITIAL 10 205 #define ARMS_ST_PUSH_SENDREADY 11 206 #define ARMS_ST_PUSH_WAIT 12 207 #define ARMS_ST_PUSH_ADDTRANS 13 208 #define ARMS_ST_PUSH_EXECTRANS 14 209 #define ARMS_ST_PUSH_TERM 15 210 #define ARMS_ST_PUSH_REBOOT 16 211 212 /* 213 * log type and coes 214 */ 215 #define ARMS_LOG_INFO 0 /* 0 - 99 */ 216 #define ARMS_LOG_ERROR 100 /* 100 - 199 */ 217 #define ARMS_LOG_DEBUG 200 218 219 /* STM Information Log */ 220 #define ARMS_LOG_EFALLBACK 1 /* Fallback to previous state */ 221 222 /* LS and RS access */ 223 #define ARMS_LOG_ILS_ACCESS_START 2 /* Connecting to LS */ 224 #define ARMS_LOG_ILS_ACCESS_END 3 /* LS Access done. */ 225 226 #define ARMS_LOG_IRS_ACCESS_START 5 /* Connecting to RS */ 227 #define ARMS_LOG_IRS_ACCESS_END 6 /* RS Access done */ 228 229 #define ARMS_LOG_ILS_ACCESS_RETRY 8 /* LS retry */ 230 #define ARMS_LOG_IRS_ACCESS_RETRY 9 /* RS retry */ 231 232 /* Line Configuration */ 233 #define ARMS_LOG_ILINE_CONNECTED 21 /* line connected */ 234 #define ARMS_LOG_ILINE_DISCONNECTED 25 /* line connected */ 235 236 /* HTTP Access */ 237 #define ARMS_LOG_IHTTP_CONNECT_START 30 /* Connecting to httpd */ 238 #define ARMS_LOG_IHTTP_CONNECT_END 31 /* httpd Connected */ 239 #define ARMS_LOG_IHTTP_LISTEN_START 32 /* Ready to answer push */ 240 #define ARMS_LOG_IHTTP_ACCEPT 33 /* Accept connection */ 241 #define ARMS_LOG_IHTTP_CLOSE 34 /* Done push */ 242 #define ARMS_LOG_IHTTP_RETRY 35 /* retry to send */ 243 #define ARMS_LOG_IHTTP_PROXY_CONNECTED 36 /* connected to proxy */ 244 245 /* SSL */ 246 #define ARMS_LOG_ISSL_CONNECTED 40 /* connection established */ 247 248 /* ARMS transaction */ 249 #define ARMS_LOG_ITRANSACTION_RETRY 50 /* retry transaction */ 250 251 /* tunnel */ 252 #define ARMS_LOG_ITUNNEL_CONNECTED 60 /* connection established */ 253 #define ARMS_LOG_ITUNNEL_CLOSED 61 /* clsoed */ 254 #define ARMS_LOG_ITUNNEL_RETRY 62 /* retry */ 255 #define ARMS_LOG_ITUNNEL_READY_TO_PUSH 63 /* ready to push */ 256 257 /* protocol */ 258 #define ARMS_LOG_IPROTO_CONFIRM_START 70 /* start confirmation */ 259 #define ARMS_LOG_IPROTO_CONFIRM_DONE 71 /* done confirmation */ 260 #define ARMS_LOG_IPROTO_CONFIRM_FAILED 72 /* confirmation failed */ 261 #define ARMS_LOG_IPROTO_CONFIG_COMMIT 73 /* commit config */ 262 #define ARMS_LOG_IPROTO_CONFIG_ROLLBACK 74 /* rollback config */ 263 264 /* heartbeat */ 265 #define ARMS_LOG_IHEARTBEAT_START 80 /* start heartbeat */ 266 #define ARMS_LOG_IHEARTBEAT_STOP 81 /* stop heartbeat */ 267 #define ARMS_LOG_IHEARTBEAT_SERVER 82 /* heartbeat server */ 268 269 /* Push methods */ 270 #define ARMS_LOG_IPUSH_METHOD_SIMPLE 90 /* push method: simple */ 271 #define ARMS_LOG_IPUSH_METHOD_TUNNEL 91 /* push method: tunnel */ 272 273 /* Errors (old_st = 0, new_st = 0, level = high) */ 274 #define ARMS_LOG_EURL 100 /* Invalid URL */ 275 #define ARMS_LOG_EHOST 101 /* Unknown host */ 276 #define ARMS_LOG_ESOCKET 102 /* socket() error */ 277 #define ARMS_LOG_ECONNECT 103 /* connect() error */ 278 #define ARMS_LOG_ENETNOMEM 104 /* memory exhautsted */ 279 #define ARMS_LOG_EHTTP 105 /* http level error */ 280 #define ARMS_LOG_ECERTIFICATE 106 /* ssl cetificate error */ 281 #define ARMS_LOG_ENETTIMEOUT 107 /* network layer timeout */ 282 #define ARMS_LOG_ECALLBACK 108 /* error from callback func. */ 283 #define ARMS_LOG_ESSL 109 /* OpenSSL error */ 284 285 #define ARMS_LOG_EROLLBACK 110 /* rollback failure */ 286 #define ARMS_LOG_ERETRY 111 /* retry is over */ 287 288 #define ARMS_LOG_EFATAL 112 /* fatal error */ 289 #define ARMS_LOG_EBASE64_DECODE 113 /* base64 decode error */ 290 #define ARMS_LOG_EINITIAL_CONFIG 114 /* initial config error */ 291 292 #define ARMS_LOG_ELINE_AUTH_FAIL 120 /* Authentication failure */ 293 #define ARMS_LOG_ELINE_TIMEOUT 121 /* Timeout */ 294 #define ARMS_LOG_ELINE_NOTAVAIL 122 /* not available line */ 295 296 #define ARMS_LOG_ELS_ACCESS_FAIL 130 /* Cannot access to LS */ 297 #define ARMS_LOG_ERS_ACCESS_FAIL 131 /* Cannot access to RS */ 298 #define ARMS_LOG_EHB_NO_ALGORITHM 132 /* invalid algorithm */ 299 300 /* Config Callback */ 301 #define ARMS_FRAG_CONTINUE 0x00 302 #define ARMS_FRAG_FIRST 0x01 303 #define ARMS_FRAG_FINISHED 0x02 304 305 /* Config callback action */ 306 #define ARMS_PULL_STORE_CONFIG 1 307 #define ARMS_PUSH_STORE_CONFIG 2 308 #define ARMS_PUSH_EXEC_STORED_CONFIG 3 309 #define ARMS_PUSH_REVERT_CONFIG 4 310 #define ARMS_REMOVE_MODULE 5 311 312 /* Read config callback type */ 313 #define ARMS_CONFIG_CANDIDATE 1 314 #define ARMS_CONFIG_RUNNING 2 315 #define ARMS_CONFIG_BACKUP 3 316 317 /* Command callback action */ 318 #define ARMS_PUSH_CLEAR_STATUS 1 319 #define ARMS_PUSH_PING 2 320 #define ARMS_PUSH_TRACEROUTE 3 321 #define ARMS_PUSH_DUMP_DEBUG 4 322 #define ARMS_PUSH_MD_COMMAND 5 323 324 /* Trigger values */ 325 #define ARMS_TRIGGER_CONFIG_ERROR 1 326 #define ARMS_TRIGGER_SYNC_FAILED 2 327 328 /* 329 * Data types 330 */ 331 332 /* ARMS context structure for state machine (opaque for user) */ 333 typedef struct arms_context arms_context_t; 334 335 /* Distribution ID (not packed: needs care of alignment) */ 336 typedef struct arms_distribution_id { 337 uint16_t version; 338 uint32_t vendor_code; 339 uint16_t sa_type; 340 uint64_t sa_code; 341 } distribution_id_t; 342 343 /* Methods */ 344 enum arms_push_method_type { 345 ARMS_PUSH_METHOD_UNKNOWN, 346 ARMS_PUSH_METHOD_SIMPLE, 347 ARMS_PUSH_METHOD_TUNNEL, 348 349 ARMS_PUSH_METHOD_LAST, 350 }; 351 352 /* Line management */ 353 enum arms_line_types { 354 ARMS_LINE_NONE = 0, 355 ARMS_LINE_ANONPPPOE, 356 ARMS_LINE_PPPOE, 357 ARMS_LINE_DHCP, 358 ARMS_LINE_ANONMOBILE, 359 ARMS_LINE_MOBILE, 360 ARMS_LINE_STATIC, 361 ARMS_LINE_RA, 362 363 ARMS_LINE_LAST 364 }; 365 366 enum arms_line_actions { 367 ARMS_LINE_ACT_NONE = 0, 368 ARMS_LINE_ACT_CONNECT, 369 ARMS_LINE_ACT_DISCONNECT, 370 ARMS_LINE_ACT_STATUS, 371 372 ARMS_LINE_ACT_LAST 373 }; 374 375 enum arms_line_result { 376 ARMS_LINE_NEEDPOLL = 0, /* now conncting, need polling */ 377 ARMS_LINE_CONNECTED, /* connected */ 378 ARMS_LINE_DISCONNECTED, /* disconnected */ 379 ARMS_LINE_TIMEOUT, /* failed because of timeout */ 380 ARMS_LINE_AUTHFAIL, /* failed because of authentication */ 381 ARMS_LINE_NOTAVAILABLE, /* failed because of not available */ 382 }; 383 384 enum arms_tunnel_status { 385 ARMS_TUNNEL_INACTIVE = 0, 386 ARMS_TUNNEL_ACTIVE 387 }; 388 389 enum arms_hb_mobile_status { 390 ARMS_HB_MOBILE_RUNNING = 0, 391 ARMS_HB_MOBILE_NOSIGNAL, 392 ARMS_HB_MOBILE_INVALIDDATA, 393 ARMS_HB_MOBILE_NODEVICE, 394 ARMS_HB_MOBILE_ERROR 395 }; 396 397 /* configuration data for anonymous PPPoE connection */ 398 typedef struct arms_line_conf_anonpppoe { 399 int ifindex; 400 } arms_line_conf_anonpppoe_t; 401 402 /* configuration data for PPPoE connection */ 403 typedef struct arms_line_conf_pppoe { 404 int ifindex; 405 char id[MAX_PPP_ID]; 406 char pass[MAX_PPP_PASS]; 407 } arms_line_conf_pppoe_t; 408 409 /* configuration data for DHCP connection */ 410 typedef struct arms_line_conf_dhcp { 411 int ifindex; 412 } arms_line_conf_dhcp_t; 413 414 /* configuration data for anonymous mobile connection */ 415 typedef struct arms_line_conf_anonmobile { 416 int ifindex; 417 } arms_line_conf_anonmobile_t; 418 419 /* configuration data for mobile connection */ 420 typedef struct arms_line_conf_mobile { 421 int ifindex; 422 char telno[MAX_MOBILE_TEL_LEN]; 423 int cid; 424 char apn[MAX_MOBILE_APN_LEN]; 425 char pdp[MAX_MOBILE_PDP_LEN]; 426 char id[MAX_MOBILE_PPP_ID]; 427 char pass[MAX_MOBILE_PPP_PASS]; 428 char ipaddr[48]; /* note: IPv6 strlen == 46 */ 429 } arms_line_conf_mobile_t; 430 431 /* configuration data for static connection */ 432 typedef struct arms_line_conf_static { 433 int ifindex; 434 char ipaddr[48]; /* note: IPv6 strlen == 46 */ 435 } arms_line_conf_static_t; 436 437 /* configuration data for IPv6 RA/SLAAC,RA/DHCPv6-PD */ 438 typedef struct arms_line_conf_ra { 439 int ifindex; 440 } arms_line_conf_ra_t; 441 442 443 /* data type for API */ 444 typedef struct arms_line_description { 445 int type; 446 void *line_conf; 447 } arms_line_desc_t; 448 449 /* for command callback */ 450 typedef struct arms_ping_arg { 451 const char *dst; 452 int count; 453 int size; 454 } arms_ping_arg_t; 455 456 typedef struct arms_ping_report { 457 int success; 458 int failure; 459 } arms_ping_report_t; 460 461 462 typedef struct arms_traceroute_arg { 463 const char *addr; 464 int count; 465 int maxhop; 466 } arms_traceroute_arg_t; 467 468 #define MAX_HOP 256 /* Generally, IP_TTL + 1 */ 469 #define ARMS_TR_STRSIZE 256 470 typedef struct arms_traceroute_info { 471 int hop; 472 char addr[ARMS_TR_STRSIZE]; 473 } arms_traceroute_info_t; 474 475 #define MAX_HBT_INFO 5 476 #define MAX_HBT_ALGORITHMS 3 477 typedef struct arms_hbt_info { 478 const char *host; 479 int port; 480 const char *passphrase; 481 int interval; 482 int numalg; /* number of algorithms */ 483 const char *algorithm[MAX_HBT_ALGORITHMS]; 484 } arms_hbt_info_t; 485 486 #define MAX_RS_INFO 5 487 typedef struct arms_rs_info { 488 const char *host; 489 } arms_rs_info_t; 490 491 typedef struct arms_url { 492 const char *url; 493 } arms_url_t; 494 495 typedef struct arms_connection_info { 496 int method; 497 int af; 498 union { 499 /* simple info */ 500 struct { 501 char sa_address[128]; 502 int sa_port; 503 } simple_info; 504 /* tunnel info */ 505 int tunnel_info[MAX_RS_INFO]; 506 } un; 507 } arms_connection_info_t; 508 509 /* 510 * Prototypes for Callback functions 511 */ 512 typedef int (*arms_config_cb_t)(uint32_t, const char *, const char *, int, const char *, size_t, int, void *); 513 typedef int (*arms_line_ctrl_cb_t)(int, int, void *, void *); 514 typedef int (*arms_state_cb_t)(int, int, void *); 515 typedef int (*arms_log_cb_t)(int, const char *, void *); 516 typedef int (*arms_read_config_cb_t)(uint32_t, int, char *, size_t, int *, void *); 517 typedef int (*arms_get_status_cb_t)(uint32_t, const char *, size_t, char *, size_t, int *, void *); 518 typedef int (*arms_command_cb_t)(uint32_t, int, const char *, size_t, char *, size_t, int *, void *); 519 typedef int (*arms_app_event_cb_t)(void *); 520 typedef int (*arms_hb_store_statistics_t)(arms_context_t *, void *); 521 522 typedef struct arms_callback_tbl { 523 int version; /* = ARMS_API_VERSION */ 524 arms_config_cb_t config_cb; 525 arms_line_ctrl_cb_t line_ctrl_cb; 526 arms_state_cb_t state_cb; 527 arms_log_cb_t log_cb; 528 arms_read_config_cb_t read_config_cb; 529 arms_get_status_cb_t get_status_cb; 530 arms_command_cb_t command_cb; 531 arms_app_event_cb_t app_event_cb; 532 arms_hb_store_statistics_t hb_store_statistics_cb; 533 } arms_callback_tbl_t; 534 535 /* 536 * API functions 537 */ 538 539 /* prepare and finalize */ 540 int arms_init(distribution_id_t *, arms_context_t **); 541 int arms_load_config(arms_context_t *, const char *, size_t); 542 int arms_register_cert(arms_context_t *, const char *); 543 int arms_register_description(arms_context_t *, const char *, const char *); 544 int arms_register_authkey(arms_context_t *, const char *); 545 int arms_set_pull_trigger(arms_context_t *, int); 546 void arms_end(arms_context_t *); 547 548 /* pull */ 549 int arms_pull(arms_context_t *, time_t, size_t, arms_callback_tbl_t *, arms_line_desc_t *, void *); 550 551 /* state dump/restore */ 552 size_t arms_size_of_state(void); 553 int arms_dump_state(arms_context_t *, char *, size_t); 554 int arms_restore_state(arms_context_t *, const char *, size_t); 555 556 /* info */ 557 int arms_get_hbtinfo(arms_context_t *, arms_hbt_info_t *, int); 558 int arms_get_rsinfo(arms_context_t *, arms_rs_info_t *, int); 559 int arms_get_proposed_push_port(arms_context_t *); 560 int arms_get_proposed_push_timeout(arms_context_t *); 561 int arms_get_rs_url(arms_context_t *, arms_url_t *, int); 562 int arms_get_rs_tunnel_url(arms_context_t *, arms_url_t *, int); 563 int arms_get_connection_info(arms_context_t *, arms_connection_info_t *, int); 564 565 /* push */ 566 int arms_push_method_query(arms_context_t *, arms_callback_tbl_t *, void *); 567 int arms_event_loop(arms_context_t *, int, size_t, arms_callback_tbl_t *, void *); 568 569 /* app_event */ 570 const struct timeval *arms_get_app_event_interval(arms_context_t *); 571 int arms_set_app_event_interval(arms_context_t *, const struct timeval *); 572 573 /* http proxy */ 574 int arms_set_https_proxy(arms_context_t *, const char *); 575 576 /* heartbeat */ 577 void arms_hb_start(arms_context_t *); 578 void arms_hb_stop(arms_context_t *); 579 int arms_hb_is_running(arms_context_t *); 580 int arms_hb_set_cpu_usage(arms_context_t *, uint16_t, uint8_t); 581 int arms_hb_set_cpu_detail_usage(arms_context_t *, 582 uint16_t, uint8_t, 583 uint8_t, uint8_t, 584 uint8_t, uint8_t); 585 int arms_hb_set_mem_usage(arms_context_t *, uint16_t, uint64_t, uint64_t); 586 int arms_hb_set_disk_usage(arms_context_t *, uint16_t, uint64_t, uint64_t); 587 int arms_hb_set_traffic_count(arms_context_t *, uint16_t, 588 uint64_t, uint64_t, 589 uint64_t, uint64_t, 590 uint64_t, uint64_t); 591 int arms_hb_set_traffic_rate(arms_context_t *, uint16_t, 592 uint64_t, uint64_t, 593 uint64_t, uint64_t, 594 uint64_t, uint64_t); 595 int arms_hb_set_radiowave(arms_context_t *, uint16_t, 596 uint8_t, uint8_t, 597 uint8_t, uint8_t); 598 599 /* misc functions */ 600 int arms_library_ver_major(void); 601 int arms_library_ver_minor(void); 602 const char * arms_library_ver_string(void); 603 int arms_protocol_ver_major(void); 604 int arms_protocol_ver_minor(void); 605 606 #ifdef __cplusplus 607 } 608 #endif /* __cplusplus */ 609 #endif /* __LIBARMS_H__ */ 610