1 | #include "pshare.h" |
---|
2 | #include <stdio.h> |
---|
3 | #include <time.h> |
---|
4 | |
---|
5 | namespace pshare |
---|
6 | { |
---|
7 | int get_gmt_date(char* dst,int ndst) |
---|
8 | { |
---|
9 | time_t timestamp=time(0); |
---|
10 | |
---|
11 | tm* t=gmtime(×tamp); |
---|
12 | |
---|
13 | static const char* wd[7]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
---|
14 | static const char* m[12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; |
---|
15 | |
---|
16 | return snprintf(dst,ndst,"%s, %i %s %.4i %.2i:%.2i:%.2i GMT",wd[t->tm_wday],t->tm_mday,m[t->tm_mon],t->tm_year+1900, |
---|
17 | t->tm_hour,t->tm_min,t->tm_sec); |
---|
18 | } |
---|
19 | |
---|
20 | // const char xbox360_extra_hdrs[]="X-User-Agent: redsonic\r\n"; |
---|
21 | |
---|
22 | int print_http_hdrs(FILE* fp,const char* content_type,int extras) |
---|
23 | { |
---|
24 | char date[64]; |
---|
25 | get_gmt_date(date,sizeof(date)); |
---|
26 | |
---|
27 | fprintf(fp, |
---|
28 | "HTTP/1.1 200 OK\r\nPragma: no-cache\r\nCache-control: no-cache\r\nDate: %s\r\nServer: %s\r\nAccept-Ranges: none\r\n" |
---|
29 | "Connection: close\r\nContent-Type: %s\r\nEXT:\r\n", |
---|
30 | date,server_name,content_type); |
---|
31 | |
---|
32 | // if(xbox360) |
---|
33 | // fprintf(fp,"%s",xbox360_extra_hdrs); |
---|
34 | |
---|
35 | if(!extras) |
---|
36 | fprintf(fp,"\r\n"); |
---|
37 | |
---|
38 | return 0; |
---|
39 | } |
---|
40 | |
---|
41 | int print_http_hdrs_no_content(FILE* fp,int extras) |
---|
42 | { |
---|
43 | char date[64]; |
---|
44 | get_gmt_date(date,sizeof(date)); |
---|
45 | |
---|
46 | fprintf(fp, |
---|
47 | "HTTP/1.1 200 OK\r\nPragma: no-cache\r\nCache-control: no-cache\r\nDate: %s\r\nServer: %s\r\nAccept-Ranges: none\r\n" |
---|
48 | "Connection: close\r\nContent-Length: 0\r\nEXT:\r\n",date,server_name); |
---|
49 | |
---|
50 | // if(xbox360) |
---|
51 | // fprintf(fp,"%s",xbox360_extra_hdrs); |
---|
52 | |
---|
53 | if(!extras) |
---|
54 | fprintf(fp,"\r\n"); |
---|
55 | |
---|
56 | return 0; |
---|
57 | } |
---|
58 | |
---|
59 | int print_http_error_hdrs(FILE* fp,const char* status,int extras) |
---|
60 | { |
---|
61 | char date[64]; |
---|
62 | get_gmt_date(date,sizeof(date)); |
---|
63 | |
---|
64 | fprintf(fp,"HTTP/1.1 %s\r\nPragma: no-cache\r\nCache-control: no-cache\r\nDate: %s\r\nServer: %s\r\nConnection: close\r\nEXT:\r\n", |
---|
65 | status,date,server_name); |
---|
66 | |
---|
67 | // if(xbox360) |
---|
68 | // fprintf(fp,"%s",xbox360_extra_hdrs); |
---|
69 | |
---|
70 | if(!extras) |
---|
71 | fprintf(fp,"\r\n"); |
---|
72 | |
---|
73 | return 0; |
---|
74 | } |
---|
75 | } |
---|