int main(int argc, char **argv) { mdata_proto_t *mdp; mdata_response_t mdr; string_t *data; const char *errmsg = NULL; if (argc < 2) { errx(MDEC_USAGE_ERROR, "Usage: %s <keyname>", argv[0]); } if (proto_init(&mdp, &errmsg) != 0) { fprintf(stderr, "ERROR: could not initialise protocol: %s\n", errmsg); return (MDEC_ERROR); } if (proto_version(mdp) < 2) { fprintf(stderr, "ERROR: host does not support DELETE\n"); return (MDEC_ERROR); } keyname = strdup(argv[1]); if (proto_execute(mdp, "DELETE", keyname, &mdr, &data) != 0) { fprintf(stderr, "ERROR: could not execute GET\n"); return (MDEC_ERROR); } return (print_response(mdr, data)); }
void mdataPut(const char *keyname, const char *value) { string_t *data; char *errmsg = NULL; mdata_response_t mdr; string_t *req = dynstr_new(); if (initialized_proto == 0) { if (proto_init(&mdp, &errmsg) != 0) { fatal(ERR_MDATA_INIT, "could not initialize metadata: %s\n", errmsg); } initialized_proto = 1; } base64_encode(keyname, strlen(keyname), req); dynstr_appendc(req, ' '); base64_encode(value, strlen(value), req); if (proto_version(mdp) < 2) { fatal(ERR_MDATA_TOO_OLD, "mdata protocol must be >= 2 for PUT"); } if (proto_execute(mdp, "PUT", dynstr_cstr(req), &mdr, &data) != 0) { fatal(ERR_MDATA_FAIL, "failed to PUT"); } dynstr_free(req); dlog("MDATA PUT %s=%s\n", keyname, value); }
void mdataDelete(const char *keyname) { string_t *data; char *errmsg = NULL; mdata_response_t mdr; if (initialized_proto == 0) { if (proto_init(&mdp, &errmsg) != 0) { fatal(ERR_MDATA_INIT, "could not initialize metadata: %s\n", errmsg); } initialized_proto = 1; } if (proto_version(mdp) < 2) { fatal(ERR_MDATA_TOO_OLD, "mdata protocol must be >= 2 for DELETE"); } if (proto_execute(mdp, "DELETE", keyname, &mdr, &data) != 0) { fatal(ERR_MDATA_FAIL, "failed to DELETE"); } dlog("MDATA DELETE %s\n", keyname); }
/** * The structure of the entry point function for one of * the 3 'output' boards. The sensor board will differ slightly in * its running state. */ void main(void) { // initialise stuff proto_init(); while (1) { switch (proto_state()) { case STARTUP: break; case CALIBRATING: break; case RUNNING: if (proto_msg_buff_length()) { msg = proto_msg_buff_pop(); if (msg.command == CMD_SET) { set_steering(msg.data[0]); proto_refresh(); } else { proto_state_error(); } } break; default: // ERROR //broadcast ERROR signal break; } } }
static void init(vfs_dev_t *dev) { dev->state = STATE_NOTHING; dev->scanline_buf = malloc(0); dev->scanline_count = 0; usb_init(dev); proto_init(dev); }
/* * Contact the hypervisor metadata agent and request the value for the provided * key name. Returns a C string if a value is found, NULL if no value is * found, or aborts the program on any other condition. The caller is expected * to call free(3C) on the returned string. */ char * mdataGet(const char *keyname) { char *errmsg = NULL; string_t *mdata = NULL; mdata_response_t mdr; char *out; if (initialized_proto == 0) { if (proto_init(&mdp, &errmsg) != 0) { fatal(ERR_MDATA_INIT, "could not initialize metadata: %s\n", errmsg); } initialized_proto = 1; } if (proto_execute(mdp, "GET", keyname, &mdr, &mdata) != 0) { fatal(ERR_UNEXPECTED, "failed to get metadata for '%s': unknown " "error\n", keyname); } switch (mdr) { case MDR_SUCCESS: if ((out = strdup(dynstr_cstr(mdata))) == NULL) { fatal(ERR_STRDUP, "strdup failure\n"); } dynstr_free(mdata); dlog("MDATA %s=%s\n", keyname, out); return (out); case MDR_NOTFOUND: dlog("INFO no metadata for '%s'\n", keyname); dynstr_free(mdata); return (NULL); case MDR_UNKNOWN: fatal(ERR_MDATA_FAIL, "failed to get metadata for '%s': %s\n", keyname, dynstr_cstr(mdata)); break; case MDR_INVALID_COMMAND: fatal(ERR_MDATA_FAIL, "failed to get metadata for '%s': %s\n", keyname, "host does not support GET"); break; default: fatal(ERR_UNEXPECTED, "GET[%s]: unknown response\n", keyname); break; } /* NOTREACHED */ abort(); return (NULL); }
void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), void (*register_all_handoffs_func)(register_cb cb, gpointer client_data), register_cb cb, gpointer client_data, void (*report_failure)(const char *, va_list), void (*report_open_failure)(const char *, int, gboolean), void (*report_read_failure)(const char *, int), void (*report_write_failure)(const char *, int)) { init_report_err(report_failure, report_open_failure, report_read_failure, report_write_failure); /* initialize memory allocation subsystem */ ep_init_chunk(); se_init_chunk(); /* initialize the GUID to name mapping table */ guids_init(); except_init(); #ifdef HAVE_LIBGNUTLS gnutls_global_init(); #elif defined(HAVE_LIBGCRYPT) gcry_check_version(NULL); #endif tvbuff_init(); tap_init(); prefs_init(); proto_init(register_all_protocols_func, register_all_handoffs_func, cb, client_data); packet_init(); dfilter_init(); final_registration_all_protocols(); host_name_lookup_init(); expert_init(); oids_init(); #ifdef HAVE_LUA_5_1 wslua_init(NULL); #endif #ifdef HAVE_GEOIP geoip_db_init(); #endif }
void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), void (*register_all_handoffs_func)(register_cb cb, gpointer client_data), register_cb cb, gpointer client_data, void (*report_failure_fcn_p)(const char *, va_list), void (*report_open_failure_fcn_p)(const char *, int, gboolean), void (*report_read_failure_fcn_p)(const char *, int), void (*report_write_failure_fcn_p)(const char *, int)) { init_report_err(report_failure_fcn_p, report_open_failure_fcn_p, report_read_failure_fcn_p, report_write_failure_fcn_p); /* initialize memory allocation subsystems */ emem_init(); wmem_init(); /* initialize the GUID to name mapping table */ guids_init(); except_init(); #ifdef HAVE_LIBGCRYPT /* initialize libgcrypt (beware, it won't be thread-safe) */ gcry_check_version(NULL); gcry_control (GCRYCTL_DISABLE_SECMEM, 0); gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #ifdef HAVE_LIBGNUTLS gnutls_global_init(); #endif tap_init(); prefs_init(); expert_init(); proto_init(register_all_protocols_func, register_all_handoffs_func, cb, client_data); packet_init(); dfilter_init(); final_registration_all_protocols(); /*host_name_lookup_init();*//* We load the hostname file in cf_open, no need to do it here? */ expert_packet_init(); #ifdef HAVE_LUA wslua_init(cb, client_data); #endif }
void epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), void (*register_all_handoffs_func)(register_cb cb, gpointer client_data), register_cb cb, gpointer client_data) { /* initialize memory allocation subsystem */ wmem_init(); /* initialize the GUID to name mapping table */ guids_init(); /* initialize name resolution (addr_resolv.c) */ addr_resolv_init(); except_init(); #ifdef HAVE_LIBGCRYPT /* initialize libgcrypt (beware, it won't be thread-safe) */ gcry_check_version(NULL); gcry_control (GCRYCTL_DISABLE_SECMEM, 0); gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #ifdef HAVE_LIBGNUTLS gnutls_global_init(); #endif tap_init(); prefs_init(); expert_init(); packet_init(); proto_init(register_all_protocols_func, register_all_handoffs_func, cb, client_data); packet_cache_proto_handles(); dfilter_init(); final_registration_all_protocols(); print_cache_field_handles(); expert_packet_init(); #ifdef HAVE_LUA wslua_init(cb, client_data); #endif }
int main(void) { cli(); flg_hw_setup(); #if (FOSC == 18432000UL) /* * Fosc = 18432000 * Fping = 100 Hz * * Fosc / Fping / 1024 = 180; */ set_timer2(_BV(CS22) | _BV(CS20), 180); #elif (FOSC == 7372800UL) /* * Fosc = 7372800 * Fping = 100 Hz * * Fosc / Fping / 1024 = 72; */ set_timer2(_BV(CS22) | _BV(CS20), 72); #else #error "FLGMAIN: unsupported FOSC freq" #endif config_init(); uart_init(uart_baud(FOSC, 115200)); flg_proto.handlers->set_addr = &flg_set_addr; flg_proto.handlers->send = &flg_queue_pkt; proto_init(&flg_proto, config.addr); sei(); wdt_enable(WDTO_1S); while (1) { flg_work(); } }
int main() { int ret = 0, i; struct ModuleInfo modinf; struct ModuleInfo config_modinf; struct KeyValueArray proto_cfg; //char Buffer[40]; memset(&modinf, 0, sizeof(struct ModuleInfo)); config_init(NULL, main_callback, &config_modinf); config_control(0, 3, NULL, (void *) &proto_cfg); ret = proto_init(&proto_cfg, main_callback, &modinf); if (ret <= -1) { printf("初始化失败,程序退出\n"); return -1; } while (1) { //提示信息 puts("\n选择要测试的功能:"); puts("1: 登录到服务器"); puts("2: 登出服务器"); puts("3: 前端设备注册"); puts("4: 前端设备帐号修改"); puts("5: 前端设备帐号注销"); puts("6: 消息推送请求"); puts("7: 升级查询"); puts("8: 文件传输"); puts("0: 退出程序\n"); scanf("%d", &i); //执行用户选择 switch (i) { case 1: modinf.control(0, PROTO_CONTROL_LOGIN, NULL, NULL); break; case 2: modinf.control(0, PROTO_CONTROL_LOGINOUT, NULL, NULL); break; case 3: { register_data data; char info[20] = { "\0" }; init_register_data(&data); modinf.control(0, PROTO_CONTROL_REGISTER, (register_data*) &data, info); PLOG("register info:%s\n", info); } break; case 4: { register_data data; char info[20] = { "\0" }; init_accmod_data(&data); modinf.control(0, PROTO_CONTROL_MODIFY, (register_data*) &data, info); PLOG("register info:%s\n", info); } break; case 5: modinf.control(0, PROTO_CONTROL_LOGOUT, NULL, NULL); PLOG("Logout suceess\n"); break; case 6: proto_deliver_reauest_start(); break; case 7: proto_upgrade_request_start(); break; case 8: proto_fileinfo_request_start(); break; case 0: modinf.control(0, PROTO_CONTROL_LOGINOUT, NULL, NULL); modinf.close(); exit(1); break; default: printf("ERROR!\n"); } } //程序退出处理 modinf.close(); return 0; }
gboolean epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data), void (*register_all_handoffs_func)(register_cb cb, gpointer client_data), register_cb cb, gpointer client_data) { volatile gboolean status = TRUE; /* initialize memory allocation subsystem */ wmem_init(); /* initialize the GUID to name mapping table */ guids_init(); /* initialize name resolution (addr_resolv.c) */ addr_resolv_init(); except_init(); #ifdef HAVE_LIBGCRYPT /* initialize libgcrypt (beware, it won't be thread-safe) */ gcry_check_version(NULL); gcry_control (GCRYCTL_DISABLE_SECMEM, 0); gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #ifdef HAVE_LIBGNUTLS gnutls_global_init(); #endif TRY { tap_init(); prefs_init(); expert_init(); packet_init(); capture_dissector_init(); proto_init(register_all_protocols_func, register_all_handoffs_func, cb, client_data); packet_cache_proto_handles(); dfilter_init(); final_registration_all_protocols(); print_cache_field_handles(); expert_packet_init(); export_pdu_init(); #ifdef HAVE_LUA wslua_init(cb, client_data); #endif } CATCH(DissectorError) { /* * This is probably a dissector, or something it calls, * calling REPORT_DISSECTOR_ERROR() in a registration * routine or something else outside the normal dissection * code path. */ const char *exception_message = GET_MESSAGE; static const char dissector_error_nomsg[] = "Dissector writer didn't bother saying what the error was"; report_failure("Dissector bug: %s", exception_message == NULL ? dissector_error_nomsg : exception_message); if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL) abort(); status = FALSE; } ENDTRY; return status; }
static int proto_reload(sigma_proto *instance) { return proto_init(instance); }