[xiph-cvs] cvs commit: libshout/src shout.c shout_private.h

Brendan brendan at xiph.org
Wed Jan 15 00:20:15 PST 2003



brendan     03/01/15 03:20:15

  Modified:    src      shout.c shout_private.h
  Log:
  Add default useragent (libshout/VERSION).
  Get all this reindenting out of the way

Revision  Changes    Path
1.16      +131 -135  libshout/src/shout.c

Index: shout.c
===================================================================
RCS file: /usr/local/cvsroot/libshout/src/shout.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- shout.c	15 Jan 2003 07:31:29 -0000	1.15
+++ shout.c	15 Jan 2003 08:20:15 -0000	1.16
@@ -19,8 +19,6 @@
 static int login_icy(shout_t *self);
 static int login_http_basic(shout_t *self);
 
-static int set_metadata_xaudiocast(shout_t *self, shout_metadata_t *metadata);
-
 /* -- public functions -- */
 
 shout_t *shout_new(void)
@@ -41,6 +39,11 @@
 
                 return NULL;
         }
+	if (shout_set_agent(self, LIBSHOUT_DEFAULT_USERAGENT) != SHOUTERR_SUCCESS) {
+		shout_free(self);
+
+		return NULL;
+	}
 
         self->port = LIBSHOUT_DEFAULT_PORT;
         self->format = LIBSHOUT_DEFAULT_FORMAT;
@@ -257,18 +260,67 @@
         return SHOUTERR_SUCCESS;
 }
 
+/* open second socket to server, send HTTP request to change metadata.
+ * TODO: prettier error-handling. */
 int shout_set_metadata(shout_t *self, shout_metadata_t *metadata)
 {
+	sock_t socket;
+	int rv;
+	char *encvalue;
+
         if (!self || !metadata)
                 return SHOUTERR_INSANE;
 
         if (!self->connected)
                 return SHOUTERR_UNCONNECTED;
+	if ((socket = sock_connect(self->host, self->port)) <= 0)
+		return SHOUTERR_NOCONNECT;
+
+	if (self->protocol == SHOUT_PROTOCOL_ICY)
+		rv = sock_write(socket, "GET /admin.cgi?mode=updinfo&pass=%s", self->password);
+	else if (self->protocol == SHOUT_PROTOCOL_HTTP)
+		rv = sock_write(socket, "GET /admin.cgi?mode=updinfo&mount=%s", self->mount);
+	else
+		rv = sock_write(socket, "GET /admin.cgi?mode=updinfo&pass=%s&mount=%s", self->password, self->mount);
+	if (!rv) {
+		sock_close(socket);
+		return SHOUTERR_SOCKET;
+	}
 
-	if (self->protocol == SHOUT_PROTOCOL_ICY || self->protocol == SHOUT_PROTOCOL_XAUDIOCAST)
-		return self->error = set_metadata_xaudiocast(self, metadata);
+	while (metadata) {
+		if (metadata->name) {
+			if (metadata->value) {
+				if (!(encvalue = util_url_encode(metadata->value))) {
+					rv = SHOUTERR_MALLOC;
+					break;
+				}
+				rv = sock_write(socket, "&%s=%s", metadata->name, encvalue);
+			} else
+				rv = sock_write(socket, "&%s", metadata->name);
 
-	return self->error = SHOUTERR_UNSUPPORTED;
+			free (encvalue);
+			
+			if (!rv) {
+				sock_close(socket);
+				return SHOUTERR_SOCKET;
+			}
+		}
+		rv = SHOUTERR_SUCCESS;
+		metadata = metadata->next;
+	}
+	if (rv != SHOUTERR_SUCCESS) {
+		sock_close(socket);
+		return rv;
+	}
+
+	if (!sock_write(socket, " HTTP/1.0\r\nUser-Agent: %s\r\n\r\n", shout_get_agent(self))) {
+		sock_close(socket);
+		return SHOUTERR_SOCKET;
+	}
+
+	sock_close(socket);
+
+	return SHOUTERR_SUCCESS;
 }
 
 /* getters/setters */
@@ -510,10 +562,10 @@
 
 const char *shout_get_agent(shout_t *self)
 {
-    if (!self)
-        return NULL;
+	if (!self)
+		return NULL;
 
-    return self->useragent;
+	return self->useragent;
 }
 
 
