chiark / gitweb /
ucgi/: Return useful status codes when things go wrong.
[userv-utils.git] / www-cgi / ucgicommon.c
index 73565b5f07e4d51d5e15bdec0e75d1a5e1bc6fe5..2fa6260af02d4373a6d430df489e7b113eccdfd7 100644 (file)
@@ -37,18 +37,20 @@ static void outerror(void) {
 }
 
 void syserror(const char *m) {
 }
 
 void syserror(const char *m) {
-  if (printf("Content-Type: text/plain\n\n"
+  if (printf("Content-Type: text/plain\n"
+            "Status: 500\n\n"
             "ucgi: system call error:\n"
             "%s: %s\n",
             m,strerror(errno))==EOF || fflush(stdout)) outerror();
   exit(0);
 }
 
             "ucgi: system call error:\n"
             "%s: %s\n",
             m,strerror(errno))==EOF || fflush(stdout)) outerror();
   exit(0);
 }
 
-void error(const char *m) {
-  if (printf("Content-Type: text/plain\n\n"
+void error(const char *m, int st) {
+  if (printf("Content-Type: text/plain\n"
+            "Status: %d\n\n"
             "ucgi: error:\n"
             "%s\n",
             "ucgi: error:\n"
             "%s\n",
-            m)==EOF || fflush(stdout)) outerror();
+            st, m)==EOF || fflush(stdout)) outerror();
   exit(0);
 }
 
   exit(0);
 }
 
@@ -104,7 +106,7 @@ opened:
     l= strlen(buf);
     if (buf[l - 1] == '\n') buf[--l]= 0;
     if (l + 1 == sizeof(buf))
     l= strlen(buf);
     if (buf[l - 1] == '\n') buf[--l]= 0;
     if (l + 1 == sizeof(buf))
-      error("line too long in environment filter file");
+      error("line too long in environment filter file", 500);
     p= buf; q= p + l;
     while (isspace((unsigned char)*p)) p++;
     while (q > p && isspace((unsigned char)q[-1])) q--;
     p= buf; q= p + l;
     while (isspace((unsigned char)*p)) p++;
     while (q > p && isspace((unsigned char)q[-1])) q--;
@@ -146,7 +148,7 @@ static int envvar_match(unsigned flags, const char *en,
        rc= envvar_match(flags, en, defaults, 0, ev);
        if (rc) return rc;
       } else
        rc= envvar_match(flags, en, defaults, 0, ev);
        if (rc) return rc;
       } else
-       error("unknown pattern directive");
+       error("unknown pattern directive", 500);
       continue;
     }
 
       continue;
     }
 
@@ -208,7 +210,7 @@ void filter_environment(unsigned flags, const char *prefix_in,
     if (envvar_match(flags, en + pn, patv, defaults, &ev) > 0) {
       n= strcspn(en, "=");
       if (n >= sizeof(enbuf))
     if (envvar_match(flags, en + pn, patv, defaults, &ev) > 0) {
       n= strcspn(en, "=");
       if (n >= sizeof(enbuf))
-       error("environment variable name too long");
+       error("environment variable name too long", 500);
       memcpy(enbuf, en, n);
       enbuf[n]= 0;
       D( if (debugmode)
       memcpy(enbuf, en, n);
       enbuf[n]= 0;
       D( if (debugmode)