bool FServerIrcBotPlugin::serve(const message& msg) { BUG_COMMAND(msg); //--------------------------------------------------- // get_nickname() : Lelly // get_user() : ~lelly // get_host() : wibble.wobble // get_userhost() : [email protected] // get_nick() : Lelly // get_chan() : #ommo // get_user_cmd() : !ommo // get_user_params() : Test #1.zip //--------------------------------------------------- if(done.load()) { bot.fc_reply_pm_notice(msg, "Declined, server shutting down"); return true; } bot.fc_reply(msg, "This is a test."); // !ommo Test #1.zip str data_dir = bot.get("fserver.data.dir", bot.get_data_folder()); bug_var(data_dir); request_file(msg, data_dir + '/' + msg.get_user_params()); return true; }
/*====================================================== * llrpt_pageout -- Output current page and clear page buffer * usage: pageout() -> VOID *====================================================*/ PVALUE llrpt_pageout (PNODE node, SYMTAB stab, BOOLEAN *eflg) { char scratch[MAXCOLS+2]; STRING p; INT row, i; node=node; /* unused */ stab=stab; /* unused */ *eflg = TRUE; if (outputmode != PAGEMODE) return NULL; if (!Poutfp) { if (!request_file(eflg)) return NULL; setbuf(Poutfp, NULL); } *eflg = FALSE; scratch[__cols] = '\n'; scratch[__cols+1] = 0; p = pagebuffer; for (row = 1; row <= __rows; row++) { memcpy(scratch, p, __cols); for (i = __cols - 1; i > 0 && scratch[i] == ' '; i--) ; scratch[i+1] = '\n'; scratch[i+2] = 0; fputs(scratch, Poutfp); p += __cols; } memset(pagebuffer, ' ', __rows*__cols); return NULL; }
// Request a file long __asm __saveds HookFileRequest( register __a0 struct Window *parent, register __a1 char *title, register __a2 char *initial_path, register __a3 char *pathname, register __d0 ULONG flags, register __d1 char *pattern) { return request_file(parent,title,pathname,initial_path,flags,pattern); }
/*====================================+ * llrpt_outfile -- Return output file name * usage: outfile() -> STRING *===================================*/ PVALUE llrpt_outfile (PNODE node, SYMTAB stab, BOOLEAN *eflg) { node=node; /* unused */ stab=stab; /* unused */ if (!Poutfp) { if (!request_file(eflg)) return NULL; setbuf(Poutfp, NULL); } *eflg = FALSE; return create_pvalue_from_string(outfilename); }
TEST(RequestTest, Parsing) { std::ifstream request_file("sample_request", std::ios::binary); Request::buffer *raw_request = new Request::buffer(std::istreambuf_iterator<char>(request_file), std::istreambuf_iterator<char>()); Request request; request.raw_request = raw_request; EXPECT_EQ(true, request.parse()); EXPECT_EQ(request.request_line[0], "GET"); EXPECT_EQ(request.request_line[1], "/"); EXPECT_EQ(request.request_line[2], "HTTP/1.1"); EXPECT_EQ(request.headers["Connection"], "Keep-Alive"); }
/* * Prompt for a key file to add, and add it. */ static void prompt_add_keyfile(void) { OPENFILENAME of; char *filelist = snewn(8192, char); if (!keypath) keypath = filereq_new(); memset(&of, 0, sizeof(of)); of.hwndOwner = hwnd; of.lpstrFilter = FILTER_KEY_FILES; of.lpstrCustomFilter = NULL; of.nFilterIndex = 1; of.lpstrFile = filelist; *filelist = '\0'; of.nMaxFile = 8192; of.lpstrFileTitle = NULL; of.lpstrTitle = "Select Private Key File"; of.Flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER; if (request_file(keypath, &of, TRUE, FALSE)) { if (strlen(filelist) > of.nFileOffset) { /* Only one filename returned? */ Filename *fn = filename_from_str(filelist); win_add_keyfile(fn); filename_free(fn); } else { /* we are returned a bunch of strings, end to * end. first string is the directory, the * rest the filenames. terminated with an * empty string. */ char *dir = filelist; char *filewalker = filelist + strlen(dir) + 1; while (*filewalker != '\0') { char *filename = dupcat(dir, "\\", filewalker, NULL); Filename *fn = filename_from_str(filename); win_add_keyfile(fn); filename_free(fn); sfree(filename); filewalker += strlen(filewalker) + 1; } } keylist_update(); pageant_forget_passphrases(); } sfree(filelist); }
/* * Prompt for a key file. Assumes the filename buffer is of size * FILENAME_MAX. */ static int prompt_keyfile(HWND hwnd, char *dlgtitle, char *filename, int save, int ppk) { OPENFILENAME of; memset(&of, 0, sizeof(of)); of.hwndOwner = hwnd; if (ppk) { of.lpstrFilter = "PuTTY Private Key Files (*.ppk)\0*.ppk\0" "All Files (*.*)\0*\0\0\0"; of.lpstrDefExt = ".ppk"; } else { of.lpstrFilter = "All Files (*.*)\0*\0\0\0"; } of.lpstrCustomFilter = NULL; of.nFilterIndex = 1; of.lpstrFile = filename; *filename = '\0'; of.nMaxFile = FILENAME_MAX; of.lpstrFileTitle = NULL; of.lpstrTitle = dlgtitle; of.Flags = 0; return request_file(NULL, &of, FALSE, save); }
bool FServerIrcBotPlugin::files(const message& msg) { BUG_COMMAND(msg); if(done.load()) { bot.fc_reply_pm_notice(msg, "Declined, server shutting down"); return true; } // make zip file // ommo-ebooks-YYYY-MM-DD.txt str data_dir = bot.get("fserver.data.dir", bot.get_data_folder()); bug_var(data_dir); str fname = data_dir; fname += "/" + bot.get("fserver.index.file.prefix", bot.nick + "-files"); fname += "-" + todays_date(); if(!have_zip(data_dir, fname)) return false; request_file(msg, fname + ".zip"); return true; }
int main (int argc, char* argv[]) { menu_option current_option; // Menu action char arg[BUFSIZE]; // Menu action argument char *host; // Hostname to connect to short portnum; // Port of the server int sock, // Socket to host conn; // Connection to the host // Get server hostname if (argc == 3) { host = argv[1]; // Extract the hostname portnum = atoi(argv[2]); // Extract the port number } else { fprintf(stderr, "Usage: %s <host> <port>\n", argv[0]); exit(1); } // Initialize the connection printf("Connecting..."); fflush(stdout); if (setup(host, portnum, &sock, &conn) < 0) { fprintf(stderr, "\nCould not connect to %s:%d\n", host, portnum); exit(1); } printf("\rConnected to %s:%d\n", host, portnum); // Request the desired action from the user for (;;) { current_option = handle_input(host, arg, sizeof(arg)); switch (current_option) { // Close the socket before quitting case QUIT: close(sock); exit(1); break; case LISTFILES: if (request_file_list(sock) < 0) fatal("[!!] Request File List failed."); break; case GETFILE: if (request_file(sock, arg) < 0) fatal("[!!] Request Get File failed."); break; case PUTFILE: if (request_put(sock, arg) < 0) fatal("[!!] Request Put File failed."); break; case RENAMEFILE: if (request_rename(sock, arg) < 0) fatal("[!! Request Rename failed."); break; default: fprintf(stderr, "[!!] Unknown command\n"); break; } } return 0; }
/*========================================+ * poutput -- Output string in current mode *=======================================*/ void poutput (STRING str, BOOLEAN *eflg) { STRING p; ZSTR zstr = 0; INT c, len; XLAT ttmr = transl_get_predefined_xlat(MINRP); if (!str || (len = strlen(str)) <= 0) return; zstr = translate_string_to_zstring(ttmr, str); str = zs_str(zstr); if ((len = strlen(str)) <= 0) goto exit_poutput; if (!Poutfp) { if (!request_file(eflg)) goto exit_poutput; setbuf(Poutfp, NULL); } switch (outputmode) { case UNBUFFERED: fwrite(str, len, 1, Poutfp); adjust_cols(str); goto exit_poutput; case BUFFERED: if (len >= 1024) { fwrite(linebuffer, linebuflen, 1, Poutfp); fwrite(str, len, 1, Poutfp); linebuflen = 0; bufptr = (STRING)linebuffer; adjust_cols(str); goto exit_poutput; } if (len + linebuflen >= 1024) { fwrite(linebuffer, linebuflen, 1, Poutfp); linebuflen = 0; bufptr = (STRING)linebuffer; } linebuflen += len; while ((c = *bufptr++ = *str++)) { if (c == '\n') curcol = 1; else curcol++; } --bufptr; goto exit_poutput; case PAGEMODE: p = pagebuffer + (currow - 1)*__cols + curcol - 1; while ((c = *str++)) { if (c == '\n') { curcol = 1; currow++; p = pagebuffer + (currow - 1)*__cols; } else { if (curcol <= __cols && currow <= __rows) *p++ = c; curcol++; } } goto exit_poutput; default: FATAL(); } exit_poutput: zs_free(&zstr); }
void file_open_with(struct Window *window,char *name,ULONG flags) { char *buffer; short len,wb=0,ok=0; struct DiskObject *icon; // Allocate buffer if (!(buffer=AllocVec(1400,MEMF_CLEAR))) return; // App already selected? if (flags&(1<<30)) { short num; struct Node *node; // Get application number in list num=flags&~(1<<30); // Lock the list lock_listlock(&GUI->open_with_list,0); // Find the node for (node=GUI->open_with_list.list.lh_Head; node->ln_Succ; node=node->ln_Succ) { // Matched? if (num--==0) break; } // Valid node? if (node->ln_Succ) { // Get the application name strcpy(buffer+1,node->ln_Name); ok=1; } // Unlock the list unlock_listlock(&GUI->open_with_list); } // Need to ask? if (!ok) { // Build title lsprintf(buffer+1024,GetString(&locale,MSG_SELECT_APP),FilePart(name)); // Ask for file if (!(request_file( window, buffer+1024, buffer+1, 0, 0,0)) || !*(buffer+1)) { FreeVec(buffer); return; } // Add App to OpenWith list add_open_with(buffer+1); } // See if app has an icon if (icon=GetDiskObject(buffer+1)) { // Is it a tool? if (icon->do_Type==WBTOOL) { // Launch as Workbench App wb=1; } // Free icon FreeDiskObject(icon); } // Fill in quotes buffer[0]='\"'; buffer[(len=strlen(buffer))]='\"'; // Add filename in quotes buffer[len+1]=' '; buffer[len+2]='\"'; strcpy(buffer+len+3,name); buffer[(len=strlen(buffer))]='\"'; buffer[len+1]=0; // Launch the function file_launch(buffer,wb,"ram:"); // Free buffer FreeVec(buffer); }
void main_event_handler() { ULONG result; UWORD Code; static char *strinfo, *args; static char *path; int line=0; int *iptr; struct Node *node; uint32 addr; struct Process *pr; while ((result = RA_HandleInput(MainWinObj, &Code)) != WMHI_LASTMSG && done != TRUE) { switch (result & WMHI_CLASSMASK) { case WMHI_CLOSEWINDOW: done = TRUE; break; case WMHI_ICONIFY: if( RA_Iconify(MainWinObj) ) mainwin = NULL; break; case WMHI_UNICONIFY: mainwin = RA_Uniconify(MainWinObj); if( !mainwin ) done = TRUE; break; case WMHI_MENUPICK: if (Code != MENUNULL) switch (MENUNUM(Code)) { case MENU_FILE: switch(ITEMNUM(Code)) { case MENU_PREFS: preferences_open_window(); break; case MENU_MODULES: modules_open_window(); break; case MENU_ABOUT: show_about(); break; case MENU_QUIT: done = TRUE; break; } } break; case WMHI_GADGETUP: switch(result & WMHI_GADGETMASK) { case GAD_SELECT_BUTTON: strinfo = request_file(mainwin, &path); if (!strinfo) break; strcpy (filename, strinfo); if (strlen(path) > 0) { strcpy (childpath, path); } if(!request_arguments(&args)) { console_printf(OUTPUT_WARNING, "User aborted!"); break; } main_load (strinfo, path, args); break; case GAD_RELOAD_BUTTON: main_load(strinfo, path, args); break; case GAD_ATTACH_BUTTON: if(!isattached) { pr = attach_select_process(); if(main_attach (pr)) button_set_detach(); } else { console_printf(OUTPUT_SYSTEM, "Detaching from external process..."); detach(); stabs_free_stabs(); button_set_attach(); enable(TRUE, GAD_SELECT_BUTTON, TAG_END); enable(FALSE, GAD_START_BUTTON, GAD_PAUSE_BUTTON, GAD_KILL_BUTTON, GAD_STEPOVER_BUTTON, GAD_STEPINTO_BUTTON, GAD_STEPOUT_BUTTON, GAD_SETBREAK_BUTTON, GAD_HEX_BUTTON, TAG_END); console_printf(OUTPUT_SYSTEM, "Done!"); } break; case GAD_START_BUTTON: main_play(); break; case GAD_PAUSE_BUTTON: main_pause(); break; case GAD_STEPOVER_BUTTON: main_step(); break; case GAD_STEPINTO_BUTTON: main_into(); break; case GAD_STEPOUT_BUTTON: main_out(); break; case GAD_KILL_BUTTON: main_kill(); break; #if 0 case GAD_CRASH_BUTTON: crash(); break; #endif case GAD_SETBREAK_BUTTON: breakpoints_open_window(); break; case GAD_VARIABLES_LISTBROWSER: variables_handle_input(); break; case GAD_SIGNAL_BUTTON: sigwin_open_window(); break; case GAD_IMPORT_BUTTON: import_open_window(); break; case GAD_X_BUTTON: console_clear(); break; case GAD_HEX_BUTTON: hex_open_window(); break; case GAD_DISASSEMBLER_LISTBROWSER: disassembler_show_selected(); break; case GAD_DISASSEMBLER_STEP_BUTTON: asmstep(); should_continue = FALSE; asm_trace = TRUE; break; case GAD_DISASSEMBLER_SKIP_BUTTON: asmskip(); disassembler_makelist(); break; case GAD_SOURCE_LISTBROWSER: source_handle_input(); source_show_currentline(); break; case GAD_SOURCELIST_LISTBROWSER: sourcelist_handle_input(); break; case GAD_AREXX_BUTTON: case GAD_AREXX_STRING: { char *str; IIntuition->GetAttrs( MainObj[GAD_AREXX_STRING], STRINGA_TextVal, &str, TAG_DONE ); strcpy (arexxcommandstring, str); arexxexecute.MethodID = AM_EXECUTE; arexxexecute.ape_CommandString = arexxcommandstring; arexxexecute.ape_PortName = "AREXXDB101"; arexxexecute.ape_IO = (BPTR)NULL; IIntuition->SetAttrs( MainObj[GAD_AREXX_STRING], STRINGA_TextVal, "", TAG_DONE ); IIntuition->RefreshGadgets ((struct Gadget *)MainObj[GAD_AREXX_STRING], mainwin, NULL); console_printf(OUTPUT_AREXX, arexxcommandstring); IIntuition->IDoMethodA(arexx_obj, (Msg)&arexxexecute); //IIntuition->ActivateGadget((struct Gadget *)MainObj[GAD_AREXX_STRING], mainwin, NULL); ILayout->ActivateLayoutGadget((struct Gadget *)MainObj[GAD_TOPLAYOUT], mainwin, NULL, (uint32)MainObj[GAD_AREXX_STRING]); break; } } break; } } return; }
int httpserver_route_request(HttpSession *session) { if(httproute_call(session)!=200) return request_file(session,NULL); return 200; }