cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] RTMP: added swf verification options

From: Przemysław Iskra <sparky_at_pld-linux.org>
Date: Sat, 24 Jul 2010 00:41:46 +0200

Added three new options for swf verification in rtmpe tramsmissions:
- CURLOPT_RTMP_SWF_URL - pointer to a string
- CURLOPT_RTMP_SWF_SIZE - long
- CURLOPT_RTMP_SWF_HASH - pointer to binary data (32 bytes)

Additionally CURLOPT_REFERER is now recognized as rtmp page url.

---
 include/curl/curl.h |    5 +++++
 lib/curl_rtmp.c     |   22 ++++++++++++++++++++++
 lib/url.c           |   31 +++++++++++++++++++++++++++++++
 lib/urldata.h       |    3 +++
 4 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/include/curl/curl.h b/include/curl/curl.h
index b19828f..105aac0 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -1435,6 +1435,11 @@ typedef enum {
   /* FNMATCH_FUNCTION user pointer */
   CINIT(FNMATCH_DATA, OBJECTPOINT, 202),
 
+  /* set swf verification for rtmpe */
+  CINIT(RTMP_SWF_URL, OBJECTPOINT, 203),
+  CINIT(RTMP_SWF_SIZE, LONG, 204),
+  CINIT(RTMP_SWF_HASH, OBJECTPOINT, 205),
+
   CURLOPT_LASTENTRY /* the last unused */
 } CURLoption;
 
diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c
index df30dc1..6acd851 100644
--- a/lib/curl_rtmp.c
+++ b/lib/curl_rtmp.c
@@ -174,6 +174,28 @@ static CURLcode rtmp_setup(struct connectdata *conn)
     RTMP_Free(r);
     return CURLE_URL_MALFORMAT;
   }
+
+  if ( conn->data->set.rtmp_swf_size > 0 &&
+      conn->data->set.str[STRING_RTMP_SWF_HASH] != NULL )
+    {
+      memcpy(r->Link.SWFHash, conn->data->set.str[STRING_RTMP_SWF_HASH], sizeof(r->Link.SWFHash));
+      r->Link.SWFSize = conn->data->set.rtmp_swf_size;
+    }
+  else
+      r->Link.SWFSize = 0;
+
+  if ( conn->data->set.str[STRING_RTMP_SWF_URL] != NULL )
+    {
+      r->Link.swfUrl.av_val = conn->data->set.str[STRING_RTMP_SWF_URL];
+      r->Link.swfUrl.av_len = strlen( conn->data->set.str[STRING_RTMP_SWF_URL] );
+    }
+
+  if ( conn->data->change.referer != NULL )
+    {
+      r->Link.pageUrl.av_val = conn->data->change.referer;
+      r->Link.pageUrl.av_len = strlen( conn->data->change.referer );
+    }
+
   conn->proto.generic = r;
   return CURLE_OK;
 }
diff --git a/lib/url.c b/lib/url.c
index 4ed330e..bd2cbd5 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2482,6 +2482,37 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
   case CURLOPT_FNMATCH_DATA:
     data->set.fnmatch_data = va_arg(param, void *);
     break;
+
+  case CURLOPT_RTMP_SWF_URL:
+    result = setstropt(&data->set.str[STRING_RTMP_SWF_URL],
+                       va_arg(param, char *));
+    break;
+  case CURLOPT_RTMP_SWF_SIZE:
+    data->set.rtmp_swf_size = va_arg(param, long);
+    break;
+  case CURLOPT_RTMP_SWF_HASH:
+    argptr = va_arg(param, char *);
+
+    if(!argptr)
+      result = setstropt(&data->set.str[STRING_RTMP_SWF_HASH], NULL);
+    else {
+      const size_t hash_size = 32;
+      char * p;
+
+      (void) setstropt(&data->set.str[STRING_RTMP_SWF_HASH], NULL);
+
+      p = malloc( hash_size );
+
+      if(!p)
+        result = CURLE_OUT_OF_MEMORY;
+      else {
+        memcpy(p, argptr, hash_size);
+
+        data->set.str[STRING_RTMP_SWF_HASH] = p;
+      }
+    }
+    break;
+
   default:
     /* unknown tag and its companion, just ignore: */
     result = CURLE_FAILED_INIT; /* correct this */
diff --git a/lib/urldata.h b/lib/urldata.h
index 7763278..aaf94a6 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1245,6 +1245,8 @@ enum dupstring {
   STRING_SOCKS5_GSSAPI_SERVICE,  /* GSSAPI service name */
 #endif
   STRING_MAIL_FROM,
+  STRING_RTMP_SWF_URL,    /* uri string for swf verification in rtmpe */
+  STRING_RTMP_SWF_HASH,   /* hash for swf verification in rtmpe */
 
   /* -- end of strings -- */
   STRING_LAST /* not used, just an end-of-list marker */
@@ -1431,6 +1433,7 @@ struct UserDefined {
   curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds
                                     to pattern (e.g. if WILDCARDMATCH is on) */
   void *fnmatch_data;
+  long rtmp_swf_size;    /* size of the swf file to verify */
 };
 
 struct Names {
-- 
1.7.1
-- 
 ____  Sparky{PI] -- Przemyslaw _  ___  _  _  ......... LANG...Pl,Ca,Es,En
/____) ___  ___  _ _ || Iskra  |  | _ \| |  | : WWW...ppcrcd.pld-linux.org
\____\| -_)'___| ||^'||//\\// <   |  _/| |  | : WWW2..............rsget.pl
(____/||   (_-_|_||  ||\\ ||   |_ |_|  |_| _| : Mail..sparky_at_pld-linux.org
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-07-25