@@ -536,10 +588,10 @@
 
 const char *shout_get_user(shout_t *self)
 {
-    if (!self)
-        return NULL;
+	if (!self)
+		return NULL;
 
-    return self->user;
+	return self->user;
 }
 
 int shout_set_description(shout_t *self, const char *description)
@@ -722,78 +774,78 @@
 
 static int login_http_basic(shout_t *self)
 {
-    char header[4096];
-    http_parser_t *parser;
-    int code;
-    char *retcode, *realm;
+	char header[4096];
+	http_parser_t *parser;
+	int code;
+	char *retcode, *realm;
     
-    self->error = SHOUTERR_SOCKET;
+	self->error = SHOUTERR_SOCKET;
 
            self->socket = sock_connect(self->host, self->port);
-    if (self->socket <= 0) {
-	    return self->error = SHOUTERR_NOCONNECT;
-    }
-
-    if(send_http_request(self, NULL, NULL) != 0) {
-        sock_close(self->socket);
-        return self->error = SHOUTERR_SOCKET;
-    }
-
-    if (util_read_header(self->socket, header, 4096) == 0) {
-        /* either we didn't get a complete header, or we timed out */
-        sock_close(self->socket);
-	    return self->error = SHOUTERR_SOCKET;
-    }
-
-    parser = httpp_create_parser();
-    httpp_initialize(parser, NULL);
-    if (httpp_parse_response(parser, header, strlen(header), self->mount)) {
-        retcode = httpp_getvar(parser, HTTPP_VAR_ERROR_CODE);
-        code = atoi(retcode);
-        if(code >= 200 && code < 300) {
-            httpp_destroy(parser);
-	        return SHOUTERR_SUCCESS;
-        }
-        else if(code == 401) {
-            /* Don't really use this right now other than to check that it's
-             * present.
-             */
-            realm = httpp_getvar(parser, "www-authenticate");
-            if(realm) {
-                httpp_destroy(parser);
-                sock_close(self->socket);
-
-   	            self->socket = sock_connect(self->host, self->port);
-                if (self->socket <= 0)
-            	    return self->error = SHOUTERR_NOCONNECT;
-
-                if(send_http_request(self, self->user, self->password) != 0) {
-                    sock_close(self->socket);
-                    return self->error = SHOUTERR_SOCKET;
-                }
-
-                if (util_read_header(self->socket, header, 4096) == 0) {
-                    /* either we didn't get a complete header, or we timed out */
-                    sock_close(self->socket);
-	                return self->error = SHOUTERR_SOCKET;
-                }
-                parser = httpp_create_parser();
-                httpp_initialize(parser, NULL);
-                if (httpp_parse_response(parser, header, strlen(header), self->mount)) {
-                    retcode = httpp_getvar(parser, HTTPP_VAR_ERROR_CODE);
-                    code = atoi(retcode);
-                    if(code >= 200 && code < 300) {
-                        httpp_destroy(parser);
-            	        return SHOUTERR_SUCCESS;
-                    }
-                }
-            }
-        }
-    }
+	if (self->socket <= 0) {
+		return self->error = SHOUTERR_NOCONNECT;
+	}
 
-    httpp_destroy(parser);
-    sock_close(self->socket);
-    return self->error = SHOUTERR_REFUSED;
+	if(send_http_request(self, NULL, NULL) != 0) {
+		sock_close(self->socket);
+		return self->error = SHOUTERR_SOCKET;
+	}
+
+	if (util_read_header(self->socket, header, 4096) == 0) {
+		/* either we didn't get a complete header, or we timed out */
+		sock_close(self->socket);
+		return self->error = SHOUTERR_SOCKET;
+	}
+
+	parser = httpp_create_parser();
+	httpp_initialize(parser, NULL);
+	if (httpp_parse_response(parser, header, strlen(header), self->mount)) {
+		retcode = httpp_getvar(parser, HTTPP_VAR_ERROR_CODE);
+		code = atoi(retcode);
+		if(code >= 200 && code < 300) {
+			httpp_destroy(parser);
+			return SHOUTERR_SUCCESS;
+		}
+		else if(code == 401) {
+			/* Don't really use this right now other than to check that it's
+			* present.
+			*/
+			realm = httpp_getvar(parser, "www-authenticate");
+			if(realm) {
+				httpp_destroy(parser);
+				sock_close(self->socket);
+
+				self->socket = sock_connect(self->host, self->port);
+				if (self->socket <= 0)
+					return self->error = SHOUTERR_NOCONNECT;
+
+				if(send_http_request(self, self->user, self->password) != 0) {
+					sock_close(self->socket);
+					return self->error = SHOUTERR_SOCKET;
+				}
+
+				if (util_read_header(self->socket, header, 4096) == 0) {
+					/* either we didn't get a complete header, or we timed out */
+					sock_close(self->socket);
+					return self->error = SHOUTERR_SOCKET;
+				}
+				parser = httpp_create_parser();
+				httpp_initialize(parser, NULL);
+				if (httpp_parse_response(parser, header, strlen(header), self->mount)) {
+					retcode = httpp_getvar(parser, HTTPP_VAR_ERROR_CODE);
+					code = atoi(retcode);
+					if(code >= 200 && code < 300) {
+						httpp_destroy(parser);
+						return SHOUTERR_SUCCESS;
+					}
+				}
+			}
+		}
+	}
+
+	httpp_destroy(parser);
+	sock_close(self->socket);
+	return self->error = SHOUTERR_REFUSED;
 }
 
 static int login_ice(shout_t *self)
