From 09a0535db70e2ed406749768f071c491ba5fb85c Mon Sep 17 00:00:00 2001 From: hyc Date: Tue, 29 Dec 2009 10:59:24 +0000 Subject: [PATCH] Drop libcurl stuff git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@130 400ebc74-4327-4243-bc38-086b20814532 --- Makefile | 2 +- README | 2 +- rtmpdump.c | 10 ---- rtmpsuck.c | 10 ---- streams.c | 10 ---- swfvfy.c | 165 ++++++++++++++++++++++++++++++++++++++++++----------- 6 files changed, 134 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index 1a52104..1e0ad97 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ LD=$(CROSS_COMPILE)ld OPT=-O2 CFLAGS=-Wall $(XCFLAGS) $(INC) $(OPT) LDFLAGS=-Wall $(XLDFLAGS) -LIBS=-lcrypto -lcurl -lz +LIBS=-lcrypto -lz THREADLIB=-lpthread SLIBS=$(THREADLIB) $(LIBS) diff --git a/README b/README index 542ea7f..b7460c8 100644 --- a/README +++ b/README @@ -19,7 +19,7 @@ but you may need to override the CROSS_COMPILE and INC variables, e.g. Please read the Makefile to see what other make variables are used. -This code also requires you to have OpenSSL, curl, and zlib installed. +This code also requires you to have OpenSSL and zlib installed. SWF Verification diff --git a/rtmpdump.c b/rtmpdump.c index 50c509c..f7ddb0a 100644 --- a/rtmpdump.c +++ b/rtmpdump.c @@ -46,14 +46,8 @@ #include "parseurl.h" #ifdef CRYPTO -#include #define HASHLEN 32 extern int SWFVerify(const char *url, unsigned int *size, unsigned char *hash); -#define InitCurl() curl_global_init(CURL_GLOBAL_ALL) -#define FreeCurl() curl_global_cleanup() -#else -#define InitCurl() -#define FreeCurl() #endif #define RTMPDUMP_VERSION "v2.0" @@ -1154,8 +1148,6 @@ main(int argc, char **argv) return RD_FAILED; } - InitCurl(); - /* sleep(30); */ int opt; @@ -1718,8 +1710,6 @@ clean: if (file != 0) fclose(file); - FreeCurl(); - CleanupSockets(); #ifdef _DEBUG diff --git a/rtmpsuck.c b/rtmpsuck.c index 4de8a1e..f9dd187 100644 --- a/rtmpsuck.c +++ b/rtmpsuck.c @@ -46,14 +46,8 @@ #endif #ifdef CRYPTO -#include #define HASHLEN 32 extern int SWFVerify(const char *url, unsigned int *size, unsigned char *hash); -#define InitCurl() curl_global_init(CURL_GLOBAL_ALL) -#define FreeCurl() curl_global_cleanup() -#else -#define InitCurl() -#define FreeCurl() #endif #define RTMPDUMP_PROXY_VERSION "v2.0" @@ -1016,8 +1010,6 @@ main(int argc, char **argv) InitSockets(); - InitCurl(); - // start text UI ThreadCreate(controlServerThread, 0); @@ -1037,8 +1029,6 @@ main(int argc, char **argv) } Log(LOGDEBUG, "Done, exiting..."); - FreeCurl(); - CleanupSockets(); #ifdef _DEBUG diff --git a/streams.c b/streams.c index 41e982f..0cbc0b9 100644 --- a/streams.c +++ b/streams.c @@ -38,14 +38,8 @@ #endif #ifdef CRYPTO -#include #define HASHLEN 32 extern int SWFVerify(const char *url, unsigned int *size, unsigned char *hash); -#define InitCurl() curl_global_init(CURL_GLOBAL_ALL) -#define FreeCurl() curl_global_cleanup() -#else -#define InitCurl() -#define FreeCurl() #endif #define RTMPDUMP_STREAMS_VERSION "v2.0" @@ -1156,8 +1150,6 @@ main(int argc, char **argv) InitSockets(); - InitCurl(); - while ((opt = getopt_long(argc, argv, "hvqVzr:s:t:p:a:f:u:n:c:l:y:m:d:D:A:B:T:g:w:x:W:", longopts, @@ -1288,8 +1280,6 @@ main(int argc, char **argv) } Log(LOGDEBUG, "Done, exiting..."); - FreeCurl(); - CleanupSockets(); #ifdef _DEBUG diff --git a/swfvfy.c b/swfvfy.c index e56f14a..56806e5 100644 --- a/swfvfy.c +++ b/swfvfy.c @@ -21,9 +21,18 @@ #include #include +#ifdef WIN32 +#include +#else +#include +#include +#include +#include +#include +#endif + #include #include -#include #include struct info { @@ -82,24 +91,129 @@ swfcrunch(void *ptr, size_t size, size_t nmemb, void *stream) return size * nmemb; } -static size_t -hdrcrunch(void *ptr, size_t size, size_t nmemb, void *stream) +#define AGENT "Mozilla/5.0" + +static int +http_get(const char *url, struct info *in) { - struct info *i = stream; - char *p = ptr; - size_t len = size * nmemb; + char *host, *path; + char *p1, *p2; + char hbuf[256]; + int port = 80; + int ssl = 0; + int hlen, flen; + int s = -1, rc, i, ret = 0; + FILE *sf = NULL; + struct sockaddr_in sa; + char buf[4096]; + + memset(&sa, 0, sizeof(struct sockaddr_in)); + sa.sin_family = AF_INET; + + /* we only handle http here */ + if (strncasecmp(url, "http", 4)) + return -1; + + if (url[4] == 's') + { + ssl = 1; + port = 443; + } + + p1 = strchr(url+4, ':'); + if (!p1 || strncmp(p1, "://", 3)) + return -1; + + host = p1+3; + path = strchr(host, '/'); + hlen = path - host; + strncpy(hbuf, host, hlen); + hbuf[hlen] = '\0'; + host = hbuf; + p1 = strrchr(host, ':'); + if (p1) + { + *p1++ = '\0'; + port = atoi(p1); + } - if (!strncmp(p, "Last-Modified: ", 15)) + sa.sin_addr.s_addr = inet_addr(host); + if (sa.sin_addr.s_addr == INADDR_NONE) { - int l = len-15; - strncpy(i->date, p+15, l); - if (i->date[l-1] == '\n') - l--; - if (i->date[l-1] == '\r') - l--; - i->date[l] = '\0'; + struct hostent *hp = gethostbyname(host); + if (!hp || !hp->h_addr) + return -1; + sa.sin_addr = *(struct in_addr *)hp->h_addr; } - return len; + sa.sin_port = htons(port); + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (s < 0) + return -1; + i = sprintf(buf, "GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\n", path, AGENT, host); + if (in->date[0]) + i += sprintf(buf+i, "If-Modified-Since: %s\r\n", in->date); + i += sprintf(buf+i, "\r\n"); + + if (connect(s, (struct sockaddr *)&sa, sizeof(struct sockaddr)) < 0) + { + ret = -1; + goto leave; + } + write(s, buf, i); + sf = fdopen(s, "rb"); + + if (!fgets(buf, sizeof(buf), sf)) + { + ret = -1; + goto leave; + } + if (strncmp(buf, "HTTP/1", 6)) + { + ret = -1; + goto leave; + } + + p1 = strchr(buf, ' '); + rc = atoi(p1+1); + + /* not modified */ + if (rc == 304) + goto leave; + + while(fgets(buf, sizeof(buf), sf)) + { + if (!strncasecmp(buf, "Content-Length: ", sizeof("Content-Length: ")-1)) + { + flen = atoi(buf+sizeof("Content-Length: ")-1); + } + else if (!strncasecmp(buf, "Last-Modified: ", sizeof("Last-Modified: ")-1)) + { + p1 = buf+sizeof("Last-Modified: ")-1; + p2 = strchr(p1, '\r'); + *p2 = '\0'; + strcpy(in->date, p1); + } + else if (buf[0] == '\r') + break; + } + + hlen = sizeof(buf); + while ((i=fread(buf, 1, hlen, sf))>0) + { + swfcrunch(buf, 1, i, in); + flen -= i; + if (flen < 1) + break; + if (hlen > flen) + hlen = flen; + } + +leave: + if (sf) + fclose(sf); + else if (s >= 0) + close(s); + return ret; } #define HEX2BIN(a) (((a)&0x40)?((a)&0xf)+9:((a)&0xf)) @@ -112,10 +226,7 @@ SWFVerify(const char *url, unsigned int *size, unsigned char *hash) long pos = 0; int i, got = 0, ret = 0; unsigned int hlen; - CURL *c; - char csbuf[96]; - struct curl_slist cs = {csbuf}; - struct info in; + struct info in = {0}; z_stream zs = {0}; HMAC_CTX ctx; @@ -167,7 +278,7 @@ SWFVerify(const char *url, unsigned int *size, unsigned char *hash) else if (!strncmp(buf, "date: ", 6)) { buf[strlen(buf)-1] = '\0'; - strncpy(date, buf, sizeof(date)); + strncpy(date, buf+6, sizeof(date)); got++; } else if (!strncmp(buf, "url: ", 5)) @@ -185,19 +296,7 @@ SWFVerify(const char *url, unsigned int *size, unsigned char *hash) in.ctx = &ctx; in.zs = &zs; - c = curl_easy_init(); - curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, swfcrunch); - curl_easy_setopt(c, CURLOPT_WRITEDATA, &in); - curl_easy_setopt(c, CURLOPT_HEADERFUNCTION, hdrcrunch); - curl_easy_setopt(c, CURLOPT_HEADERDATA, &in); - curl_easy_setopt(c, CURLOPT_URL, url); - if (date[0]) - { - sprintf(csbuf, "If-Modified-Since: %s", date); - curl_easy_setopt(c, CURLOPT_HTTPHEADER, &cs); - } - ret = curl_easy_perform(c); - curl_easy_cleanup(c); + ret = http_get(url, &in); inflateEnd(&zs); -- 2.50.1