[xiph-cvs] cvs commit: icecast/src source.c util.c yp.c

Ed oddsock at xiph.org
Thu Apr 10 20:00:24 PDT 2003



oddsock     03/04/10 23:00:24

  Modified:    src      source.c util.c yp.c
  Log:
  - fixed alot of yp logic.  timeouts now work properly so the tolerance of
    the unavailability of yp servers is much much better now.
  
  - new icecast config option <yp-url-timeout> to specify the timeout
  
  - url encoding is now fixed so that the yp data is formatted much nicer (and is correct :))
  
  - added url encoding for some fields that were not url-encoded
  
  - modified util_dict_urlencode() to not url-encode the key (still does the value)
  
  - new curl option (CURLOPT_NOSIGNAL) which prevents curl from using signals when
    timeouts are hit.  This new option needs curl 7.10 at least.

Revision  Changes    Path
1.50      +82 -66    icecast/src/source.c

Index: source.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/source.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- source.c	31 Mar 2003 12:54:44 -0000	1.49
+++ source.c	11 Apr 2003 03:00:24 -0000	1.50
@@ -298,13 +298,9 @@
         }
     }
     for (i=0;i<source->num_yp_directories;i++) {
-        if (source->ypdata[i]->server_type) {
-            free(source->ypdata[i]->server_type);
-        }
-        source->ypdata[i]->server_type = malloc(
-                strlen(source->format->format_description) + 1);
-        strcpy(source->ypdata[i]->server_type, 
-                source->format->format_description);
+        _add_yp_info(source, "server_type", 
+                     source->format->format_description,
+                     YP_SERVER_TYPE);
     }
 
     for (i=0;i<source->num_yp_directories;i++) {
@@ -352,35 +348,26 @@
                 if (current_time > (source->ypdata[i]->yp_last_touch + 
                             source->ypdata[i]->yp_touch_interval)) {
                     current_song[0] = 0;
-                    if (stats_get_value(source->mount, "artist")) {
-                        strncat(current_song, 
-                                stats_get_value(source->mount, "artist"), 
+                    if ((s = stats_get_value(source->mount, "artist"))) {
+                        strncat(current_song, s, 
                                 sizeof(current_song) - 1);
-                        if (strlen(current_song) + 4 < sizeof(current_song)) {
+                        if (strlen(current_song) + 4 < 
+                                sizeof(current_song)) 
+                        {
                             strncat(current_song, " - ", 3);
                         }
                     }
-                    if (stats_get_value(source->mount, "title")) {
-                        if (strlen(current_song) + 
-                                strlen(stats_get_value(source->mount, "title"))
+                    if (s = stats_get_value(source->mount, "title")) {
+                        if (strlen(current_song) + strlen(s)
                                 < sizeof(current_song) -1) 
                         {
                             strncat(current_song, 
-                                    stats_get_value(source->mount, "title"), 
+                                    s, 
                                     sizeof(current_song) - 1 - 
                                     strlen(current_song));
                         }
                     }
-                    
-                    if (source->ypdata[i]->current_song) {
-                        free(source->ypdata[i]->current_song);
-                        source->ypdata[i]->current_song = NULL;
-                    }
-    
-                    source->ypdata[i]->current_song = 
-                        malloc(strlen(current_song) + 1);
-                    strcpy(source->ypdata[i]->current_song, current_song);
-    
+                    _add_yp_info(source, "current_song", current_song, YP_CURRENT_SONG);
                     thread_create("YP Touch Thread", yp_touch_thread, 
                             (void *)source, THREAD_DETACHED); 
                 }
@@ -743,6 +730,7 @@
 static void _add_yp_info(source_t *source, char *stat_name, 
             void *info, int type)
 {
+    char *escaped;
     int i;
     if (!info) {
         return;
@@ -750,49 +738,69 @@
     for (i=0;i<source->num_yp_directories;i++) {
         switch (type) {
         case YP_SERVER_NAME:
-        if (source->ypdata[i]->server_name) {
-                free(source->ypdata[i]->server_name);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->server_name) {
+                        free(source->ypdata[i]->server_name);
+                    }
+                    source->ypdata[i]->server_name = 
+                         malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->server_name, (char *)escaped);
+                    stats_event(source->mount, stat_name, (char *)info);
+                    free(escaped);
                 }
-                source->ypdata[i]->server_name = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->server_name, (char *)info);
-                stats_event(source->mount, stat_name, (char *)info);
                 break;
         case YP_SERVER_DESC:
-                if (source->ypdata[i]->server_desc) {
-                    free(source->ypdata[i]->server_desc);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->server_desc) {
+                        free(source->ypdata[i]->server_desc);
+                    }
+                    source->ypdata[i]->server_desc = 
+                        malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->server_desc, (char *)escaped);
+                    stats_event(source->mount, stat_name, (char *)info);
+                    free(escaped);
                 }
-                source->ypdata[i]->server_desc = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->server_desc, (char *)info);
-                stats_event(source->mount, stat_name, (char *)info);
                 break;
         case YP_SERVER_GENRE:
-                if (source->ypdata[i]->server_genre) {
-                    free(source->ypdata[i]->server_genre);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->server_genre) {
+                        free(source->ypdata[i]->server_genre);
+                    }
+                    source->ypdata[i]->server_genre = 
+                        malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->server_genre, (char *)escaped);
+                    stats_event(source->mount, stat_name, (char *)info);
+                    free(escaped);
                 }
-                source->ypdata[i]->server_genre = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->server_genre, (char *)info);
-                stats_event(source->mount, stat_name, (char *)info);
                 break;
         case YP_SERVER_URL:
-                if (source->ypdata[i]->server_url) {
-                    free(source->ypdata[i]->server_url);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->server_url) {
+                        free(source->ypdata[i]->server_url);
+                    }
+                    source->ypdata[i]->server_url = 
+                        malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->server_url, (char *)escaped);
+                    stats_event(source->mount, stat_name, (char *)info);
+                    free(escaped);
                 }
