SR_PRIV int pce_322a_receive_data(int fd, int revents, void *cb_data) { const struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; unsigned char c; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; if (!(serial = sdi->conn)) return TRUE; if (revents == G_IO_IN) { if (serial_read_nonblocking(serial, &c, 1) != 1) return TRUE; process_byte(sdi, c); } return TRUE; }
inline void sha1::process_block(void const* bytes_begin, void const* bytes_end) { cvc4_uchar8 const* begin = static_cast<cvc4_uchar8 const*>(bytes_begin); cvc4_uchar8 const* end = static_cast<cvc4_uchar8 const*>(bytes_end); for(; begin != end; ++begin) { process_byte(*begin); } }
inline void sha1::process_block(void const* bytes_begin, void const* bytes_end) { unsigned char const* begin = static_cast<unsigned char const*>(bytes_begin); unsigned char const* end = static_cast<unsigned char const*>(bytes_end); for(; begin != end; ++begin) { process_byte(*begin); } }
inline void process_block(const Iterator start, const Iterator end) { const boost::uint8_t* begin = static_cast<const boost::uint8_t*>(&(*start)); const boost::uint8_t* finish = static_cast<const boost::uint8_t*>(&(*end)); while(begin != finish) { process_byte(*begin); begin++; } }
inline void sha1::get_digest(digest_type digest) { std::size_t bit_count = byte_count_*8; // append the bit '1' to the message process_byte(0x80); // append k bits '0', where k is the minimum number >= 0 // such that the resulting message length is congruent to 56 (mod 64) // check if there is enough space for padding and bit_count if (block_byte_index_ > 56) { // finish this block while (block_byte_index_ != 0) { process_byte(0); } // one more block while (block_byte_index_ < 56) { process_byte(0); } } else { while (block_byte_index_ < 56) { process_byte(0); } } // append length of message (before pre-processing) // as a 64-bit big-endian integer process_byte(0); process_byte(0); process_byte(0); process_byte(0); process_byte( static_cast<unsigned char>((bit_count>>24) & 0xFF)); process_byte( static_cast<unsigned char>((bit_count>>16) & 0xFF)); process_byte( static_cast<unsigned char>((bit_count>>8 ) & 0xFF)); process_byte( static_cast<unsigned char>((bit_count) & 0xFF)); // get final digest digest[0] = h_[0]; digest[1] = h_[1]; digest[2] = h_[2]; digest[3] = h_[3]; digest[4] = h_[4]; }
static int global_ini_callback(const char *section, const char *name, const char *value) { //fprintf(stdout, "[%s] '%s'='%s'\n", section, name, value); #define check_ini_section(section_name) (strcasecmp(section, section_name) == 0) // Make sure that we return successfully as soon as name matches the correct option_name #define process_word(option_name, target, value_names) \ if (ini_process_word(name, value, option_name, target, value_names)) return 1; #define process_short(option_name, target, value_names) \ if (ini_process_short(name, value, option_name, target, value_names)) return 1; #define process_byte(option_name, target, value_names) \ if (ini_process_byte(name, value, option_name, target, value_names)) return 1; #define process_boolean(option_name, target) \ if (ini_process_boolean(name, value, option_name, target)) return 1; if (check_ini_section("General")) { process_boolean("enable_copyprot", &options.enable_copyprot); process_boolean("enable_mixer", &options.enable_mixer); process_boolean("enable_fade", &options.enable_fade); process_boolean("enable_flash", &options.enable_flash); process_boolean("enable_text", &options.enable_text); process_boolean("start_fullscreen", &start_fullscreen); process_word("pop_window_width", &pop_window_width, NULL); process_word("pop_window_height", &pop_window_height, NULL); process_boolean("use_correct_aspect_ratio", &options.use_correct_aspect_ratio); if (strcasecmp(name, "levelset") == 0) { if (value[0] == '\0' || strcasecmp(value, "original") == 0 || strcasecmp(value, "default") == 0) { use_custom_levelset = 0; } else { use_custom_levelset = 1; strcpy(levelset_name, value); } return 1; } } if (check_ini_section("AdditionalFeatures")) { process_boolean("enable_quicksave", &options.enable_quicksave); process_boolean("enable_quicksave_penalty", &options.enable_quicksave_penalty); process_boolean("enable_replay", &options.enable_replay); } if (check_ini_section("Enhancements")) { if (strcasecmp(name, "use_fixes_and_enhancements") == 0) { if (strcasecmp(value, "true") == 0) options.use_fixes_and_enhancements = 1; else if (strcasecmp(value, "false") == 0) options.use_fixes_and_enhancements = 0; else if (strcasecmp(value, "prompt") == 0) options.use_fixes_and_enhancements = 2; return 1; } process_boolean("enable_crouch_after_climbing", &options.enable_crouch_after_climbing); process_boolean("enable_freeze_time_during_end_music", &options.enable_freeze_time_during_end_music); process_boolean("enable_remember_guard_hp", &options.enable_remember_guard_hp); process_boolean("fix_gate_sounds", &options.fix_gate_sounds); process_boolean("fix_two_coll_bug", &options.fix_two_coll_bug); process_boolean("fix_infinite_down_bug", &options.fix_infinite_down_bug); process_boolean("fix_gate_drawing_bug", &options.fix_gate_drawing_bug); process_boolean("fix_bigpillar_climb", &options.fix_bigpillar_climb); process_boolean("fix_jump_distance_at_edge", &options.fix_jump_distance_at_edge); process_boolean("fix_edge_distance_check_when_climbing", &options.fix_edge_distance_check_when_climbing); process_boolean("fix_painless_fall_on_guard", &options.fix_painless_fall_on_guard); process_boolean("fix_wall_bump_triggers_tile_below", &options.fix_wall_bump_triggers_tile_below); process_boolean("fix_stand_on_thin_air", &options.fix_stand_on_thin_air); process_boolean("fix_press_through_closed_gates", &options.fix_press_through_closed_gates); process_boolean("fix_grab_falling_speed", &options.fix_grab_falling_speed); process_boolean("fix_skeleton_chomper_blood", &options.fix_skeleton_chomper_blood); process_boolean("fix_move_after_drink", &options.fix_move_after_drink); process_boolean("fix_loose_left_of_potion", &options.fix_loose_left_of_potion); process_boolean("fix_guard_following_through_closed_gates", &options.fix_guard_following_through_closed_gates); process_boolean("fix_safe_landing_on_spikes", &options.fix_safe_landing_on_spikes); process_boolean("fix_glide_through_wall", &options.fix_glide_through_wall); process_boolean("fix_drop_through_tapestry", &options.fix_drop_through_tapestry); process_boolean("fix_land_against_gate_or_tapestry", &options.fix_land_against_gate_or_tapestry); } if (check_ini_section("CustomGameplay")) { process_word("start_minutes_left", &start_minutes_left, NULL); process_word("start_ticks_left", &start_ticks_left, NULL); process_word("start_hitp", &start_hitp, NULL); process_word("max_hitp_allowed", &max_hitp_allowed, NULL); process_word("saving_allowed_first_level", &saving_allowed_first_level, NULL); process_word("saving_allowed_last_level", &saving_allowed_last_level, NULL); process_boolean("allow_triggering_any_tile", &allow_triggering_any_tile); } // [Level 1], etc. int ini_level = -1; if (strncasecmp(section, "Level ", 6) == 0 && sscanf(section+6, "%d", &ini_level) == 1) { if (ini_level >= 0 && ini_level <= 15) { // TODO: And maybe allow new types in addition to the existing ones. process_byte("level_type", &tbl_level_type[ini_level], &level_type_names_list); process_word("level_color", &tbl_level_color[ini_level], NULL); process_short("guard_type", &tbl_guard_type[ini_level], &guard_type_names_list); process_byte("guard_hp", &tbl_guard_hp[ini_level], NULL); } else { // TODO: warning? } } return 0; }
int http_async_req_status(void *ctx) { struct http_ctx *cx = ctx; char *dns,*srv,buf[CHUNK]; int tmp, i; time_t now = time(NULL); #ifdef WIN32 unsigned long tmp2; #endif switch (cx->state) { case HTS_STRT: dns = getserv(cx->host); srv = getport(cx->host); if (resolve(dns, srv, &cx->addr)) { free(dns); free(srv); cx->state = HTS_DONE; cx->ret = 602; return 1; } free(dns); free(srv); cx->state = HTS_RSLV; return 0; case HTS_RSLV: cx->state = HTS_CONN; cx->last = now; return 0; case HTS_CONN: if (cx->fd == PERROR) { cx->fd = socket(AF_INET, SOCK_STREAM, 0); if (cx->fd == PERROR) goto fail; cx->fdhost = mystrdup(cx->host); #ifdef WIN32 tmp2 = 1; if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR) goto fail; #else tmp = fcntl(cx->fd, F_GETFL); if (tmp < 0) goto fail; if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0) goto fail; #endif } if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr))) cx->state = HTS_IDLE; #ifdef WIN32 else if (PERRNO==WSAEISCONN) cx->state = HTS_IDLE; #endif #ifdef MACOSX else if (PERRNO==EISCONN) cx->state = HTS_IDLE; #endif else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY #ifdef WIN32 && PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL #endif ) goto fail; if (now-cx->last>http_timeout) goto timeout; return 0; case HTS_IDLE: if (cx->txdl) { // generate POST cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 121 + cx->txdl + cx->thlen); cx->tptr = 0; cx->tlen = 0; cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\n", cx->path); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host); if (!cx->keep) cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); if (cx->thdr) { memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); cx->tlen += cx->thlen; free(cx->thdr); cx->thdr = NULL; cx->thlen = 0; } cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\n", cx->txdl); if (save_as%3 == 0) cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); else if (save_as%3 == 1) cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, BETA_VERSION, BETA_MINOR_VER); else cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, RELEASE_VERSION, RELEASE_MINOR_VER); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl); cx->tlen += cx->txdl; free(cx->txd); cx->txd = NULL; cx->txdl = 0; } else { // generate GET cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 89 + cx->thlen); cx->tptr = 0; cx->tlen = 0; cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\n", cx->path); cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\n", cx->host); if (cx->thdr) { memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen); cx->tlen += cx->thlen; free(cx->thdr); cx->thdr = NULL; cx->thlen = 0; } if (!cx->keep) cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\n"); if (save_as%3 == 0) cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION); else if (save_as%3 == 1) cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\n", IDENT_VERSION, BETA_VERSION, BETA_MINOR_VER); else cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\n", IDENT_VERSION, RELEASE_VERSION, RELEASE_MINOR_VER); cx->tlen += sprintf(cx->tbuf+cx->tlen, "\n"); } cx->state = HTS_XMIT; cx->last = now; return 0; case HTS_XMIT: tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0); if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR) goto fail; if (tmp!=PERROR) { cx->tptr += tmp; if (cx->tptr == cx->tlen) { cx->tptr = 0; cx->tlen = 0; if (cx->tbuf) free(cx->tbuf); cx->state = HTS_RECV; } cx->last = now; } if (now-cx->last>http_timeout) goto timeout; return 0; case HTS_RECV: tmp = recv(cx->fd, buf, CHUNK, 0); if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR) goto fail; if (tmp!=PERROR) { for (i=0; i<tmp; i++) { process_byte(cx, buf[i]); if (cx->state == HTS_DONE) return 1; } cx->last = now; } if (now-cx->last>http_timeout) goto timeout; return 0; case HTS_DONE: return 1; } return 0; fail: cx->ret = 600; cx->state = HTS_DONE; return 1; timeout: cx->ret = 605; cx->state = HTS_DONE; return 1; }
inline void process(boost::uint8_t b) { process_byte(b); }