void CurlClient::doRequest(proxygen::HTTPMethod httpMethod, proxygen::HTTPMessage request, std::unique_ptr<folly::IOBuf> buf_body) { std::cout << "do request !" << std::endl; request.setMethod(httpMethod); request.setHTTPVersion(1, 1); URL url("https://newapi.mogujie.com/gw/mwp.PetStore.helloWorld/2/?data=123"); //URL url("https://newapi.mogujie.com/gw/mwp.Petstore.helloworld/2/?data=123"); request.setURL(url.makeRelativeURL()); request.setSecure(url.isSecure()); if (!request.getHeaders().getNumberOfValues(HTTP_HEADER_USER_AGENT)) { request.getHeaders().add(HTTP_HEADER_USER_AGENT, "proxygen_curl"); } if (!request.getHeaders().getNumberOfValues(HTTP_HEADER_HOST)) { request.getHeaders().add(HTTP_HEADER_HOST, url.getHostAndPort()); } if (!request.getHeaders().getNumberOfValues(HTTP_HEADER_ACCEPT)) { request.getHeaders().add("Accept", "*/*"); } request.getHeaders().add("SequenceNum", "123"); request.getHeaders().add("mw-appkey","100001"); std::string device_id = "484d39ffb532b735cf4873a5129c560f"; request.getHeaders().add("mw-did", device_id); request.getHeaders().add("mw-lang", "zh_CN"); request.getHeaders().add("mw-pv", "1.0"); request.getHeaders().add("mw-t", "1461922412"); std::string cs = "202cb962ac59075b964b07152d234b70";//util::getMd5CString("123", 3); std::string query = "100001&" + device_id + "&zh_CN" + "&1.0" + "&1461922412" + "&mwp.PetStore.helloWorld" + "&2&" + cs; std::string token = generate_token(query.c_str(), "00c422a8d19627e941b5fb43fd6b80c0"); token = "c98b25f90660de2c"; request.getHeaders().add("mw-sign", token); request.dumpMessage(4); std::cout << "send header!" << std::endl; std::cout << "send header!" << std::endl; txn_ = session_->newTransaction(this); if (!txn_) { std::cout << "txn_ is empty!" << std::endl; return; } txn_->sendHeaders(request); // note that sendBody() is called only for POST. It's fine not to call it at all. ///< 存在 body,同时是 post 请求时才发送 http body if (httpMethod == HTTPMethod::POST && buf_body && buf_body->length() > 0) { txn_->sendBody(std::move(buf_body)); } txn_->sendEOM(); }
void generate_blacklist(char *config_fname, struct dataset *frames) { char blacklist_fname[1024] = {'\0'}, sel_string[1024] = {'\0'} ; char line[1024], section_name[1024], config_folder[1024], *token ; char *temp_fname = strndup(config_fname, 1024) ; sprintf(config_folder, "%s/", dirname(temp_fname)) ; free(temp_fname) ; FILE *config_fp = fopen(config_fname, "r") ; while (fgets(line, 1024, config_fp) != NULL) { if ((token = generate_token(line, section_name)) == NULL) continue ; if (strcmp(section_name, "emc") == 0) { if (strcmp(token, "blacklist_file") == 0) absolute_strcpy(config_folder, blacklist_fname, strtok(NULL, " =\n")) ; else if (strcmp(token, "selection") == 0) strcpy(sel_string, strtok(NULL, " =\n")) ; } } fclose(config_fp) ; if (sel_string[0] == '\0') { make_blacklist(blacklist_fname, 0, frames) ; } else if (strcmp(sel_string, "odd_only") == 0) { fprintf(stderr, "Only processing 'odd' frames\n") ; make_blacklist(blacklist_fname, 1, frames) ; } else if (strcmp(sel_string, "even_only") == 0) { fprintf(stderr, "Only processing 'even' frames\n") ; make_blacklist(blacklist_fname, 2, frames) ; } else { fprintf(stderr, "Did not understand selection keyword: %s. Will process all frames\n", sel_string) ; make_blacklist(blacklist_fname, 0, frames) ; } fprintf(stderr, "%d/%d blacklisted frames\n", frames->num_blacklist, frames->tot_num_data) ; }
static void receive_text (RingTextManager *self, RingTextChannel *channel, gchar const *message, GHashTable *info, guint32 sms_class) { char const *sent; char *token; gint64 message_sent; gint64 message_received = (gint64) time(NULL); sent = tp_asv_get_string (info, "SentTime"); if (sent) message_sent = modem_sms_parse_time (sent); else message_sent = message_received; token = generate_token (); ring_text_channel_receive_text (channel, token, message, message_sent, message_received, sms_class); g_free (token); }
int generate_data(char *config_fname, char *config_section, char *type_string, struct detector *det_list, struct dataset *frames_list) { int num_datasets = 0 ; char data_fname[1024] = {'\0'}, data_flist[1024] = {'\0'}, out_data_fname[1024] = {'\0'} ; char fname_opt[64], flist_opt[64] ; char line[1024], section_name[1024], config_folder[1024], *token ; char *temp_fname = strndup(config_fname, 1024) ; sprintf(config_folder, "%s/", dirname(temp_fname)) ; free(temp_fname) ; sprintf(fname_opt, "%s_photons_file", type_string) ; sprintf(flist_opt, "%s_photons_list", type_string) ; FILE *config_fp = fopen(config_fname, "r") ; while (fgets(line, 1024, config_fp) != NULL) { if ((token = generate_token(line, section_name)) == NULL) continue ; if (strcmp(section_name, "make_data") == 0) { if (strcmp(token, "out_photons_file") == 0) absolute_strcpy(config_folder, out_data_fname, strtok(NULL, " =\n")) ; } else if (strcmp(section_name, config_section) == 0) { if (strcmp(token, fname_opt) == 0) absolute_strcpy(config_folder, data_fname, strtok(NULL, " =\n")) ; else if (strcmp(token, flist_opt) == 0) absolute_strcpy(config_folder, data_flist, strtok(NULL, " =\n")) ; } } fclose(config_fp) ; if (strcmp(data_fname, "make_data:::out_photons_file") == 0) strcpy(data_fname, out_data_fname) ; if (data_flist[0] != '\0' && data_fname[0] != '\0') { fprintf(stderr, "Config file contains both in_photons_file and in_photons_list. Pick one.\n") ; return 1 ; } else if (data_fname[0] != '\0') { if (frames_list == NULL) frames_list = malloc(sizeof(struct dataset)) ; if (parse_dataset(data_fname, det_list, frames_list)) return 1 ; frames_list->num_data_prev = 0 ; frames_list->next = NULL ; calc_sum_fact(det_list, frames_list) ; num_datasets = 1 ; } else if (data_flist[0] != '\0') { if (frames_list == NULL) frames_list = malloc(sizeof(struct dataset)) ; frames_list->next = NULL ; if ((num_datasets = parse_data(data_flist, det_list, frames_list)) < 0) return 1 ; } else if (strcmp(type_string, "in") == 0) { fprintf(stderr, "Need either in_photons_file or in_photons_list.\n") ; return 1 ; } if (strcmp(type_string, "in") == 0) { if (det_list[0].num_dfiles > 0 && det_list[0].num_dfiles != num_datasets) { fprintf(stderr, "Number of detector files and photon files don't match (%d vs %d)\n", det_list[0].num_dfiles, num_datasets) ; return 1 ; } fprintf(stderr, "Number of dataset files = %d\n", num_datasets) ; } return 0 ; }
// Replace the incoming token from the cookies to the data set from driver // database. If the token is not set or doesn't exist, it will generate a new // one and set it in request variables for the output filter. // // TODO: It should be useful to put the token into a special header or cookie. void psm_map_cookies(request_rec *r, psm_driver *driver) { const char *header; char *token; psm_request_vars *vars; unsigned int found = 0; // Fetch configuration of the server vars = (psm_request_vars *) apr_palloc(r->pool, sizeof(psm_request_vars)); // Look at `Cookie` header to get private state cookie header = apr_table_get(r->headers_in, HEADER_COOKIE); if (header != NULL) { int i; apr_array_header_t *cookies; // Parse incoming cookies cookies = parse_cookie(r->pool, header); // Test if the private state cookie is set and contains a token for (i = 0; i < cookies->nelts && ! found; i++) { psm_cookie *cookie = ((psm_cookie **)cookies->elts)[i]; if (! strcasecmp(cookie->name, PSM_TOKEN_NAME) && strlen(cookie->value)) { ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, "Private token detected: %s", cookie->value); vars->token = apr_pstrdup(r->pool, cookie->value); found = 1; } } } // Try to retrieve cookies from the driver if we found the private state cookie token if (found) { apr_array_header_t *cookies; // Initialize Apache array with the good size cookies = apr_array_make(r->pool, PSM_ARRAY_INIT_SZ, sizeof(psm_cookie *)); // Fetch "data" cookies from the driver (aka db) and write them if (driver->fetch_cookies(r->pool, *driver->data, cookies, vars->token) == OK) { psm_write_cookie(r->headers_in, cookies); } // If we didn't find it, trigger the token generation else { found = 0; } } // Re-check in case of fetch_cookies function failed if (! found) { // Generate a random token vars->token = generate_token(r->pool, PSM_TOKEN_LENGTH); // Unset incoming cookies apr_table_unset(r->headers_in, HEADER_COOKIE); ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, "Not any private token found. New token set: %s", vars->token); } // Set variables of this request for the output filter // TODO is it mandatory to set when `vars` is a pointer ? ap_set_module_config(r->request_config, &psm_module, vars); }
int main(int argc, char *argv[]) { struct mbus *m; char c_addr[60], *token_u[2], *token_e[2]; int seed = (gethostid() << 8) | (getpid() & 0xff), final_iters; struct timeval timeout; int i, num_sessions = 0; char **xargv = xmalloc(argc); int xargc=0; #ifdef WIN32 win32_create_null_window(); /* Needed to listen to messages */ #else signal(SIGCONT, sigchld_handler); signal(SIGCHLD, sigchld_handler); signal(SIGINT, sigint_handler); signal(SIGTERM, sigint_handler); signal(SIGHUP, sigint_handler); #endif debug_msg("rat-%s started argc=%d\n", RAT_VERSION, argc); /* We have two modes: one for operation as a transcoder, one */ /* when working as a normal end-system audio tool. We choose */ /* based on the first command line argument supplied. */ if ((argc > 2) && (strcmp(argv[1], "-T") == 0)) { num_sessions = 2; } else { num_sessions = 1; } if (parse_options_early(argc, (const char**)argv) == FALSE) { return FALSE; } srand48(seed); snprintf(c_addr, 60, "(media:audio module:control app:rat id:%lu)", (unsigned long) getpid()); debug_msg("c_addr = %s\n", c_addr); m = mbus_init(mbus_control_rx, mbus_err_handler, c_addr); if (m == NULL) { fatal_error("RAT v" RAT_VERSION, "Could not initialize Mbus: Is multicast enabled?"); return FALSE; } /* pull out -X arguments */ for(i=0; i<argc; i++) { if( strcmp(argv[i],"-X") == 0 ) { xargv[xargc] = argv[i]; xargc++; i++; xargv[xargc] = argv[i]; xargc++; } } if (ui_enabled) { token_u[0] = generate_token(); fork_process(UI_NAME, c_addr, &pid_ui, 1, token_u, xargc, xargv); debug_msg("Controller waiting for %s from UI...\n", token_u[0]); if ((u_addr = mbus_rendezvous_waiting(m, "()", token_u[0], m, 20000000)) == NULL) { fatal_error("RAT v" RAT_VERSION, "MBUS Failed to rendezvous with UI - Likely firewall/VPN issue"); return FALSE; } debug_msg("Controller has rendezvous'd with UI (%s)\n",u_addr); } token_e[0] = generate_token(); token_e[1] = generate_token(); fork_process(ENGINE_NAME, c_addr, &pid_engine, num_sessions, token_e, xargc, xargv); should_exit = FALSE; for (i = 0; i < num_sessions; i++) { debug_msg("Controller waiting for %s from media engine...\n", token_e[i]); if ((e_addr[i] = mbus_rendezvous_waiting(m, "()", token_e[i], m, 20000000)) == NULL ) { fatal_error("RAT v" RAT_VERSION, "Failed to rendezvous with media engine - Likely firewall/VPN issue"); return FALSE; } debug_msg("Controller rendezvous'd with media engine (%s)\n",e_addr[i]); } if (parse_addresses(m, e_addr, argc, argv) == TRUE) { char *peer; if (ui_enabled) { if ((peer = mbus_rendezvous_go(m, token_u[0], (void *) m, 20000000)) == NULL) { fatal_error("RAT v" RAT_VERSION, "Failed to rendezvous with UI - Likely firewall/VPN issue"); return FALSE; } debug_msg("User interface is %s\n", peer); } for (i = 0; i < num_sessions; i++) { if ((peer = mbus_rendezvous_go(m, token_e[i], (void *) m, 20000000)) == NULL) { fatal_error("RAT v" RAT_VERSION, "Failed to rendezvous with UI - Likely firewall/VPN issue"); return FALSE; } debug_msg("Media engine %d is %s\n", i, peer); } debug_msg("Parsing options\n"); for (i = 0; i < num_sessions; i++) { parse_options_late(m, e_addr[i], argc, argv); } debug_msg("Entering main loop\n"); final_iters = 25; while (final_iters > 0) { mbus_send(m); mbus_heartbeat(m, 1); mbus_retransmit(m); timeout.tv_sec = 0; timeout.tv_usec = 20000; #ifdef WIN32 win32_check_children_running(); win32_process_messages(); #endif mbus_recv(m, NULL, &timeout); if (should_exit) { final_iters--; } } if (ui_enabled) { terminate(m, u_addr, &pid_ui); } for (i = 0; i < num_sessions; i++) { terminate(m, e_addr[i], &pid_engine); } } if (ui_enabled) { kill_process(pid_ui); } kill_process(pid_engine); #ifdef WIN32 WSACleanup(); #endif if (ui_enabled) xfree(token_u[0]); xfree(token_e[0]); xfree(token_e[1]); xfree(xargv); debug_msg("Controller exit\n"); return 0; }
void do_insert(CHAR_DATA *ch, char *argument) { OBJ_DATA *obj, *obj_next; OBJ_DATA *obj2; OBJ_DATA *machine, *machine_next; int reward; bool found; CHAR_DATA *to,*to_next; if(argument[0] == '\0') { send_to_one(ch,"Insert what?"); return; } if( ( obj = get_obj_carry(ch,argument,ch)) == NULL) { send_to_one(ch,"You don't have that to insert."); return; } found = FALSE; for(machine = ch->in_room->contents; machine; machine = machine_next) { machine_next = machine->next_content; if( machine->item_type == ITEM_TOKEN && machine->value[4] == 1) { found = TRUE; if( obj->item_type != ITEM_TOKEN) { send_to_one(ch,"You can't insert that."); return; } //alrighty, let's gamble send_to_one(ch,"You insert %s into %s.",obj->short_descr,machine->short_descr); for(to = ch->in_room->people; to; to = to_next) { to_next = to->next_in_room; if(to->in_room == ch->in_room && to != ch) { send_to_one(to,"%s inserts %s into %s.",PERS(ch,to), obj->short_descr,machine->short_descr); } } ch->inserted = obj; machine->value[2] += number_range(75,125); if(chance(obj->value[1])) { if(chance(45) && obj->value[0] != 4)//45 percent chance you win a new token generate_token(ch); else if( chance(5) && machine->value[2] != 0 && obj->value[0] == 0) //5 percent chance you hit jackpot with a normal token { reward = machine->value[2]; send_to_one(ch,"You hit the {RJ{WA{YC{BK{MP{CO{GT{x!"); send_to_one(ch,"You win {Y%d gold!{x",reward); for(to = ch->in_room->people; to; to = to_next) { to_next = to->next_in_room; if(to->in_room == ch->in_room && to != ch) { send_to_one(to,"%s just hit the {RJ{WA{YC{BK{MP{CO{GT{x!\n\r%s won {Y%d gold{x!",PERS(ch,to), PERS(ch,to), reward); } } ch->gold += reward; machine->value[2] = 0; } else { reward = number_range(obj->value[3],obj->value[2]); send_to_one(ch,"You win %d %s!",reward, token_table[obj->value[0]].reward); if (token_table[obj->value[0]].value == 1) ch->gold += reward; else if(token_table[obj->value[0]].value == 2) ch->practice += reward; else if(token_table[obj->value[0]].value == 3) ch->train += reward; else if(token_table[obj->value[0]].value == 4) ch->pcdata->questpoints += reward; else if(token_table[obj->value[0]].value == 5) gain_exp(ch,reward); } obj_from_char(obj); extract_obj(obj); } else { send_to_one(ch,"You lost your %s token.",token_table[obj->value[0]].name); obj_from_char(obj); extract_obj(obj); return; } } } if(!found) { send_to_one(ch,"You see nothing to insert it into."); return; } return; }