void source_accept_cb(uv_stream_t *server, int status) { struct source_context *source = new_source(); struct target_context *target = new_target(); source->target = target; target->source = source; uv_tcp_init(server->loop, &source->handle.tcp); uv_tcp_init(server->loop, &target->handle.tcp); uv_tcp_nodelay(&source->handle.tcp, 0); uv_tcp_nodelay(&target->handle.tcp, 0); uv_tcp_keepalive(&source->handle.tcp, 1, 60); uv_tcp_keepalive(&target->handle.tcp, 1, 60); int rc = uv_accept(server, &source->handle.stream); if (rc == 0) { connect_to_target(target); } else { logger_log(LOG_ERR, "accept error: %s", uv_strerror(rc)); close_source(source); close_target(target); } }
int thread_read_openstream(struct thread_read *thread) { thread->source = new_source(thread->url, thread->headers, thread->flags); if (thread->source != NULL) { int ret; ret = source_open(thread->source); if (ret != 0) { LOGI("source opened failed\n"); release_source(thread->source); thread_read_wakewait(thread); thread->source = NULL; thread->error = ret; return ret; } source_getoptions(thread->source, &thread->options); thread_read_wakewait(thread); thread->opened = 1; } return 0; }
void TesterAnalizer::insert_testcases( std::fstream * stream, std::string name ) { std::string line; std::string new_name( name ); new_name.append( ".temp" ); std::fstream new_source( new_name, WRITE|APPEND ); if( new_source.is_open() ) { while( std::getline( (* stream ), line ) ) { if( line.find( "*/" ) != std::string::npos ) { line.pop_back(); line.pop_back(); } for( int i = 0; i < data->methods.size(); i++ ) { if( line.find( data->methods[ i ].name ) != std::string::npos ) { long found = new_source.tellp(); new_source.seekp( found-10 ); std::string testcase = create_testcases( data->methods[ i ] ); new_source << testcase << std::endl; } } new_source << line << std::endl; } new_source.close(); } std::remove( name.c_str() ); std::rename( new_name.c_str(), name.c_str() ); }
void BeyeContext::main_loop() { __filesize_t OldCurrFilePos; /** means previous File position */ int ch; __filesize_t savep = 0,cfp,nfp,flen; unsigned long lwidth; plugin_position rc; Search& s = search(); bm_file().seek(LastOffset,binary_stream::Seek_Set); drawPrompt(); rc.textshift=0; rc = active_mode().paint(KE_SUPERKEY,rc.textshift); bm_file().seek(LastOffset,binary_stream::Seek_Set); draw_title(rc.lastbyte); while(1) { unsigned che; ch = GetEvent(drawPrompt,MainActionFromMenu,NULL); nfp = cfp = OldCurrFilePos = tell(); flen = flength(); lwidth = active_mode().curr_line_width(); che = ch & 0x00FF; if(((che >= '0' && che <= '9') || (che >= 'A' && che <= 'Z') || (che >= 'a' && che <= 'z') || ch == KE_BKSPACE) && (active_mode().flags() & Plugin::UseCodeGuide) == Plugin::UseCodeGuide) { nfp = codeguider().get_go_address(ch); goto GO; } switch(ch) { case KE_CTL_F(1): if(active_mode().action_F1()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(2): if(active_mode().action_F2()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(3): if(active_mode().action_F3()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(4): if(active_mode().action_F4()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(5): if(active_mode().action_F5()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(6): if(active_mode().action_F6()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(7): if(active_mode().action_F7()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(8): if(active_mode().action_F8()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(9): if(active_mode().action_F9()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_CTL_F(10): if(active_mode().action_F10()) { ch = KE_SUPERKEY; drawPrompt(); } break; case KE_ALT_F(1): nfp=bin_format().action_F1(); break; case KE_ALT_F(2): nfp=bin_format().action_F2(); break; case KE_ALT_F(3): nfp=bin_format().action_F3(); break; case KE_ALT_F(4): nfp=bin_format().action_F4(); break; case KE_ALT_F(5): nfp=bin_format().action_F5(); break; case KE_ALT_F(6): nfp=bin_format().action_F6(); break; case KE_ALT_F(7): nfp=bin_format().action_F7(); break; case KE_ALT_F(8): nfp=bin_format().action_F8(); break; case KE_ALT_F(9): nfp=bin_format().action_F9(); break; case KE_ALT_F(10): nfp=bin_format().action_F10(); break; case KE_SUPERKEY: goto DRAW; case KE_F(1) : About(); continue; default : continue; case KE_SHIFT_F(1): active_mode().help(); break; case KE_F(10): case KE_ESCAPE : return; case KE_ENTER: quick_select_mode(); drawPrompt(); ch = KE_SUPERKEY; break; case KE_F(2): if(select_mode()) ch = KE_SUPERKEY; break; case KE_F(3): if(new_source()) { ch = KE_SUPERKEY; s.reset(); PaintTitle(); } break; case KE_F(4): __filesize_t sfp; sfp = tell(); active_mode().misckey_action(); ch = KE_SUPERKEY; PaintTitle(); drawPrompt(); bm_file().seek(sfp,binary_stream::Seek_Set); break; case KE_F(5): { static __filesize_t shift = 0; static unsigned long flags = GJDLG_FILE_TOP; if(GetJumpDlg(&shift,&flags)) { switch(flags&0xFF) { default: case GJDLG_PERCENTS: shift=shift>100?100:shift; nfp = flength()*shift/100; break; case GJDLG_FILE_TOP: nfp = shift; break; case GJDLG_RELATIVE: nfp += (long)shift; break; case GJDLG_REL_EOF: nfp = flength()+(long)shift; break; case GJDLG_VIRTUAL: __filesize_t temp_fp; nfp = shift; temp_fp = bin_format().va2pa(shift); if(temp_fp==Plugin::Bad_Address) ErrMessageBox(NOT_ENTRY,""); else nfp = temp_fp; break; } if((active_mode().flags() & Plugin::UseCodeGuide) == Plugin::UseCodeGuide) codeguider().add_back_address(); ch = KE_SUPERKEY; } } break; case KE_SHIFT_F(5): { WhereAMI wami(beye_context()); nfp = wami.run(nfp); } break; case KE_F(6): bm_file().reread(); s.reset(); ch = KE_SUPERKEY; PaintTitle(); break; case KE_SHIFT_F(6): select_sysinfo(); break; case KE_F(7): nfp = s.run(false); ch = KE_JUSTFIND; break; case KE_SHIFT_F(7): nfp = s.run(true); ch = KE_JUSTFIND; break; case KE_F(8): nfp = bin_format().show_header(); break; case KE_SHIFT_F(8): select_tool(); break; case KE_F(9): { class Setup* setup = new class Setup(*this); setup->run(); delete setup; } break; case KE_SHIFT_F(10): if(FileUtils()) { s.reset(); ch = KE_SUPERKEY; PaintTitle(); } break; case KE_HOME: rc.textshift = 0; break; case KE_END: rc.textshift = active_mode().get_max_line_length() - tconsole().vio_width()/2; break; case KE_UPARROW: nfp = cfp - active_mode().prev_line_width(); break; case KE_DOWNARROW: nfp = cfp + active_mode().curr_line_width(); break; case KE_RIGHTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift+=active_mode().get_symbol_size(); else nfp = cfp + active_mode().get_symbol_size(); break; case KE_LEFTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift-=active_mode().get_symbol_size(); else nfp = cfp - active_mode().get_symbol_size(); if(rc.textshift < 0) rc.textshift = 0; break; case KE_CTL_RIGHTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift+=8*active_mode().get_symbol_size(); else nfp = cfp + 8*active_mode().get_symbol_size(); break; case KE_CTL_LEFTARROW: if((active_mode().flags() & Plugin::Text) == Plugin::Text) rc.textshift-=8*active_mode().get_symbol_size(); else nfp = cfp - 8*active_mode().get_symbol_size(); if(rc.textshift < 0) rc.textshift = 0; break; case KE_PGUP: nfp = cfp - active_mode().prev_page_size(); break; case KE_PGDN: nfp = cfp + active_mode().curr_page_size(); break; case KE_CTL_PGUP: nfp = 0; break; case KE_CTL_PGDN: nfp = flen; break; case KE_CTL_(O): /** User screen */ { unsigned evt; main_wnd().hide(); title_wnd().hide(); do { evt = GetEvent(drawEmptyPrompt,NULL,NULL); } while(!(evt == KE_ESCAPE || evt == KE_F(10) || evt == KE_CTL_(O))); main_wnd().show(); title_wnd().show(); } continue; } GO: if(cfp != nfp && nfp != Plugin::Bad_Address) { unsigned long twidth = ( active_mode().flags() & Plugin::Text ) == Plugin::Text ? active_mode().get_symbol_size() : ( active_mode().flags() & Plugin::Disasm ) == Plugin::Disasm ? 1 : lwidth; __filesize_t p = flen - twidth; if((__fileoff_t)nfp < 0) nfp = 0; if(nfp > 0) if(nfp > p) nfp = p; } bm_file().seek(nfp,binary_stream::Seek_Set); DRAW: if((active_mode().flags() & Plugin::Text) != Plugin::Text) savep = tell(); rc = active_mode().paint(ch,rc.textshift); if((active_mode().flags() & Plugin::Text) != Plugin::Text) bm_file().seek(savep,binary_stream::Seek_Set); draw_title(rc.lastbyte); } }
void include_source(char *inname) { char *filename; struct include_path **nptr = &first_source; struct include_path *name; FILE *f; filename = convert_path(inname); /* check whether this source was already included */ while (name = *nptr) { #if defined(AMIGA) || defined(MSDOS) || defined(_WIN32) if (!stricmp(name->path,filename)) { #else if (!strcmp(name->path,filename)) { #endif myfree(filename); if (!ignore_multinc) { filename = name->path; /* reuse already read file from cache? */ } nptr = NULL; /* ignore including this source */ break; } nptr = &name->next; } if (nptr) { name = mymalloc(sizeof(struct include_path)); name->next = NULL; name->path = filename; *nptr = name; } else if (ignore_multinc) return; /* ignore multiple inclusion of this source completely */ if (f = locate_file(filename,"r")) { char *text; size_t size; for (text=NULL,size=0; ; size+=SRCREADINC) { size_t nchar; text = myrealloc(text,size+SRCREADINC); nchar = fread(text+size,1,SRCREADINC,f); if (nchar < SRCREADINC) { size += nchar; break; } } if (feof(f)) { if (size > 0) { cur_src = new_source(filename,myrealloc(text,size+1),size+1); *(cur_src->text+size) = '\n'; } else { myfree(text); cur_src = new_source(filename,"\n",1); } } else general_error(29,filename); fclose(f); } } /* searches a section by name and attr (if secname_attr set) */ section *find_section(char *name,char *attr) { section *p; if(secname_attr) { for(p=first_section; p; p=p->next) { if(!strcmp(name,p->name) && !strcmp(attr,p->attr)) return p; } } else { for(p=first_section; p; p=p->next) { if(!strcmp(name,p->name)) return p; } } return 0; }
static void scan_input (int ac, char **av) { extern int optind; Boolean last_was_note = FALSE; outer = list_create (LIST_DOUBLE); new_outer (outer, OUTER_TEXT); while (optind < ac || do_stdin) { Uchar *fname = av[optind++]; Uchar *lp; Boolean in_matrix = FALSE, in_block = FALSE; if (do_stdin) { file_open("", "r"); do_stdin = FALSE; } else { extern const char *file; extern FILE *f_log; f_log = stderr; file_open (fname, "r"); file = fname; } if (fragments) { in_matrix = TRUE; new_outer (outer, OUTER_MATRIX); ++matrices_found; } while (NULL != (lp = getline (curr_file->fp))) { ++curr_file->line; strip_trailing_white (lp); if (matches_matrix(lp)) { if (in_matrix) warning (matrix_location(), "new matrix began before end of old one"); list_add (curr_stuff, xstrdup (lp)); new_outer (outer, OUTER_MATRIX); in_matrix = TRUE; ++matrices_found; } else if (matches_end_matrix (lp)) { if (list_len (multi_column_entries)) fix_multis (); new_outer (outer, OUTER_TEXT); list_add (curr_stuff, xstrdup (lp)); in_matrix = in_block = FALSE; } else if (in_matrix) { if (blank_line (lp)) { if (last_was_note) { list_add (curr_notes, xstrdup ("")); last_was_note = FALSE; } continue; } else if (isdigit (*lp)) { /* lp = strip_b (lp); */ last_was_note = FALSE; if (list_len (multi_column_entries)) fix_multis (); multi_column_entries = list_create (LIST_DOUBLE); in_block = 1; new_block (curr_matrix); new_composite (curr_block, lp); curr_block->reconstructed = curr_block->composite; } else if (in_block) { if (isspace (*lp) || '#' == *lp) { list_add (curr_notes, xstrdup (lp)); last_was_note = TRUE; } else if (RECONSTRUCTED_LINE(lp)) { /* lp = strip_b (lp); */ if (last_was_note) { list_add (curr_notes, xstrdup ("")); last_was_note = FALSE; } new_composite (curr_block, lp); last_was_note = FALSE; } else { /* lp = strip_b (lp); */ if (last_was_note) { list_add (curr_notes, xstrdup ("")); last_was_note = FALSE; } new_source (curr_block, lp); last_was_note = FALSE; } } else { warning (matrix_location(), "junk in matrix, outside of block"); } } else { list_add (curr_stuff, xstrdup (lp)); } } /* in case we didn't have a </matrix> tag */ if (list_len (multi_column_entries)) fix_multis (); file_close (); } }