src/server/safs/cgi.c

changeset 415
d938228c382e
parent 359
79b28ae7bfbd
child 430
83560f32e7d5
--- a/src/server/safs/cgi.c	Wed Nov 02 19:19:01 2022 +0100
+++ b/src/server/safs/cgi.c	Sun Nov 06 15:53:32 2022 +0100
@@ -36,7 +36,7 @@
 #include <signal.h>
 #include <sys/wait.h>
 
-#include <ucx/string.h>
+#include <cx/string.h>
 
 #include "../util/util.h"
 #include "../util/pblock.h"
@@ -216,13 +216,13 @@
         // child
         
         // get script directory and script name
-        sstr_t script = sstr(path);
-        sstr_t parent;    
+        cxstring script = cx_str(path);
+        cxmutstr parent;    
         int len = strlen(path);
         for(int i=len-1;i>=0;i--) {
             if(path[i] == '/') {
-                script = sstrn(path + i + 1, len - i);
-                parent = sstrdup(sstrn(path, i));
+                script = cx_strn(path + i + 1, len - i);
+                parent = cx_strdup(cx_strn(path, i));
                 if(chdir(parent.ptr)) {
                     perror("cgi_start: chdir");
                     free(parent.ptr);
@@ -281,15 +281,15 @@
     CGIResponseParser* parser = pool_malloc(sn->pool, sizeof(CGIResponseParser));
     parser->sn = sn;
     parser->rq = rq;
-    parser->tmp = ucx_buffer_new(NULL, 64, UCX_BUFFER_AUTOEXTEND);
     parser->status = 0;
     parser->msg = NULL;
+    cxBufferInit(&parser->tmp, NULL, 64, pool_allocator(sn->pool), CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS);
     return parser;
 }
 
 void cgi_parser_free(CGIResponseParser *parser) {
-    if(parser->tmp) {
-        ucx_buffer_free(parser->tmp);
+    if(parser->tmp.space) {
+        cxBufferDestroy(&parser->tmp);
     }
     pool_free(parser->sn->pool, parser);
 }
@@ -302,9 +302,9 @@
  *        -1: error
  */
 static int parse_lines(CGIResponseParser *parser, char *buf, size_t len, int *pos) {
-    UcxAllocator a = util_pool_allocator(parser->sn->pool);
-    sstr_t name;
-    sstr_t value;
+    CxAllocator *a = pool_allocator(parser->sn->pool);
+    cxmutstr name;
+    cxmutstr value;
     WSBool space = TRUE;
     int i;
     
@@ -313,7 +313,7 @@
     for(i=0;i<len;i++) {
         char c = buf[i];
         if(value_begin == line_begin && c == ':') {
-            name = sstrn(buf + line_begin, i - line_begin);
+            name = cx_mutstrn(buf + line_begin, i - line_begin);
             value_begin = i + 1;
         } else if(c == '\n') {
             if(value_begin == line_begin) {
@@ -325,17 +325,18 @@
                     return -1;
                 }
             }
-            value = sstrn(buf + value_begin, i - value_begin);
+            value = cx_mutstrn(buf + value_begin, i - value_begin);
             
-            name = sstrlower_a(&a, sstrtrim(name));
-            value = sstrtrim(value);
+            cx_strlower(name);
+            name = cx_strdup_a(a, cx_strtrim((cxstring){name.ptr, name.length}));
+            value = cx_strtrim_m(value);
             
             if(name.length == 0 || value.length == 0) {
                 return -1;
             }
             
-            if(!sstrcmp(name, S("status"))) {
-                sstr_t codestr = value;
+            if(!cx_strcmp((cxstring){name.ptr, name.length}, (cxstring)CX_STR("status"))) {
+                cxmutstr codestr = value;
                 int j;
                 for(j=0;j<codestr.length;j++) {
                     if(!isdigit(codestr.ptr[j])) {
@@ -351,10 +352,10 @@
                 util_strtoint(codestr.ptr, &s);
                 parser->status = (int)s;
                 
-                sstr_t msg = sstrtrim(sstrsubs(value, j + 1));
+                cxmutstr msg = cx_strtrim_m(cx_strsubs_m(value, j + 1));
                 
                 if(msg.length > 0) {
-                    parser->msg = sstrdup_pool(parser->sn->pool, msg).ptr;
+                    parser->msg = cx_strdup_pool(parser->sn->pool, msg).ptr;
                 }
             } else {
                 pblock_nvlinsert(
@@ -388,7 +389,7 @@
 int cgi_parse_response(CGIResponseParser *parser, char *buf, size_t len, size_t *bpos) {
     *bpos = 0;
     int pos = 0;
-    if(parser->tmp->pos > 0) {
+    if(parser->tmp.pos > 0) {
         // the tmp buffer contains an unfinished line
         // fill up the buffer until the line is complete
         WSBool nb = FALSE;
@@ -398,12 +399,12 @@
                 break;
             }
         }
-        ucx_buffer_write(buf, 1, pos, parser->tmp);
+        cxBufferWrite(buf, 1, pos, &parser->tmp);
         
         if(nb) {
             // line complete
             int npos;
-            int r = parse_lines(parser, parser->tmp->space, parser->tmp->pos, &npos);
+            int r = parse_lines(parser, parser->tmp.space, parser->tmp.pos, &npos);
             switch(r) {
                 case -1: return -1;
                 case 0: return -1;
@@ -414,9 +415,9 @@
                 }
             }
             // reset tmp buffer
-            parser->tmp->pos = 0;
+            parser->tmp.pos = 0;
         } else {
-            if(parser->tmp->pos > CGI_RESPONSE_MAX_LINE_LENGTH) {
+            if(parser->tmp.pos > CGI_RESPONSE_MAX_LINE_LENGTH) {
                 return -1;
             }
         }
@@ -430,7 +431,7 @@
         case 1: {
             int newlen = len - npos;
             if(npos > 0) {
-                ucx_buffer_write(buf + npos, 1, newlen, parser->tmp);
+                cxBufferWrite(buf + npos, 1, newlen, &parser->tmp);
             }
             return 0;
         }

mercurial