[xiph-cvs] cvs commit: httpp httpp.c httpp.h

Michael Smith msmith at xiph.org
Fri Mar 7 20:57:02 PST 2003



msmith      03/03/07 23:57:02

  Modified:    .        News
               src      connection.c
               .        httpp.c httpp.h
  Log:
  Added support for shoutcast login protocol (ewww...)

Revision  Changes    Path
1.3       +3 -0      icecast/News

Index: News
===================================================================
RCS file: /usr/local/cvsroot/icecast/News,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- News	7 Mar 2003 14:57:36 -0000	1.2
+++ News	8 Mar 2003 04:57:02 -0000	1.3
@@ -1,3 +1,6 @@
+2003-03-09
+    Support for shoutcast source protocol added.
+
 2003-03-08
     Started implementing generic admin interface. Supports (so far): 
     - dynamic configuration of mount fallbacks

<p><p>1.60      +33 -8     icecast/src/connection.c

Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/connection.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- connection.c	6 Mar 2003 14:46:33 -0000	1.59
+++ connection.c	8 Mar 2003 04:57:02 -0000	1.60
@@ -424,6 +424,20 @@
     return 1;
 }
 
+static int _check_pass_icy(http_parser_t *parser, char *correctpass)
+{
+    char *password;
+
+    password = httpp_getvar(parser, HTTPP_VAR_ICYPASSWORD);
+    if(!password)
+        return 0;
+
+	if (strcmp(password, correctpass))
+        return 0;
+    else
+        return 1;
+}
+
 static int _check_pass_ice(http_parser_t *parser, char *correctpass)
 {
     char *password;
@@ -469,6 +483,7 @@
     char *user = "source";
     int ret;
     int ice_login = config->ice_login;
+    char *protocol;
 
     mount_proxy *mountinfo = config->mounts;
     thread_mutex_lock(&(config_locks()->mounts_lock));
@@ -492,14 +507,19 @@
         return 0;
     }
 
-    ret = _check_pass_http(parser, user, pass);
-    if(!ret && ice_login)
-    {
-        ret = _check_pass_ice(parser, pass);
-        if(ret)
-            WARN0("Source is using deprecated icecast login");
+    protocol = httpp_getvar(parser, "HTTP_VAR_PROTOCOL");
+    if(protocol != NULL && !strcmp(protocol, "ICY")) {
+        ret = _check_pass_icy(parser, pass);
+    }
+    else {
+        ret = _check_pass_http(parser, user, pass);
+        if(!ret && ice_login)
+        {
+            ret = _check_pass_ice(parser, pass);
+            if(ret)
+                WARN0("Source is using deprecated icecast login");
+        }
     }
-
     return ret;
 }
 
@@ -849,7 +869,12 @@
                 }
 
                 free(uri);
-			} else {
+			} 
+            else if(httpp_parse_icy(parser, header, strlen(header))) {
+                /* TODO: Map incoming icy connections to /icy_0, etc. */
+                _handle_source_request(con, parser, "/");
+            }
+            else {
                 ERROR0("HTTP request parsing failed");
                                 connection_close(con);
                                 httpp_destroy(parser);

<p><p>1.14      +40 -2     httpp/httpp.c

Index: httpp.c
===================================================================
RCS file: /usr/local/cvsroot/httpp/httpp.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- httpp.c	6 Mar 2003 01:55:20 -0000	1.13
+++ httpp.c	8 Mar 2003 04:57:02 -0000	1.14
@@ -270,6 +270,42 @@
         }
 }
 
+/* The old shoutcast procotol. Don't look at this, it's really nasty */
+int httpp_parse_icy(http_parser_t *parser, char *http_data, unsigned long len)
+{
+    char *data;
+    char *line[MAX_HEADERS];
+    int lines;
+
+    if(http_data == NULL)
+        return 0;
+
+    data = malloc(len + 1);
+    memcpy(data, http_data, len);
+    data[len] = 0;
+
+	lines = split_headers(data, len, line);
+
+    /* Now, this protocol looks like:
+     * sourcepassword\n
+     * headers: as normal\n"
+     * \n
+     */
+
+    parser->req_type = httpp_req_source;
+    httpp_setvar(parser, HTTPP_VAR_URI, "/");
+    httpp_setvar(parser, HTTPP_VAR_ICYPASSWORD, line[0]);
+    httpp_setvar(parser, HTTPP_VAR_PROTOCOL, "ICY");
+    /* This protocol is evil */
+    httpp_setvar(parser, HTTPP_VAR_VERSION, "666");
+
+    parse_headers(parser, line, lines);
+
+    free(data);
+    
+    return 1;
+}
+
 int httpp_parse(http_parser_t *parser, char *http_data, unsigned long len)
 {
         char *data, *tmp;
@@ -348,8 +384,10 @@
                 }
 
                 parser->uri = strdup(uri);
-	} else
-		parser->uri = NULL;
+	} else {
+        free(data);
+        return 0;
+    }
 
         if ((version != NULL) && ((tmp = strchr(version, '/')) != NULL)) {
                 tmp[0] = '\0';

<p><p>1.7       +2 -0      httpp/httpp.h

Index: httpp.h
===================================================================
RCS file: /usr/local/cvsroot/httpp/httpp.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- httpp.h	16 Jan 2003 05:48:31 -0000	1.6
+++ httpp.h	8 Mar 2003 04:57:02 -0000	1.7
@@ -14,6 +14,7 @@
 #define HTTPP_VAR_REQ_TYPE "__req_type"
 #define HTTPP_VAR_ERROR_MESSAGE "__errormessage"
 #define HTTPP_VAR_ERROR_CODE "__errorcode"
+#define HTTPP_VAR_ICYPASSWORD "__icy_password"
 
 typedef enum httpp_request_type_tag {
         httpp_req_none, httpp_req_get, httpp_req_post, httpp_req_head,
@@ -40,6 +41,7 @@
 http_parser_t *httpp_create_parser(void);
 void httpp_initialize(http_parser_t *parser, http_varlist_t *defaults);
 int httpp_parse(http_parser_t *parser, char *http_data, unsigned long len);
+int httpp_parse_icy(http_parser_t *parser, char *http_data, unsigned long len);
 int httpp_parse_response(http_parser_t *parser, char *http_data, unsigned long len, char *uri);
 void httpp_setvar(http_parser_t *parser, char *name, char *value);
 char *httpp_getvar(http_parser_t *parser, char *name);

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list