File: httpdate.c

package info (click to toggle)
publicfile 0.52-14
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 900 kB
  • sloc: ansic: 3,903; makefile: 472; sh: 296
file content (38 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
35
36
37
38
#include "caltime.h"
#include "httpdate.h"

static char *weekday[7] = {
  " Sun, ", " Mon, ", " Tue, ", " Wed, ", " Thu, ", " Fri, ", " Sat, "
} ;

static char *month[12] = {
  " Jan ", " Feb ", " Mar ", " Apr ", " May ", " Jun "
, " Jul ", " Aug ", " Sep ", " Oct ", " Nov ", " Dec "
} ;

int httpdate(stralloc *sa,struct tai *t)
{
  struct caltime ct;
  int i;

  caltime_utc(&ct,t,&i,(int *) 0);

  if (i < 0) i = 0;
  if (i > 6) i = 6;
  if (!stralloc_copys(sa,weekday[i])) return 0;
  if (!stralloc_catuint0(sa,ct.date.day,2)) return 0;
  i = ct.date.month - 1;
  if (i < 0) i = 0;
  if (i > 11) i = 11;
  if (!stralloc_cats(sa,month[i])) return 0;
  if (!stralloc_catuint0(sa,ct.date.year,0)) return 0;
  if (!stralloc_cats(sa," ")) return 0;
  if (!stralloc_catuint0(sa,ct.hour,2)) return 0;
  if (!stralloc_cats(sa,":")) return 0;
  if (!stralloc_catuint0(sa,ct.minute,2)) return 0;
  if (!stralloc_cats(sa,":")) return 0;
  if (!stralloc_catuint0(sa,ct.second,2)) return 0;
  if (!stralloc_cats(sa," GMT")) return 0;

  return 1;
}