svn commit: samba r7019 - in branches/SAMBA_4_0: source/web_server swat/esptest

tridge at samba.org tridge at samba.org
Fri May 27 13:16:26 GMT 2005


Author: tridge
Date: 2005-05-27 13:16:26 +0000 (Fri, 27 May 2005)
New Revision: 7019

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=7019

Log:
- added esp call lpServices() which returns a list of services in smb.conf. 

- added a test of lpServices() in the esptest scripts

Modified:
   branches/SAMBA_4_0/source/web_server/calls.c
   branches/SAMBA_4_0/swat/esptest/loadparm.esp


Changeset:
Modified: branches/SAMBA_4_0/source/web_server/calls.c
===================================================================
--- branches/SAMBA_4_0/source/web_server/calls.c	2005-05-27 12:36:16 UTC (rev 7018)
+++ branches/SAMBA_4_0/source/web_server/calls.c	2005-05-27 13:16:26 UTC (rev 7019)
@@ -62,8 +62,45 @@
 	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
   
   can be called in 4 ways:
@@ -146,25 +183,13 @@
 				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 @@
 void http_setup_ejs_functions(void)
 {
 	espDefineStringCFunction(NULL, "lpGet", esp_lpGet, NULL);
+	espDefineStringCFunction(NULL, "lpServices", esp_lpServices, NULL);
 	espDefineCFunction(NULL, "typeof", esp_typeof, NULL);
 }

Modified: branches/SAMBA_4_0/swat/esptest/loadparm.esp
===================================================================
--- branches/SAMBA_4_0/swat/esptest/loadparm.esp	2005-05-27 12:36:16 UTC (rev 7018)
+++ branches/SAMBA_4_0/swat/esptest/loadparm.esp	2005-05-27 13:16:26 UTC (rev 7019)
@@ -57,6 +57,9 @@
 Here are some commonly used parameters:<p>
 
 <%
+
+showValue("defined services", lpServices());
+
 function showParameter(name) {
 	showValue(name, lpGet(name));
 }



More information about the samba-cvs mailing list