@@ -903,62 +955,6 @@
 
         if (!strstr(response, "OK"))
                 return SHOUTERR_NOLOGIN;
-
-	return SHOUTERR_SUCCESS;
-}
-
-/* open second socket to server, send HTTP request to change metadata.
- * TODO: prettier error-handling. */
-int set_metadata_xaudiocast(shout_t *self, shout_metadata_t *metadata)
-{
-	sock_t socket;
-	int rv;
-	char *encvalue;
-
-	if ((socket = sock_connect(self->host, self->port)) <= 0)
-		return SHOUTERR_NOCONNECT;
-
-	if (self->protocol == SHOUT_PROTOCOL_ICY)
-		rv = sock_write(socket, "GET /admin.cgi?mode=updinfo&pass=%s", self->password);
-	else
-		rv = sock_write(socket, "GET /admin.cgi?mode=updinfo&pass=%s&mount=%s", self->password, self->mount);
-	if (!rv) {
-		sock_close(socket);
-		return SHOUTERR_SOCKET;
-	}
-
-	while (metadata) {
-		if (metadata->name) {
-			if (metadata->value) {
-				if (!(encvalue = util_url_encode(metadata->value))) {
-					rv = SHOUTERR_MALLOC;
-					break;
-				}
-				rv = sock_write(socket, "&%s=%s", metadata->name, encvalue);
-			} else
-				rv = sock_write(socket, "&%s", metadata->name);
-
-			free (encvalue);
-			
-			if (!rv) {
-				sock_close(socket);
-				return SHOUTERR_SOCKET;
-			}
-		}
-		rv = SHOUTERR_SUCCESS;
-		metadata = metadata->next;
-	}
-	if (rv != SHOUTERR_SUCCESS) {
-		sock_close(socket);
-		return rv;
-	}
-
-	if (!sock_write(socket, " HTTP/1.0\r\nUser-Agent: libshout/" VERSION "\r\n\r\n")) {
-		sock_close(socket);
-		return SHOUTERR_SOCKET;
-	}
-
-	sock_close(socket);
 
         return SHOUTERR_SUCCESS;
 }

<p><p>1.6       +1 -0      libshout/src/shout_private.h

Index: shout_private.h
===================================================================
RCS file: /usr/local/cvsroot/libshout/src/shout_private.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- shout_private.h	15 Jan 2003 07:31:29 -0000	1.5
+++ shout_private.h	15 Jan 2003 08:20:15 -0000	1.6
@@ -36,6 +36,7 @@
 #define LIBSHOUT_DEFAULT_FORMAT SHOUT_FORMAT_VORBIS
 #define LIBSHOUT_DEFAULT_PROTOCOL SHOUT_PROTOCOL_ICE
 #define LIBSHOUT_DEFAULT_USER "source"
+#define LIBSHOUT_DEFAULT_USERAGENT "libshout/" VERSION
 
 struct shout {
         /* hostname or IP of icecast server */

<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