//------------------------------------------------------------------------------ void Console::initDir() { //build root mRootDir = new AbsDir(pac::delim); setCwd(&sgRootDir); AbsDir* uiDir = new AbsDir("consoleUi", mUi); mRootDir->addChild(uiDir, false); }
bool NetDebugReport::Process() { wxDebugReportCompress::Process(); //compress files into zip wxString filename = GetCompressedFileName(); CwdGuard setCwd( wxPathOnly( filename ) ); wxLogMessage( filename ); wxStringOutputStream response; wxStringOutputStream rheader; CURL *curl_handle; curl_handle = curl_easy_init(); struct curl_slist* m_pHeaders = NULL; struct curl_httppost* m_pPostHead = NULL; struct curl_httppost* m_pPostTail = NULL; struct curl_forms testform[2]; // these header lines will overwrite/add to cURL defaults m_pHeaders = curl_slist_append(m_pHeaders, "Expect:") ; testform[0].option = CURLFORM_FILE; //we need to keep these buffers around for curl op duration wxCharBuffer filename_buffer = filename.mb_str(); testform[0].value = (const char*)filename_buffer; testform[1].option = CURLFORM_END; curl_formadd(&m_pPostHead, &m_pPostTail, CURLFORM_COPYNAME, "file", CURLFORM_ARRAY, testform, CURLFORM_END); curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, m_pHeaders); curl_easy_setopt(curl_handle, CURLOPT_URL, m_url ); // curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "SpringLobby"); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, wxcurl_stream_write); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&response); curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *)&rheader); curl_easy_setopt(curl_handle, CURLOPT_POST, TRUE); curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, m_pPostHead); CURLcode ret = curl_easy_perform(curl_handle); wxLogError( rheader.GetString() ); /* cleanup curl stuff */ curl_easy_cleanup(curl_handle); curl_formfree(m_pPostHead); wxString szResponse; if(ret == CURLE_OK) szResponse = wxT("SUCCESS!\n\n"); else szResponse = wxT("FAILURE!\n\n"); szResponse += wxFormat(wxT("\nResponse Code: %d\n\n") ) % ret; szResponse += rheader.GetString(); szResponse += wxT("\n\n"); szResponse += response.GetString(); szResponse += wxT("\n\n"); wxLogMessage( szResponse ); return ret == CURLE_OK; }
/* * main function - executes ecerything and runs in infinite loop until stopped via CTRL+C */ int main(void){ //Initialize current time for Session-start time(&now); //Get the username and capitalize it. username = getlogin(); username[0] = toupper(username[0]); //prints a one-time welcome message promptWelcomeMsg(); //Handle CTRL+C and CTRL+Z 'manually'. //The strategy basically is: Do nothing for the parent process when there is a child-process signal(SIGINT, interruptHandler); signal(SIGTSTP, tstpHandler); //initializes variables for reading line and prompt-message char *line; char mashPrompt[LINE_LENGTH + 3]; //set 'cwd' to the current work directory and set prompt-message setCwd(); snprintf(mashPrompt, sizeof(mashPrompt), "%s >> ", cwd); //reads lines until EOF is detected, using the GNU readline library while((line = readline(mashPrompt)) != NULL){ int status; //If user presses enter without any character ignore the command if (line[0] != 0){ //saving commant to history, using GNU readline library add_history(line); }else{ continue; } //Forking the child process, which then handles the read line, as well as error handling. if ((childPID=fork())==0){ //For child-process only; parses and executes command //printf("\nChild Process with %u started. Parent Process ID: %u \n", getpid(), getppid()); parseCmdLine(line); }else if(childPID == -1){ //Failure, no child process is created fprintf(stderr, "Unfortunately there was a little mess-up, %s\n", username); }else{ //For parent-process: Waits on child pid_t result = waitpid(childPID, &status, WUNTRACED); if (result == -1) { //waitpid was not succesfull fprintf(stderr, "Something under the hood went terribly wrong. Just try again, %s", username); } else { //Everything succesfully executed; Set childPID to -1, //so signal-handler functions know there is no child-process running childPID = -1; free(line); } } //Theoretically to check if the user has changed directory. Since cd isn't built in yet, doesn't really have a function setCwd(); snprintf(mashPrompt, sizeof(mashPrompt), "%s >> ", cwd); } return EXIT_SUCCESS; }