r8318: added a bunch more ejs calls.
[samba.git] / source4 / scripting / ejs / smbcalls_string.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    provide access to string functions
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "scripting/ejs/smbcalls.h"
25 #include "lib/ejs/ejs.h"
26 #include "system/passwd.h"
27
28 /*
29   usage:
30       var s = strlower("UPPER");
31 */
32 static int ejs_strlower(MprVarHandle eid, int argc, char **argv)
33 {
34         char *s;
35         if (argc != 1) {
36                 ejsSetErrorMsg(eid, "strlower invalid arguments");
37                 return -1;
38         }
39         s = strlower_talloc(mprMemCtx(), argv[0]);
40         mpr_Return(eid, mprString(s));
41         talloc_free(s);
42         return 0;
43 }
44
45 /*
46   usage:
47       var s = strupper("lower");
48 */
49 static int ejs_strupper(MprVarHandle eid, int argc, char **argv)
50 {
51         char *s;
52         if (argc != 1) {
53                 ejsSetErrorMsg(eid, "strupper invalid arguments");
54                 return -1;
55         }
56         s = strupper_talloc(mprMemCtx(), argv[0]);
57         mpr_Return(eid, mprString(s));
58         talloc_free(s);
59         return 0;
60 }
61
62
63 /*
64   setup C functions that be called from ejs
65 */
66 void smb_setup_ejs_string(void)
67 {
68         ejsDefineStringCFunction(-1, "strlower", ejs_strlower, NULL, MPR_VAR_SCRIPT_HANDLE);
69         ejsDefineStringCFunction(-1, "strupper", ejs_strupper, NULL, MPR_VAR_SCRIPT_HANDLE);
70 }