Example #1
0
gboolean li_gnutls_ocsp_search_datum(liServer *srv, liGnuTLSOCSP *ocsp, gnutls_datum_t const* file) {
	int r;
	gnutls_datum_t decoded = { NULL, 0 };
	gboolean result = FALSE;

	r = gnutls_pem_base64_decode_alloc("OCSP RESPONSE", file, &decoded);

	if (GNUTLS_E_SUCCESS <= r) {
		result = add_response(srv, ocsp, &decoded);
		if (!result) {
			ERROR(srv, "%s", "Failed loading OCSP response from PEM block");
			goto error;
		}
	} else if (GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR == r) {
		/* ignore GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR */
	} else {
		ERROR(srv, "gnutls_pem_base64_decode_alloc failed to decode OCSP RESPONSE from PEM block (%s): %s",
			gnutls_strerror_name(r), gnutls_strerror(r));
		/* continue anyway */
	}
	result = TRUE;

error:
	gnutls_free(decoded.data);
	return result;
}
Example #2
0
// function for finding the best keyword from the database
// this function also handles context and also verifies the
// boundaries of keywords that are found inside the user input
void Eliza::find_keyword() {
	response_list.clear();
	std::string bestKey;
	bool bGeneralKey = 0;
	int bestPos = -1;
	int dbase_size = database.size();
	for(int index = 0; index < dbase_size; ++index) {
		verify_context(database[index].contexts);
		if(good_context()) {
			keyword_list = database[index].keywords;
			size_t keyNum = keyword_list.size();
			for(int i = 0; i < keyNum; ++i) {
				std::string thisKey = keyword_list[i];
				std::string keyword = thisKey;
				trimLR(keyword, "_");
				keyword.insert(0, " ");
				keyword.append(" ");
				if(thisKey == "*" && bestKey == "") {
					keyword = m_sInput;
					bGeneralKey = 1;
				}
				int thisPos = m_sInput.find(keyword);
				if(thisPos == std::string::npos) {
					continue;
				}
				verify_keyword_boundary(thisKey, thisPos);
				if(wrong_boundary()) {
					continue;
				} 
				if(bGeneralKey) {
					thisKey = "*";
					bGeneralKey = 0;
				}
				trimLR(thisKey, "_");
				if(isGoodKey(thisKey, bestKey, thisPos, bestPos)) {
					if(thisKey.length() > bestKey.length()) {
						response_list = database[index].responses;
					} else {
						add_response(database[index].responses);
					}
					bestKey = thisKey;
					bestPos = thisPos;
				}
			}
		}
	}
	bestKey == "*" ? m_sKeyWord = m_sInput : m_sKeyWord = bestKey;
}
Example #3
0
static void
serve_file( struct evhttp_request * req,
            struct tr_rpc_server *  server,
            const char *            filename )
{
    if( req->type != EVHTTP_REQ_GET )
    {
        evhttp_add_header( req->output_headers, "Allow", "GET" );
        send_simple_response( req, 405, NULL );
    }
    else
    {
        size_t content_len;
        uint8_t * content;
        const int error = errno;

        errno = 0;
        content_len = 0;
        content = tr_loadFile( filename, &content_len );

        if( errno )
        {
            send_simple_response( req, HTTP_NOTFOUND, filename );
        }
        else
        {
            struct evbuffer * out;

            errno = error;
            out = tr_getBuffer( );
            evhttp_add_header( req->output_headers, "Content-Type",
                               mimetype_guess( filename ) );
            add_response( req, server, out, content, content_len );
            evhttp_send_reply( req, HTTP_OK, "OK", out );

            tr_releaseBuffer( out );
            tr_free( content );
        }
    }
}
Example #4
0
gboolean li_gnutls_ocsp_add(liServer *srv, liGnuTLSOCSP *ocsp, const char* filename) {
	int r;
	gnutls_datum_t file = { NULL, 0 };
	gnutls_datum_t decoded = { NULL, 0 };
	gnutls_datum_t* der_data;
	gboolean result = FALSE;

	if (GNUTLS_E_SUCCESS > (r = gnutls_load_file(filename, &file))) {
		ERROR(srv, "Failed to load OCSP file '%s' (%s): %s",
				filename,
				gnutls_strerror_name(r), gnutls_strerror(r));
		goto error;
	}

	/* decode pem "-----BEGIN OCSP RESPONSE-----", otherwise expect DER */
	if (file.size > 20 && 0 == memcmp(file.data, CONST_STR_LEN("-----BEGIN "))) {
		r = gnutls_pem_base64_decode_alloc("OCSP RESPONSE", &file, &decoded);

		if (GNUTLS_E_SUCCESS > r) {
			ERROR(srv, "gnutls_pem_base64_decode_alloc failed to decode OCSP RESPONSE from '%s' (%s): %s",
				filename,
				gnutls_strerror_name(r), gnutls_strerror(r));
			goto error;
		}
		der_data = &decoded;
	} else {
		der_data = &file;
	}

	result = add_response(srv, ocsp, der_data);
	if (!result) {
		ERROR(srv, "Failed loading OCSP response from '%s'", filename);
	}

error:
	gnutls_free(file.data);
	gnutls_free(decoded.data);
	return result;
}
Example #5
0
bool service::add_content(const char* content)
{
	return add_response("%s",content);
}
Example #6
0
bool service::add_date()
{
	time_t timep;
	time (&timep);
	return add_response("Date: %s",ctime(&timep));
}
Example #7
0
bool service::add_blank_line()
{
	return add_response("%s","\r\n");
}
Example #8
0
bool service::add_content_length(int content_len)
{
	return add_response("Content-Length: %d \r\n",content_len);
}
Example #9
0
bool service::add_status_line(int status,const char* title)
{
	return add_response("%s %d %s\r\n","HTTP/1.1,",status,title);
}
Example #10
0
void service::add_page_error(int status,char* s_status,char* msg)
{
    add_response("<html><head></head><body><h1> %s </h1><hr>Reage Web Server 0.01</body></head>", msg);
    add_http_head(status, s_status, "text/html");
}
Example #11
0
void WebRequest::add_template_response (const char *buffer, int len)
{
	bool part_found;
	int index;
	int part_num;
	int count;
	char last_ch;
	char part_name[128];
	const char *part;
	const char *ptr;


	ptr = buffer;
	count = 1;
	for (index = 1; index < len; index ++)
	{
		if ((((index > 1) && (buffer[index-2] != '\\')) || (index < 2)) && (buffer[index-1] == '$') && (buffer[index] == '{'))
		{
			add_response (ptr, &buffer[index] - ptr - 1);

			index ++;
			ptr = &buffer[index];
			count = 0;

			while ((index < len) && (buffer[index] != '}'))
			{
				index += 1;
				count += 1;
			}

			if ((index < len) && (buffer[index] == '}'))
			{
				index += 1;
			}

			memcpy (part_name, ptr, count);
			
			part_name[count] = 0;
			
			part = WebPart::get (part_name, this);

			if (part)
			{
				add_template_response (part, strlen (part));
			}
			else
			{
				part_found = false;
				for (part_num = 0; part_num < maximum_number_of_request_parts; part_num ++)
				{
					if ((part_key[part_num]) && (strcasecmp (part_key[part_num], part_name) == 0))
					{
						add_template_response (part_value[part_num], strlen (part_value[part_num]));
						part_found = true;
						break;
					}
				}

				if (!part_found)
				{
					add_response ("${", 2);
					add_response (part_name, strlen (part_name));
					add_response ("}", 1);
				}
			}

			ptr = &buffer[index];
			count = 0;
		}
		else
		{
			count ++;
		}
	}

	add_response (ptr, count);
}