]>
cvs.zerfleddert.de Git - record-dvb/blob - http.c
6 #include <sys/socket.h>
7 #include <netinet/in.h>
15 int is_http(char *url
)
20 if (!strncasecmp("http://",url
,7))
26 int open_http(char *url
)
29 struct sockaddr_in server
;
30 static struct dvb_host
*dvbhost
= NULL
;
31 char c
, buffer
[BUFFSIZE
], *pos
;
38 dvbhost
= parse(&(url
[7]), "80");
39 dvbhost
->socktype
= SOCK_STREAM
;
42 if (resolve(dvbhost
, &server
) < 0) {
46 if ((fd
= socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
)) < 0) {
51 if (connect(fd
, (struct sockaddr
*) &server
, sizeof(server
)) < 0) {
56 snprintf(buffer
, BUFFSIZE
-1, "GET /%s HTTP/1.0\n\n",dvbhost
->location
);
57 buffer
[BUFFSIZE
-1] = 0;
58 if (send(fd
, buffer
, strlen(buffer
), 0) < 0) {
65 if (recv(fd
, &c
, 1, 0) < 1) {
70 if (pos
-buffer
>= BUFFSIZE
)
77 if (pos
-buffer
> 0 && *(--pos
) == 0x0d)
84 printf("%d. %s (%d)\n", lines
, buffer
, pos
-buffer
);
87 if (strncasecmp("HTTP/", buffer
, 5)) {
88 fprintf(stderr
, "Wrong answer from server: %s\n", buffer
);
94 if (*(pos
++) == ' ') {
95 if(strncmp("200", pos
, 3)) {
96 fprintf(stderr
, "Wrong result-code: %s\n", buffer
);
104 fprintf(stderr
, "Wrong answer from server: %s\n", buffer
);