File: readhttp.c

package info (click to toggle)
libowfat 0.22-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,148 kB
  • ctags: 976
  • sloc: ansic: 10,424; makefile: 42
file content (27 lines) | stat: -rw-r--r-- 824 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "stralloc.h"
#include "buffer.h"
#include "byte.h"

/* this demonstrates the buffer_get_token_sa_pred interface;
 * ishttp is the predicate that determines when buffer_get_token_sa_pred
 * stops reading.  It is supposed to return 0 if the token is not
 * complete and 1 if it is.  It can also return -1 to indicate an error,
 * for example you could enforce a timeout here or limit the token size. */

int ishttp(stralloc* sa) {
  return (sa->len>4 && byte_equal(sa->s+sa->len-4,4,"\r\n\r\n"));
}

int main() {
  stralloc sa;
  int res;

  stralloc_init(&sa);
  res=buffer_get_token_sa_pred(buffer_0,&sa,ishttp);
  buffer_puts(buffer_1,"buffer_get_token_sa_pred returned ");
  buffer_putlong(buffer_1,res);
  buffer_putsflush(buffer_1,".\n\n");
  buffer_putsa(buffer_1,&sa);
  buffer_flush(buffer_1);
  return 0;
}