My cgi-flac.c patches

Linux and UNIX specific discussions
Post Reply
mojjsan
Posts: 6
Joined: Wed Nov 21, 2007 7:36 pm

My cgi-flac.c patches

Post by mojjsan » Sat Dec 01, 2007 6:16 pm

Since I'm running Twonkyvision on an NAS with Linux but ripping cd:s from a windows-unit some filenames are created with &-char:s in them. And I'm to lazy to remove them manually I've altered cgi-flac some so it can handle it:

Code: Select all

--- upnp_util_convert.c.old     2007-11-28 21:08:00.000000000 +0000
+++ upnp_util_convert.c 2007-12-01 18:10:38.000000000 +0000
@@ -99,20 +99,28 @@
 char *get_cgi_param(char *query_string, char *param) {
     char *p = query_string;
     char *q = p;
+    int nisse=0;
     while (p) {
        if (*p == '\0' || *p == '?' || *p == '&') {
            char c = *p;
            *p = '\0';
            if (!strncmp(q, param, strlen(param)) && *(q + strlen(param)) == '=') {
-               char *ret = strdup(q + strlen(param) + 1);
-               *p = c;
-               return ret;
+               if(!strcmp(param,"source") && *(q+strlen(q)-5) != '.')
+                 nisse=1;
+                else{
+                  char *ret = strdup(q + strlen(param) + 1);
+                  *p = c;
+                  return ret;
+                }
            }
            *p = c;
-           if (*p)
-               q = p + 1;
-           else
-               return NULL;
+           if(!nisse){
+             if (*p)
+                 q = p + 1;
+              else
+                 return NULL;
+            nisse=0;
+            }
        }
        p++;
     }
Also so I wouldn't need to have a flac binary in twonky/cgi-bin I changed:

Code: Select all

--- cgi-flac.c.old      2007-12-01 18:16:33.000000000 +0000
+++ cgi-flac.c  2007-12-01 18:17:23.000000000 +0000
@@ -205,11 +205,11 @@
                        perror("fork");
                        break;
            case 0:
-                       execl (strPath, strPath, "--silent", "--decode", source, "-o", outfile, NULL);
-                       perror("execl");
+                       execlp ("flac", "flac", "--silent", "--decode", source, "-o", outfile, NULL);
+                       perror("execlp");
                        _exit(0); // should never been reached
            default:
-                       sleep(2000);
+                       sleep(2);
                        cat_file(outfile,1/*TRUE*/);
                        waitpid(pid,NULL,0);
                        free(outfile);
Be aware that I'm no software engineer but I like when things work my way.

Post Reply