-                source->ypdata[i]->server_url = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->server_url, (char *)info);
-                stats_event(source->mount, stat_name, (char *)info);
                 break;
         case YP_BITRATE:
-                if (source->ypdata[i]->bitrate) {
-                    free(source->ypdata[i]->bitrate);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->bitrate) {
+                        free(source->ypdata[i]->bitrate);
+                    }
+                    source->ypdata[i]->bitrate = 
+                        malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->bitrate, (char *)escaped);
+                    stats_event(source->mount, stat_name, (char *)info);
+                    free(escaped);
                 }
-                source->ypdata[i]->bitrate = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->bitrate, (char *)info);
-                stats_event(source->mount, stat_name, (char *)info);
                 break;
         case YP_AUDIO_INFO:
                 if (source->ypdata[i]->audio_info) {
@@ -803,21 +811,29 @@
                 strcpy(source->ypdata[i]->audio_info, (char *)info);
                 break;
         case YP_SERVER_TYPE:
-                if (source->ypdata[i]->server_type) {
-                    free(source->ypdata[i]->server_type);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->server_type) {
+                        free(source->ypdata[i]->server_type);
+                    }
+                    source->ypdata[i]->server_type = 
+                        malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->server_type, (char *)escaped);
+                    free(escaped);
                 }
-                source->ypdata[i]->server_type = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->server_type, (char *)info);
                 break;
         case YP_CURRENT_SONG:
-                if (source->ypdata[i]->current_song) {
-                    free(source->ypdata[i]->current_song);
+                escaped = util_url_escape(info);
+                if (escaped) {
+                    if (source->ypdata[i]->current_song) {
+                        free(source->ypdata[i]->current_song);
+                    }
+                    source->ypdata[i]->current_song = 
+                        malloc(strlen((char *)escaped) +1);
+                    strcpy(source->ypdata[i]->current_song, (char *)escaped);
+                    stats_event(source->mount, stat_name, (char *)info);
+                    free(escaped);
                 }
-                source->ypdata[i]->current_song = 
-                    malloc(strlen((char *)info) +1);
-                strcpy(source->ypdata[i]->current_song, (char *)info);
-                stats_event(source->mount, stat_name, (char *)info);
                 break;
         case YP_URL_TIMEOUT:
                 source->ypdata[i]->yp_url_timeout = (int)info;

<p><p>1.23      +6 -15     icecast/src/util.c

Index: util.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/util.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- util.c	10 Apr 2003 14:28:02 -0000	1.22
+++ util.c	11 Apr 2003 03:00:24 -0000	1.23
@@ -519,8 +519,8 @@
     return 1;
 }
 
-/* given a dictionary, URL-encode each key and val and 
-   stringify them in order as key=val&key=val... if val 
+/* given a dictionary, URL-encode each val and 
+   stringify it in order as key=val&key=val... if val 
    is set, or just key&key if val is NULL.
   TODO: Memory management needs overhaul. */
 char *util_dict_urlencode(util_dict *dict, char delim)
@@ -533,28 +533,19 @@
         /* encode key */
         if (!dict->key)
             continue;
-        if (!(enc = util_url_escape(dict->key))) {
-            if (res)
-                free(res);
-            return NULL;
-        }
         if (start) {
-            if (!(res = malloc(strlen(enc) + 1))) {
-                free(enc);
+            if (!(res = malloc(strlen(dict->key) + 1))) {
                 return NULL;
             }
-            sprintf(res, "%s", enc);
-            free(enc);
+            sprintf(res, "%s", dict->key);
             start = 0;
         } else {
-            if (!(tmp = realloc(res, strlen(res) + strlen(enc) + 2))) {
-                free(enc);
+            if (!(tmp = realloc(res, strlen(res) + strlen(dict->key) + 2))) {
                 free(res);
                 return NULL;
             } else
                 res = tmp;
-            sprintf(res + strlen(res), "%c%s", delim, enc);
-            free(enc);
+            sprintf(res + strlen(res), "%c%s", delim, dict->key);
         }
 
         /* encode value */

<p><p>1.8       +9 -4      icecast/src/yp.c

Index: yp.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/yp.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- yp.c	27 Mar 2003 17:10:11 -0000	1.7
+++ yp.c	11 Apr 2003 03:00:24 -0000	1.8
@@ -19,16 +19,21 @@
 static int yp_submit_url(int curl_con, char *yp_url, char *url, char *type, int i)
 {
     int ret = 0;
-    int *timeout;
+    int timeout;
     ice_config_t *config = config_get_config();
 
-    timeout = config->yp_url_timeout + i;
+    timeout = config->yp_url_timeout[i];
     config_release_config();
-
+    /* If not specified, use a reasonable timeout
+    of 30 seconds */
+    if (timeout == 0) {
+        timeout = 30;
+    }
     curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_URL, yp_url);
     curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_POSTFIELDS, url);
     curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_TIMEOUT, timeout);
-
+    /* This is to force libcurl to not use signals for timeouts */
+    curl_easy_setopt(curl_get_handle(curl_con), CURLOPT_NOSIGNAL, 1);
     /* get it! */
     memset(curl_get_result(curl_con), 0, sizeof(struct curl_memory_struct));
     memset(curl_get_header_result(curl_con), 0, 

<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