[rtmpdump] r130 - in trunk: Makefile README rtmpdump.c rtmpsuck.c streams.c swfvfy.c
hyc
subversion at mplayerhq.hu
Tue Dec 29 11:59:25 CET 2009
Author: hyc
Date: Tue Dec 29 11:59:24 2009
New Revision: 130
Log:
Drop libcurl stuff
Modified:
trunk/Makefile
trunk/README
trunk/rtmpdump.c
trunk/rtmpsuck.c
trunk/streams.c
trunk/swfvfy.c
Modified: trunk/Makefile
==============================================================================
--- trunk/Makefile Tue Dec 29 09:36:46 2009 (r129)
+++ trunk/Makefile Tue Dec 29 11:59:24 2009 (r130)
@@ -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)
Modified: trunk/README
==============================================================================
--- trunk/README Tue Dec 29 09:36:46 2009 (r129)
+++ trunk/README Tue Dec 29 11:59:24 2009 (r130)
@@ -19,7 +19,7 @@ but you may need to override the CROSS_C
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
Modified: trunk/rtmpdump.c
==============================================================================
--- trunk/rtmpdump.c Tue Dec 29 09:36:46 2009 (r129)
+++ trunk/rtmpdump.c Tue Dec 29 11:59:24 2009 (r130)
@@ -46,14 +46,8 @@
#include "parseurl.h"
#ifdef CRYPTO
-#include <curl/curl.h>
#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
Modified: trunk/rtmpsuck.c
==============================================================================
--- trunk/rtmpsuck.c Tue Dec 29 09:36:46 2009 (r129)
+++ trunk/rtmpsuck.c Tue Dec 29 11:59:24 2009 (r130)
@@ -46,14 +46,8 @@
#endif
#ifdef CRYPTO
-#include <curl/curl.h>
#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
Modified: trunk/streams.c
==============================================================================
--- trunk/streams.c Tue Dec 29 09:36:46 2009 (r129)
+++ trunk/streams.c Tue Dec 29 11:59:24 2009 (r130)
@@ -38,14 +38,8 @@
#endif
#ifdef CRYPTO
-#include <curl/curl.h>
#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
Modified: trunk/swfvfy.c
==============================================================================
--- trunk/swfvfy.c Tue Dec 29 09:36:46 2009 (r129)
+++ trunk/swfvfy.c Tue Dec 29 11:59:24 2009 (r130)
@@ -21,9 +21,18 @@
#include <stdio.h>
#include <string.h>
+#ifdef WIN32
+#include <winsock.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+#endif
+
#include <openssl/sha.h>
#include <openssl/hmac.h>
-#include <curl/curl.h>
#include <zlib.h>
struct info {
@@ -82,24 +91,129 @@ swfcrunch(void *ptr, size_t size, size_t
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];
- if (!strncmp(p, "Last-Modified: ", 15))
+ 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')
{
- 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';
+ ssl = 1;
+ port = 443;
}
- return len;
+
+ 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);
+ }
+
+ sa.sin_addr.s_addr = inet_addr(host);
+ if (sa.sin_addr.s_addr == INADDR_NONE)
+ {
+ struct hostent *hp = gethostbyname(host);
+ if (!hp || !hp->h_addr)
+ return -1;
+ sa.sin_addr = *(struct in_addr *)hp->h_addr;
+ }
+ 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
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
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
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);
More information about the rtmpdump
mailing list