Exemple #1
0
void CTimedThread::DoHttpPost( void )
{
    
	char PostData[1024] = {0};
    char data[255] = {0};
    

    result= 1;
	sprintf(PostData,"APP=%s&ADAPTER=%s&MACHINE=%s&VERSION=%s&VALUES=%s",App,Adapter,FullName,Version,Values);


	HTTP    *http = new HTTP;
	LPCTSTR pData = 0x00;
	UINT    Length = 0;

	int ret_code;
	ret_code    =  http->SetContentType("application/x-www-form-urlencoded");
	ret_code    =  http->SetPostData(PostData,strlen(PostData) );
	ret_code    =  http->Post("http://www.imagesafe.biz/docugate/index.asp");

	if (ret_code == 0 )
	{
		http->GetTransferredData( pData, Length);
	    if ( strstr( pData,"***TERMINATE***") )
				 result = 0;
	}

	delete http;
}
Exemple #2
0
/*
 * This static method is used to load catalog config info and return the
 * error status (0 is OK, 1 for error).
 *
 * The argument should be a catalog entry of type "directory", where the
 * URL points to the catalog config file. There may be multiple such
 * entries in the form of a catalog server tree.
 */
int CatalogInfo::load(CatalogInfoEntry* e) {
    // loop through the url list until success
    HTTP http;
    int nlines = 0;
    char * s = http.get(e->url(), nlines);
    if (!s) 
	return 1; // http error

    char* ctype = (http.content_type() ? http.content_type() : (char*)"");
    if (strcmp(ctype, "text/html") == 0) {
	// most likely an error message
	return http.html_error(s);
    }

    istringstream is(s);
    e->link(load(is, e->url()));
    if (! e->link()) 
	return 1;		// input error

    // if it is a local config file, allow URL commands
    if (strncmp(e->url(), "file:", 5) == 0)
	HTTP::allowUrlExec(1);
	    
    return 0;	// normal return
}
Exemple #3
0
int main(int argc, char *argv[]){
    HTTP hp;

    hp.parser(argv[1]);
    #ifdef DEBUG
    hp.show();
    #endif
}
void *run(void *argument){

	int client_fd;
	char buffer[1024];
	int n;
	
	bzero(buffer,1024);
	client_fd = * (int *)argument;
	bool alive = true;

	cout << "New Thread Started With Client FD: " << client_fd << endl << endl;

	while ( (n = read(client_fd,buffer,1024)) > -1 ){

		if( n > 0){
			cout << "Request from Client: " << endl << buffer << endl;
			
			HTTP* http = new HTTP();
			string response_string;
			if( http->parse_request(buffer) ){
				
				// Success Parsing the request
				if(http->connection.compare(CLOSE) == 0){
					alive = false;
				}

				response_string = get_response_stream(http);

			}else{

				// Failure Parsing the request
				response_string = http->prepare_response(BD,"",false);
				alive = false;
			}

			write(client_fd,response_string.c_str(),response_string.length());

			bzero(buffer,1024);

		}

		if(!alive){
			cout << "Thread with client FD closed: " << client_fd << endl;
			break;
		}

	}

	if ( n < 0){
		cerr << "Abrupt Close of Client Socket" << endl;
		exit(5);
	}
	cout << "Client Socket FD closed" << endl;
	close(client_fd);
}
Exemple #5
0
void
Client::start (System::Socket* socket)
{
    HTTP* request = new HTTP;
    while (!request->done()) {
        std::string string = socket->readLine().toString();
        request->request(string);
    }

    HTTP* response = new HTTP;
    if (request->isOk()) {
        try {
            response->setData(System::readFile(
                Config::get("directories->document[path]")+System::normalizePath(request->getUri())
            ));

            response->setStatus(200);
            response->setVersion(request->getVersion());

            response->setHeader("Connection", "close");
            response->setHeader("Content-Type", Mime::getType(request->getUri()));
            response->setHeader("Content-Length", response->getData().length());
            response->setHeader("Server", "lulzHTTPd/0.1");

            socket->send(response->get());
        }
        catch (Exception e) {
            std::stringstream resp;
            resp << "WUT, ARE YOU BLIND? :O" << std::endl;

            response->setStatus(404);
            response->setVersion(request->getVersion());

            response->setHeader("Connection", "close");
            response->setHeader("Content-Type", "text/plain");
            response->setHeader("Content-Length", resp.str().length());
            response->setHeader("Server", "lulzHTTPd/0.1");

            response->setData(resp.str());

            socket->send(response->get());
        }
    }
    else {
        std::stringstream resp;
        resp << "F****T IT'S A BAD REQUEST" << std::endl;

        response->setStatus(request->getStatus());
        response->setVersion(request->getVersion() ? request->getVersion() : 1.0);

        response->setHeader("Connection", "close");
        response->setHeader("Content-Type", "text/plain");
        response->setHeader("Content-Length", resp.str().length());
        response->setHeader("Server", "lulzHTTPd/0.1");

        response->setData(resp.str());

        socket->send(response->get());
    }

    delete request;
    delete response;
    delete socket;
}
Exemple #6
0
bool
Inventory::Send(const char* serverUrl)
{
	HTTP httpObject;

	// Send Prolog
	std::cerr << "Inventory::Send(): Prolog... ";
	tinyxml2::XMLDocument prolog;
	_WriteProlog(prolog);
	char* prologData = NULL;
	size_t prologLength = 0;
	if (!XML::Compress(prolog, prologData, prologLength)) {
		std::cerr << "error compressing prolog XML" << std::endl;
		return false;
	}

	std::string inventoryUrl(serverUrl);

	HTTPRequestHeader requestHeader;
	requestHeader.SetRequest("POST", inventoryUrl);
	requestHeader.SetValue("Pragma", "no-cache");
	requestHeader.SetValue("Keep-Alive", "300");
	requestHeader.SetValue("Connection", "Keep-Alive, TE");
	requestHeader.SetValue("TE", "deflate, gzip");
	requestHeader.SetContentType("application/x-compress");
	requestHeader.SetContentLength(prologLength);
	requestHeader.SetUserAgent(USER_AGENT);
	if (httpObject.Request(requestHeader, prologData, prologLength) != 0) {
		delete[] prologData;
		std::cerr << "cannot send prolog: ";
		std::cerr << httpObject.ErrorString() << std::endl;
		return false;
	}

	delete[] prologData;

	std::cerr << "OK!" << std::endl;

	std::cerr << "Inventory::Send(): waiting for server response... ";
	const HTTPResponseHeader& responseHeader = httpObject.LastResponse();
	if (responseHeader.StatusCode() != HTTP_OK
			|| !responseHeader.HasContentLength()) {
		std::cout << responseHeader.ToString() << std::endl;
		return false;
	}

	size_t contentLength = ::strtol(responseHeader.Value(HTTPContentLength).c_str(), NULL, 10);
	char* resultData = new char[contentLength];
	if (httpObject.Read(resultData, contentLength) < (int)contentLength) {
		delete[] resultData;
		std::cerr << "failed to read XML response: ";
		std::cerr << httpObject.ErrorString() << std::endl;
		return false;
	}

	std::cerr << "OK!" << std::endl;

	std::cerr << "Inventory::Send(): Decompressing XML... ";
	tinyxml2::XMLDocument document;
	bool uncompress = XML::Uncompress(resultData, contentLength, document);
	delete[] resultData;
	if (!uncompress) {
		std::cerr << "failed to decompress XML" << std::endl;
		return false;
	}
		
	std::cerr << "OK!" << std::endl;

	std::string serverResponse = XML::GetTextElementValue(document, "RESPONSE");
	std::cerr << "Inventory::Send(): server replied " << serverResponse;
	if (serverResponse != "SEND") {
		std::cerr << ": server not ready to accept inventory" << std::endl;
		return false;
	}
	
	std::cerr << ": OK!" << std::endl;

	std::cerr << "Inventory::Send(): Compressing XML inventory data... ";
	char* compressedData = NULL;
	size_t compressedSize;
	if (!XML::Compress(*fDocument, compressedData, compressedSize)) {
		std::cerr << "error compressing inventory XML" << std::endl;
		return false;
	}

	std::cerr << "OK!" << std::endl;

	std::cerr << "Inventory::Send(): Sending inventory...";
	requestHeader.Clear();
	requestHeader.SetRequest("POST", inventoryUrl);
	requestHeader.SetValue("Pragma", "no-cache");
	requestHeader.SetValue("Keep-Alive", "300");
	requestHeader.SetValue("Connection", "Keep-Alive, TE");
	requestHeader.SetValue("TE", "deflate, gzip");
	requestHeader.SetContentType("application/x-compress");
	requestHeader.SetContentLength(compressedSize);
	requestHeader.SetUserAgent(USER_AGENT);
	if (httpObject.Request(requestHeader, compressedData, compressedSize) != 0) {
		delete[] compressedData;
		std::cerr << "cannot send inventory: ";
		std::cerr << httpObject.ErrorString() << std::endl;
		return false;
	}

	std::cerr << "OK!" << std::endl;

	delete[] compressedData;

	return true;
}
void http_on_connection_event(HTTPConnection* c, HTTPConnectionEvent event, const char* data, size_t len, void* user) {
  HTTP* h = static_cast<HTTP*>(user);
  h->removeConnection(c);
}