e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
1b10db2002-10-08Martin Nilsson 
dc071c1999-11-14Per Hedbor #include <global.h>
8382082000-11-04Henrik Grubbström (Grubba)  #include "config.h"
dc071c1999-11-14Per Hedbor #include <threads.h> #include <fdlib.h> #ifdef _REENTRANT #include <errno.h> #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif
486dbe2003-04-23Marcus Comstedt #include "pike_netlib.h"
dc071c1999-11-14Per Hedbor #include "accept_and_parse.h" #include "util.h" int aap_get_time(void) { static int t = 0; static int last_time;
f4ef462016-01-12Martin Nilsson  if(!(t++%10)) last_time = time(0);
dc071c1999-11-14Per Hedbor  return last_time; }
1f3cb02000-08-09Henrik Grubbström (Grubba) ptrdiff_t aap_swrite(int to, char *buf, size_t towrite)
dc071c1999-11-14Per Hedbor {
1f3cb02000-08-09Henrik Grubbström (Grubba)  ptrdiff_t res=0; ptrdiff_t sent = 0;
dc071c1999-11-14Per Hedbor  while(towrite) { while((res = fd_write(to, buf, towrite)) < 0) { switch(errno) { case EAGAIN: case EINTR: continue; default: if(errno != EPIPE) perror("accept_and_parse->request->shuffle: While writing"); res = 0; return sent; } } towrite -= res; buf += res; sent += res; } return sent; } int aap_get_header(struct args *req, char *header, int operation, void *res) {
bea2ad2000-08-14Henrik Grubbström (Grubba)  ptrdiff_t os=0;
1f3cb02000-08-09Henrik Grubbström (Grubba)  ptrdiff_t i, hl=strlen(header), l=req->res.body_start-req->res.header_start;
dc071c1999-11-14Per Hedbor  char *in = req->res.data + req->res.header_start; for(i=0; i<l; i++) { switch(in[i]) { case ':': /* in[os..i-1] == the header */ if(i-os == hl) {
81c56d2013-02-07Henrik Grubbström (Grubba)  /* Inlined strncasecmp(header, in + os, hl). */
1f3cb02000-08-09Henrik Grubbström (Grubba)  ptrdiff_t j;
dc071c1999-11-14Per Hedbor  for(j=0;j<hl; j++) if((in[os+j]&95) != (header[j]&95)) break; /* no match */ if(j == hl) { struct pstring *r = res; switch(operation) { case H_EXISTS: return 1; case H_INT: *((int *)res) = atoi(in+i+1); return 1; case H_STRING: os = i+1; for(j=os;j<l;j++) if(in[j] == '\r') break; /* okie.. */ while(in[os]==' ') os++; r->len = j-os; r->str = in+os; return 1; } } }
81c56d2013-02-07Henrik Grubbström (Grubba)  break;
dc071c1999-11-14Per Hedbor  case '\r': case '\n': os = i+1; } } return 0;
13670c2015-05-25Martin Nilsson }
dc071c1999-11-14Per Hedbor #endif