r7019: - added esp call lpServices() which returns a list of services in smb.conf.
authorAndrew Tridgell <tridge@samba.org>
Fri, 27 May 2005 13:16:26 +0000 (13:16 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:17:07 +0000 (13:17 -0500)
- added a test of lpServices() in the esptest scripts

source/web_server/calls.c
swat/esptest/loadparm.esp

index 6f1649d131f184b8436d50a3321b5bdfaa82103a..859ae17433cc9c1b06d06819ed052514b07b4597 100644 (file)
@@ -62,6 +62,43 @@ static int esp_typeof(struct EspRequest *ep, int argc, struct MprVar **argv)
        return 0;
 }
 
+/*
+  setup a return of a string list
+*/
+static void esp_returnlist(struct EspRequest *ep, 
+                          const char *name, const char **list)
+{
+       struct MprVar var;
+       int i;
+
+       var = mprCreateObjVar(name, ESP_HASH_SIZE);
+       for (i=0;list[i];i++) {
+               char idx[16];
+               struct MprVar val;
+               mprItoa(i, idx, sizeof(idx));
+               val = mprCreateStringVar(list[i], 1);
+               mprCreateProperty(&var, idx, &val);
+       }
+       espSetReturn(ep, var);
+}
+
+/*
+  return a list of defined services
+*/
+static int esp_lpServices(struct EspRequest *ep, int argc, char **argv)
+{
+       int i;
+       const char **list;
+       if (argc != 0) return -1;
+       
+       for (i=0;i<lp_numservices();i++) {
+               list = str_list_add(list, lp_servicename(i));
+       }
+       talloc_steal(ep, list);
+       esp_returnlist(ep, "services", list);
+       return 0;
+}
+
 
 /*
   allow access to loadparm variables from inside esp scripts in swat
@@ -146,25 +183,13 @@ static int esp_lpGet(struct EspRequest *ep, int argc, char **argv)
                                return 0;
                        }
                }
-               return -1;
-       
-       case P_LIST: {
-               const char **list = *(const char ***)parm_ptr;
-               struct MprVar var;
-               var = mprCreateObjVar(parm->label, 10);
-               for (i=0;list[i];i++) {
-                       char idx[16];
-                       struct MprVar val;
-                       mprItoa(i, idx, sizeof(idx));
-                       val = mprCreateStringVar(list[i], 1);
-                       mprCreateProperty(&var, idx, &val);
-               }
-               espSetReturn(ep, var);
+               return -1;      
+       case P_LIST: 
+               esp_returnlist(ep, parm->label, *(const char ***)parm_ptr);
                break;
        case P_SEP:
                return -1;
        }
-       }
        return 0;
 }
 
@@ -174,5 +199,6 @@ static int esp_lpGet(struct EspRequest *ep, int argc, char **argv)
 void http_setup_ejs_functions(void)
 {
        espDefineStringCFunction(NULL, "lpGet", esp_lpGet, NULL);
+       espDefineStringCFunction(NULL, "lpServices", esp_lpServices, NULL);
        espDefineCFunction(NULL, "typeof", esp_typeof, NULL);
 }
index b5f3c86b1d9493e71297adccdd144e0cb4d464bd..b9f2c54ec5a83728ca8391b029be73071bcde659 100644 (file)
@@ -57,6 +57,9 @@ if (request['REQUEST_METHOD'] == "POST") {
 Here are some commonly used parameters:<p>
 
 <%
+
+showValue("defined services", lpServices());
+
 function showParameter(name) {
        showValue(name, lpGet(name));
 }