本文整理汇总了C++中parse_request函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_request函数的具体用法?C++ parse_request怎么用?C++ parse_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_conn_read
static void handle_conn_read(struct conn *p_conn, struct pollfd *p_pollfd) {
/* Log some debug info. */
log_debug(NULL, "Reading connection %lu/socket %d (assigned pollfd %lu)",
(unsigned long) p_conn->conn_idx,
p_conn->sock,
(unsigned long) p_conn->pollfd_idx);
/* Parse the next portion of this client's request. */
switch (parse_request(p_conn)) {
case -1:
/* If an error occurred, bail out. */
handle_conn_delete(p_conn, p_pollfd);
case 0:
/* If no error occurred, but the request is not yet complete, try again
* when there's more data to be read. */
return;
}
/* Otherwise, no errors occurred and we got a complete selector. Now try to
* serve the requested resource. */
p_conn->stage = STAGE_RESPONSE_START;
p_pollfd->events = POLLOUT;
handle_conn_write(p_conn, p_pollfd);
}
示例2: main
int main(int argc, char* argv[])
{
const char* tmp;
const char* end;
int log_requests;
log_requests = getenv("LOGREQUESTS") != 0;
log_responses = getenv("LOGRESPONSES") != 0;
tmp = getenv("TIMEOUT");
if (tmp) {
if ((timeout = strtou(tmp, &end)) == 0 || *end != 0) {
respond(421, 1, "Configuration error, invalid timeout value");
return 1;
}
}
else
timeout = 900;
inbuf.io.timeout = timeout * 1000;
outbuf.io.timeout = timeout * 1000;
sig_alarm_catch(handle_alrm);
if (!startup(argc, argv)) return 1;
for (;;) {
int len = read_request();
if (len < 0) break;
parse_request(len);
if (!dispatch_request(internal_verbs, verbs, log_requests)) break;
}
return 0;
}
示例3: phr_parse_request
int phr_parse_request(const char* buf_start, size_t len, const char** method,
size_t* method_len, const char** path, size_t* path_len,
int* minor_version, struct phr_header* headers,
size_t* num_headers, size_t last_len)
{
const char * buf = buf_start, * buf_end = buf_start + len;
size_t max_headers = *num_headers;
int r;
*method = NULL;
*method_len = 0;
*path = NULL;
*path_len = 0;
*minor_version = -1;
*num_headers = 0;
/* if last_len != 0, check if the request is complete (a fast countermeasure
againt slowloris */
if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) {
return r;
}
if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len,
minor_version, headers, num_headers, max_headers,
&r))
== NULL) {
return r;
}
return buf - buf_start;
}
示例4: dispatch_request
void dispatch_request(char* from, char* to, int accept_socket, int* keep_alive){
char* req_str = (char*) malloc(sizeof(char) * (to - from + 1));
char* char_i;
int int_i;
int _ = 0;
for(char_i = from, int_i = 0; char_i < to; char_i++, int_i++){
*(req_str + int_i) = *(char_i);
}
*(req_str + int_i) = '\0';
struct request* req = malloc_request();
parse_request(req, req_str);
struct response* resp = malloc_response(req);
//free(req_str);
write_request(resp, accept_socket);
if(resp->html == 0){
read_file(req->resource_name, accept_socket);
} else{
_ = write(accept_socket, resp->html, strlen(resp->html));
}
if(_ == -1){
printf("scream write %d\n", _);
}
*keep_alive = req->keep_alive;
free(req_str);
free_request(req);
print_response(resp);
free_response(resp);
}
示例5: localhost
/**
* Listening and handling incoming requests
*/
void HttpServer::listen()
{
try
{
// Start server
boost::asio::io_service io_service;
tcp::endpoint localhost(tcp::v4(), this->port);
tcp::acceptor acceptor(io_service, localhost);
std::cout << "Server has started. Listening on address localhost:" << this->port
<< " (that's 127.0.0.1:" << this->port << " for you Windows folks).\n\n"
<< "Now type this address into your browser." << std::endl;
// Reply to incoming HTTP requests
while (1)
{
boost::system::error_code error_code;
// Accept connection
tcp::socket socket(io_service);
acceptor.accept(socket);
// Send HTTP response
std::string filepath = parse_request(socket, error_code);
boost::asio::write(socket, boost::asio::buffer(build_response(filepath)), error_code);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}
示例6: create_cache
// Create a new cache object with a given maximum memory capacity.
cache_t create_cache(uint64_t maxmem){
if (maxmem<1){
fprintf(stderr,"400 Bad Request.\n");
exit(2);
}
//Initialize cache
cache_t cache = (cache_t) calloc(1, sizeof(struct cache_obj));
assert(cache!=NULL&&"cache fails to allocate");
char * servername = SERVERNAME_DF;
char * servername_udp = SERVERNAME_DF;
char * portnum = PORTNUM_DF;
char * portnum_udp = PORTNUM_UDP_DF;
char buffer[MAXDATASIZE];
bzero(buffer,MAXDATASIZE);
char content[REQUESTSIZE];
bzero(content,REQUESTSIZE);
cache->sockfd = initialize_TCP_client(servername, portnum);
cache->sockfd_udp = initialize_UDP_client(servername_udp, portnum_udp);
//resize cache to maxmem
sprintf(content,"POST /memsize/%"PRIu64"",maxmem);
parse_request(buffer,content,SERVERNAME_DF);
if (write(cache->sockfd,buffer,strlen(buffer)) < 0)
{error("ERROR writing to socket");}
bzero(buffer,MAXDATASIZE);
if (read(cache->sockfd,buffer,MAXDATASIZE-1) < 0)
{error("ERROR reading from socket");}
return cache;
}
示例7: destroy_cache
// Destroy all resource connected to a cache object
void destroy_cache(cache_t cache){
if (cache==NULL){
fprintf(stderr,"400 Bad Request.\n");
exit(2);
}
char buffer[MAXDATASIZE];
bzero(buffer,MAXDATASIZE);
char content[REQUESTSIZE];
bzero(content,REQUESTSIZE);
sprintf(buffer,"POST /shutdown");
parse_request(content,buffer,SERVERNAME_DF);
if (write(cache->sockfd,content,strlen(content)) < 0)
{error("ERROR writing to socket");}
bzero(buffer,MAXDATASIZE);
if (read(cache->sockfd,buffer,MAXDATASIZE-1) < 0)
{error("ERROR reading from socket");}
// UDP version
// if (send(cache->sockfd_udp,buffer,strlen(buffer), 0) < 0)
// {error("ERROR sendto to socket");}
// bzero(buffer,MAXDATASIZE);
// if (recv(cache->sockfd_udp,buffer,MAXDATASIZE-1, 0 ) < 0)
// {error("ERROR recvfrom from socket");}
close(cache->sockfd);
free(cache);
}
示例8: cache_space_used
// Compute the total amount of memory used up by all cache values (not keys)
uint32_t cache_space_used(cache_t cache){
if (cache==NULL){
fprintf(stderr,"400 Bad Request.\n");
exit(2);
}
char buffer[MAXDATASIZE];
bzero(buffer,MAXDATASIZE);
char content[REQUESTSIZE];
bzero(content,REQUESTSIZE);
uint32_t space_use = 0;
sprintf(buffer,"HEAD /0");
parse_request(buffer,content,SERVERNAME_DF);
if (write(cache->sockfd,buffer,strlen(buffer)) < 0)
{error("ERROR writing to socket");}
bzero(buffer,MAXDATASIZE);
if (read(cache->sockfd,buffer,MAXDATASIZE-1) < 0)
{error("ERROR reading from socket");}
// UDP version
// if (send(cache->sockfd_udp,buffer,strlen(buffer), 0) < 0)
// {error("ERROR sendto to socket");}
// bzero(buffer,MAXDATASIZE);
// if (recv(cache->sockfd_udp,buffer,MAXDATASIZE-1, 0 ) < 0)
// {error("ERROR recvfrom from socket");}
get_spaceuse_from_head(buffer,&space_use);
return space_use;
}
示例9: main
int
main(int argc, char **argv)
{
char buffer[0x1000] = { 0 };
char user[0x100], pwd[0x100], cookie[0x100] = { 0 };
(void)(argc);
(void)(argv);
if (
!getenv("REQUEST_METHOD") ||
strcmp(getenv("REQUEST_METHOD"), "POST") ||
!fread(buffer, 1, sizeof(buffer) - 1, stdin)
)
login_page(NULL);
chomp(buffer);
if (parse_request(buffer, user, sizeof(user), pwd, sizeof(pwd)))
login_page("Missing username or password");
if (!match_user("db/members.csv", user, pwd))
login_page("Incorrect username or password");
if (set_cookie("db/loggedin.csv", user, cookie, sizeof(cookie)))
login_page("Internal error, please try again");
catalog_page(user, cookie);
return 0;
}
示例10: cache_set
// Add a <key, value> pair to the cache.
// If key already exists, it will overwrite the old value.
// If maxmem capacity is exceeded, sufficient values will be removed
// from the cache to accomodate the new value.
void cache_set(cache_t cache, key_type key, val_type val, uint32_t val_size){
if (cache==NULL || key==NULL || val==NULL || val_size==0){
fprintf(stderr,"400 Bad Request.\n");
exit(2);
}
char buffer[MAXDATASIZE];
bzero(buffer,MAXDATASIZE);
char content[REQUESTSIZE];
bzero(content,REQUESTSIZE);
sprintf(content,"PUT /%s/%s",(char *)key,(char *)val);
parse_request(buffer,content,SERVERNAME_DF);
//printf("buffer:%s\n",buffer);
if (write(cache->sockfd,buffer,strlen(buffer)) < 0)
{error("ERROR writing to socket");}
bzero(buffer,MAXDATASIZE);
if (read(cache->sockfd,buffer,MAXDATASIZE-1) < 0)
{error("ERROR reading from socket");}
// UDP version
// printf("buffer:%s\n",buffer);
// if (send(cache->sockfd_udp,buffer,strlen(buffer), 0) < 0)
// {error("ERROR sendto to socket");}
// bzero(buffer,MAXDATASIZE);
// if (recv(cache->sockfd_udp,buffer,MAXDATASIZE-1, 0 ) < 0)
// {error("ERROR recvfrom from socket");}
}
示例11: process_ser330
// Process SER330 command
// This changes the serial number in seneca.config file
// then restarts the q330serv program to use the new serial number
void process_ser330()
{
int64_t serno;
int count;
char cmdstr[80];
fprintf(stderr, "Processing %s\n", incmdbuf);
// Validate the serial number
++cmdcnt ;
parse_request(' ') ;
serno = 0 ;
count = sscanf(prsbuf,"%Lx", &serno) ;
if (count != 1)
{
send_data ("Unable to parse serial number\n") ;
return;
}
// Use a shell script to make changes, restart q330serv
sprintf(cmdstr, "newser330 %016Lx", serno);
if (system(cmdstr) == -1)
{
if (gDebug)
fprintf(stderr, "system(%s) returned error\n", cmdstr);
else
syslog(LOG_ERR, "system(%s) returned error\n", cmdstr);
send_data ("newser330 command returned error, status unknown\n") ;
return;
}
} // process_ser330()
示例12: route
void route (WiFiClient socket, Router *router, uint8_t *req) {
#else
void route (uint8_t socket, Router *router, uint8_t *req) {
#endif
Request *request;
Response *response;
request = parse_request(req);
response = response_create(socket);
if (router->write) {
response->write = router->write;
}
if (request->method == HTTP_ERROR) {
five_hundred(request, response);
} else {
int8_t found = find_route(router, request->path);
if (found != -1) {
router->routes[found].method(request, response);
} else {
four_oh_four(request, response);
}
}
}
示例13: replay_thread
void replay_thread(void *fd) {
int c_sock = (int)fd;
char in_buf[MAXDATA];
char out_buf[MAXDATA];
int size;
// TODO
/*while(1) {
memset(in_buf, 0, sizeof(in_buf));
size = 0;
size = read(c_sock, in_buf, sizeof(in_buf));
if (size == 0) {
break;
} else if (size == -1) {
perror("read");
exit(EXIT_FAILURE);
} else {
parse_request(in_buf);
}
}*/
memset(in_buf, 0, sizeof(in_buf));
size = read(c_sock, in_buf, sizeof(in_buf));
parse_request(in_buf);
memset(out_buf, 0, sizeof(out_buf));
create_response(out_buf, sizeof(out_buf));
write(c_sock, out_buf, sizeof(out_buf));
if ( close(c_sock) < 0) {
perror("close");
exit(EXIT_FAILURE);
}
printf("Thread Connection closed.\n");
}
示例14: sizeof
/*
@details
-# Loop until the connection is broken or timed_out
-# Call select to wait up to 15 seconds for a message.
-# If a message is found, read it into the incoming_msg buffer
-# Call parse_request on the incoming_msg buffer
-# Disconnect the socket connection
*/
void * Trick::JSONVariableServerThread::thread_body() {
int nbytes = -1 ;
socklen_t sock_size = sizeof(connection.remoteServAddr) ;
fd_set rfds;
struct timeval timeout_time = { 15, 0 };
bool timed_out = false ;
while (! timed_out and nbytes != 0 ) {
FD_ZERO(&rfds);
FD_SET(connection.socket, &rfds);
timeout_time.tv_sec = 15 ;
select(connection.socket + 1, &rfds, NULL, NULL, &timeout_time);
if ( FD_ISSET(connection.socket, &rfds)) {
nbytes = recvfrom( connection.socket, incoming_msg, MAX_CMD_LEN, 0 ,
(struct sockaddr *)&connection.remoteServAddr, &sock_size ) ;
//std::cout << "nbytes = " << nbytes << std::endl ;
if (nbytes != 0 ) {
//std::cout << incoming_msg << std::endl ;
parse_request() ;
}
} else {
timed_out = true ;
}
}
tc_disconnect(&connection) ;
//std::cout << "closed variable server connection" << std::endl ;
return NULL ;
}
示例15: server
void server(void)
{
// request re;
int size = sizeof(re);
int no = 0;
// recv(new_sockfd, &re, size, 0);
while(1)
{
recv(new_sockfd, &req_body, 1000, 0);
printf("%s\n", req_body);
// parse_request(req_body);
strcpy(res_body, "<h1> Hello </h1>");
send_response(
handle_request(
parse_request(req_body)
)
);
printf("%s", res_body);
send(new_sockfd, &res_body, sizeof(res_body), 0);
// shutdown(new_sockfd, SHUT_WR);
// return 0;
}
printf("NEW SOCKFD %d\n", new_sockfd);
new_sockfd = 0;
}