示例#1
0
文件: http.c 项目: berke/hhttppss
/*(*** http_parse_header_line */
int http_parse_header_line(http_header_line *hl, char *p, int m)
{
  scanbuf sb;
  int i;
  int name_i, name_j;
  int value_i, value_j;
  char *name;
  lines *value;

  scan_init(&sb, p, m);

#define check(x) if((x) < 0) return 0;

  name_i   = 0;
  name_j   = scan_alphabet_plus  (&sb, name_i, is_valid_header_name_char);   check(name_j);
  i        = scan_char           (&sb, name_j, ':');                         check(i);
  value_i  = scan_alphabet_plus  (&sb, i, is_valid_space);                   check(value_i);
  value_j  = sb.sb_length;

#undef check

  name     = scan_extract(&sb, name_i, name_j - 1);
  value    = lines_create(0, 0);
  lines_add_bytes(value, sb.sb_data + value_i, value_j - value_i);

  hl->hhl_allocated = 1;
  hl->hhl_name = name;
  hl->hhl_value = value;

  return 1;
}
示例#2
0
static void test_lines_printf(){
  struct line *l;

  l = lines_create();
  assert_valid_line(l);

  lines_printf(l, "a = %.1f, b=%.2e", 1.234, 56.789);
  assert_valid_line(l);
  assert(0 == strcmp(l->line_buffer, "a = 1.2, b=5.68e+01") ||
         0 == strcmp(l->line_buffer, "a = 1.2, b=5.68e+001") );

  lines_printf(l, "%s %s %s",
               "A very long line with lots of characters",
               "to test the ability of lines_printf to cope",
               "with lines longer than the default buffer size");
  assert_valid_line(l);

  lines_printf(l, "oldbuffer");

  /* Check the ability to use the old buffer as input */
  lines_printf(l, "Previous buffer was '%s' i.e. old '%s'",
               l->line_buffer, (l->line_buffer)+3);
  assert_valid_line(l);

  assert(0 == strcmp(l->line_buffer,
         "Previous buffer was 'oldbuffer' i.e. old 'buffer'"));

  lines_free(l);
}
示例#3
0
文件: http.c 项目: berke/hhttppss
/*(*** http_create */
http *http_create(server *sv, connection *cn, struct sockaddr_in *sa)
{
  http *ht;

  ht = xmalloc(sizeof(http));
  ht->ht_sockaddr = *sa;
  ht->ht_server = sv;
  ht->ht_connection = cn;
  ht->ht_lines = lines_create(http_eater, ht);
  ht->ht_state = HTTP_REQUEST;
  ht->ht_response = 0;
  ht->ht_hhl.hhl_allocated = 0;
  ht->ht_hrl.hrl_allocated = 0;
  ht->ht_writer = 0;
  ht->ht_resource = 0;
  return ht;
}