version 0.2.1
[fms.git] / libs / shttpd / io_emb.c
index 42cd5c5..762afe5 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "defs.h"
 
-#if defined(EMBEDDED)
 const char *
 shttpd_version(void)
 {
@@ -29,6 +28,12 @@ call_user(struct conn *c, struct shttpd_arg *arg, shttpd_callback_t func)
        arg->in.len             = io_data_len(&c->rem.io);
        arg->in.num_bytes       = 0;
 
+       if (io_data_len(&c->rem.io) >= c->rem.io.size)
+               arg->flags |= SHTTPD_POST_BUFFER_FULL;
+
+       if (c->rem.content_len > 0 && c->rem.io.total < c->rem.content_len)
+               arg->flags |= SHTTPD_MORE_POST_DATA;
+
        func(arg);
 
        io_inc_head(&c->loc.io, arg->out.num_bytes);
@@ -177,32 +182,6 @@ shttpd_register_uri(struct shttpd_ctx *ctx,
        }
 }
 
-#if 0
-struct shttpd_ctx *
-shttpd_init2(const char *config_file, char *names[], char *values[], size_t n)
-{
-       size_t i;
-
-       for (i = 0; i < n; i++)
-               set_option(names[i], values[i]);
-
-       return (init_ctx(config_file, 0, NULL));
-}
-#endif
-
-void
-shttpd_protect_uri(struct shttpd_ctx *ctx, const char *uri, const char *file)
-{
-       struct uri_auth *auth;
-
-       if ((auth = malloc(sizeof(*auth))) != NULL) {
-               auth->uri       = my_strdup(uri);
-               auth->file_name = my_strdup(file);
-               auth->uri_len   = strlen(uri);
-               LL_ADD(&ctx->uri_auths, &auth->link);
-       }
-}
-
 int
 shttpd_get_var(const char *var, const char *buf, int buf_len,
                char *value, int value_len)
@@ -211,27 +190,24 @@ shttpd_get_var(const char *var, const char *buf, int buf_len,
        size_t          var_len;
 
        var_len = strlen(var);
-       e = buf + buf_len - var_len;
+       e = buf + buf_len;              /* End of QUERY_STRING buffer   */
 
        /* buf is "var1=val1&var2=val2...". Find variable first */
-       for (p = buf; p < e; p++)
-               if (!my_strncasecmp(var, p, var_len) && p[var_len] == '=') {
+       for (p = buf; p + var_len < e; p++)
+               if ((p == buf || p[-1] == '&') &&
+                   p[var_len] == '=' &&
+                   !my_strncasecmp(var, p, var_len)) {
 
-                       /* Found. Shift to variable value */
-                       e = buf + buf_len;
-                       p += var_len + 1;
-
-                       /* Find where the value ends */
+                       /* Point 'p' to var value, 's' to the end of value */
+                       p += var_len + 1;       
                        if ((s = memchr(p, '&', e - p)) == NULL)
                                s = e;
 
-                       /* Copy value into the buffer, decoding it */
-                       url_decode(p, s - p, value, value_len);
-
-                       return (1);
+                       /* URL-decode value. Return result length */
+                       return (url_decode(p, s - p, value, value_len));
                }
 
-       return (0);
+       return (-1);
 }
 
 static int
@@ -297,5 +273,3 @@ const struct io_class       io_embedded =  {
        (int (*)(struct stream *, const void *, size_t)) do_embedded,
        close_embedded
 };
-
-#endif /* EMBEDDED */