void HttpdSocket::OnData(const char *p,size_t l) { if (m_file) { m_file -> fwrite(p,1,l); } m_received += l; if (m_received >= m_content_length && m_content_length) { // all done if (m_file && !m_form) { m_form = new HttpdForm(m_file, m_content_type, m_content_length); AddResponseHeader("Date", datetime2httpdate(GetDate()) ); if (GetUri() == "/image") { Send64(Utility::Logo, "image/png"); } else { Exec(); } Reset(); // prepare for next request } } }
void CurlDownloaderRequest::SendImpl () { LOG_CURL ("BRIDGE CurlDownloaderRequest::Send %p\n", this); if (IsAborted ()) return; VERIFY_MAIN_THREAD state = OPENED; if (isPost ()) curl_easy_setopt(curl, CURLOPT_POST, 1); // we're ready to start the connection, set the headers response = new CurlDownloaderResponse (bridge, this); curl_easy_setopt (curl, CURLOPT_URL, GetUri ()); curl_easy_setopt (curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, data_received); curl_easy_setopt (curl, CURLOPT_WRITEDATA, response); curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, header_received); curl_easy_setopt (curl, CURLOPT_WRITEHEADER, response); response->Open (); }
JSONItem TextDocumentItem::ToJSON(const wxString& name) const { JSONItem json = JSONItem::createObject(name); json.addProperty("uri", wxFileSystem::FileNameToURL(GetUri())) .addProperty("languageId", GetLanguageId()) .addProperty("version", GetVersion()) .addProperty("text", GetText()); return json; }
void CGeneralAgentHttpServer::CreateHeader() { SetStatus("200"); SetStatusText("OK"); fprintf(stderr, "Uri: '%s'\n", GetUri().c_str()); { size_t x = 0; for (size_t i = 0; i < GetUri().size(); i++) if (GetUri()[i] == '.') x = i; std::string ext = GetUri().substr(x + 1); if (ext == "gif" || ext == "jpg" || ext == "png") AddResponseHeader("Content-type", "image/" + ext); else AddResponseHeader("Content-type", "text/" + ext); } AddResponseHeader("Connection", "close"); SendResponse(); }
void HttpRequest::SendAsync () { char *templ; VERIFY_MAIN_THREAD; LOG_DOWNLOADER ("HttpRequest::SendAsync () is_aborted: %i is_completed: %i\n", is_aborted, is_completed); if (is_aborted || is_completed) return; /* create tmp file */ if ((options & DisableFileStorage) == 0) { const char *dir = handler->GetDownloadDir (); if (dir == NULL) { Failed ("Could not create temporary download directory"); return; } templ = g_build_filename (dir, "XXXXXX", NULL); tmpfile_fd = g_mkstemp (templ); if (tmpfile_fd == -1) { char *msg = g_strdup_printf ("Could not create temporary download file %s for url %s\n", templ, GetUri ()); Failed (msg); g_free (msg); g_free (templ); return; } tmpfile = templ; LOG_DOWNLOADER ("HttpRequest::Send () uri %s is being saved to %s\n", GetUri (), tmpfile); } else { LOG_DOWNLOADER ("HttpRequest::Send () uri %s is not being saved to disk\n", GetUri ()); } #if DEBUG GetDeployment ()->AddSource (GetOriginalUri (), tmpfile == NULL ? "Not stored on disk" : tmpfile); #endif SendImpl (); }
void EQWHTTPHandler::Exec() { m_sentHeaders = false; m_responseCode = "200"; // printf("Request: %s, %s, %s, %s.\n", GetMethod().c_str(), GetUrl().c_str(), GetUri().c_str(), GetQueryString().c_str()); SetHttpVersion("HTTP/1.0"); AddResponseHeader("Connection", "close"); if(GetUri().find("..") != std::string::npos) { SendResponse("403", "Forbidden"); printf("%s is forbidden.\n", GetUri().c_str()); return; } if(!CheckAuth()) { AddResponseHeader("Content-type", "text/plain"); AddResponseHeader("WWW-Authenticate", "Basic realm=\"EQEmulator\""); SendResponse("401", "Authorization Required"); SendString("Gotta Authenticate."); } else { std::string::size_type start = GetUri().find_first_not_of('/'); std::string page; if(start != std::string::npos) page = GetUri().substr(start); else page = "index.html"; SendPage(page); } /* if (!Detach()) { printf("Unable to detach...\n"); } if(GetOutputLength() > 0) { //we cannot close yet m_closeOnFinish = true; } else { Close(); }*/ Free(); //the "app" side (us) is done with this connection too... Disconnect(); }
nsresult nsMailboxUrl::GetFolder(nsIMsgFolder **msgFolder) { // if we have a RDF URI, then try to get the folder for that URI and then ask the folder // for it's charset.... nsCString uri; GetUri(getter_Copies(uri)); NS_ENSURE_TRUE(!uri.IsEmpty(), NS_ERROR_FAILURE); nsCOMPtr<nsIMsgDBHdr> msg; GetMsgDBHdrFromURI(uri.get(), getter_AddRefs(msg)); if (!msg) return NS_ERROR_FAILURE; return msg->GetFolder(msgFolder); }
void HttpdSocket::OnHeaderComplete() { m_cookies = new HttpdCookies(m_http_cookie); if (GetMethod() == "GET") { Utility::SetEnv("QUERY_STRING", GetQueryString()); } Utility::SetEnv("REQUEST_METHOD", GetMethod()); Utility::SetEnv("HTTP_COOKIE", m_http_cookie); Utility::SetEnv("CONTENT_TYPE", m_content_type); Utility::SetEnv("CONTENT_LENGTH", m_content_length_str); if (GetMethod() == "POST") { m_file = new MemFile; } else if (GetMethod() == "GET") { m_form = new HttpdForm(GetQueryString(), GetQueryString().size() ); AddResponseHeader("Date", datetime2httpdate(GetDate()) ); if (GetUri() == "/image") { Send64(Utility::Logo, "image/png"); } else { Exec(); } Reset(); // prepare for next request } else { AddResponseHeader("Date", GetHttpDate()); AddResponseHeader("Connection", "close"); SetStatus("405"); SetStatusText("Method not allowed"); SendResponse(); } }