0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <sys/param.h>
0039
0040 #include <ndrstandard.h>
0041 #include <ndebug.h>
0042
0043 #include <ndrx.h>
0044 #include <ndrxdcmn.h>
0045 #include <atmi_int.h>
0046 #include <gencall.h>
0047 #include <errno.h>
0048
0049 #include "nclopt.h"
0050
0051 #ifndef NDRX_DISABLEPSCRIPT
0052 #include <pscript.h>
0053 #include <psstdblob.h>
0054 #include <psstdio.h>
0055 #include <psstdsystem.h>
0056 #include <psstdmath.h>
0057 #include <psstdstring.h>
0058 #include <psstdexutil.h>
0059 #include <psstdaux.h>
0060 #endif
0061
0062
0063 #ifndef NDRX_DISABLEPSCRIPT
0064
0065
0066
0067 extern const char ndrx_G_resource_provision[];
0068 extern const size_t ndrx_G_resource_provision_len;
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 expublic int cmd_provision(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0084 {
0085 int ret=EXSUCCEED;
0086 const PSChar *s;
0087 HPSCRIPTVM v;
0088 PSInteger res;
0089 int i;
0090 const PSChar *err;
0091 PSMemReader reader;
0092
0093 v = ps_open(1024);
0094
0095 ps_setprintfunc(v,printfunc,errorfunc);
0096
0097 ps_pushroottable(v);
0098
0099
0100 psstd_register_bloblib(v);
0101 psstd_register_iolib(v);
0102 psstd_register_systemlib(v);
0103 psstd_register_mathlib(v);
0104 psstd_register_stringlib(v);
0105 psstd_register_exutillib(v);
0106
0107 register_getExfields(v);
0108
0109
0110 psstd_seterrorhandlers(v);
0111
0112
0113
0114 ps_pushstring(v, "args", -1);
0115 ps_newtable(v);
0116
0117 if (EXSUCCEED!=add_defaults_from_config(v, "provision"))
0118 {
0119 EXFAIL_OUT(ret);
0120 }
0121
0122 if (argc>=2)
0123 {
0124 for (i=1; i<argc; i++)
0125 {
0126
0127 if (0==strcmp(argv[i], "-d"))
0128 {
0129 PSBool isDefaulted = EXTRUE;
0130 ps_pushstring(v, "isDefaulted", -1);
0131 ps_pushbool(v, isDefaulted);
0132 ps_newslot(v, -3, PSFalse );
0133 }
0134 else if (0==strncmp(argv[i], "-v", 2)
0135 && 0!=strcmp(argv[i], "-v") )
0136 {
0137
0138
0139
0140 if (EXSUCCEED!=load_value(v, argv[i]+2))
0141 {
0142 fprintf(stderr, "Invalid value\n");
0143 EXFAIL_OUT(ret);
0144 }
0145 }
0146 else if (0==strncmp(argv[i], "-v", 2))
0147 {
0148
0149 if (i+1<argc)
0150 {
0151 i++;
0152 if (EXSUCCEED!=load_value(v, argv[i]))
0153 {
0154 fprintf(stderr, "Invalid value\n");
0155 EXFAIL_OUT(ret);
0156 }
0157 }
0158 else
0159 {
0160 fprintf(stderr, "Invalid command line missing value at end.\n");
0161 EXFAIL_OUT(ret);
0162 }
0163 }
0164
0165 }
0166 }
0167
0168
0169
0170 ps_newslot(v, -3, PSFalse );
0171 memset(&reader, 0, sizeof(reader));
0172 reader.memptr = (char *)ndrx_G_resource_provision;
0173 reader.size = ndrx_G_resource_provision_len;
0174
0175
0176 if (PS_FAILED(psstd_loadmem(v, &reader)))
0177 {
0178 fprintf(stderr, "Failed to load byte\n");
0179
0180 if(PS_SUCCEEDED(ps_getstring(v,-1,&err)))
0181 {
0182 fprintf(stderr, _SC("Error [%s]\n"),err);
0183 return EXFAIL;
0184 }
0185 }
0186 else
0187 {
0188 ps_pushroottable(v);
0189 }
0190
0191
0192 if (PS_FAILED(ps_call(v,1,PSTrue, PSTrue)))
0193 {
0194 fprintf(stderr, "Failed to load script\n");
0195 ps_getlasterror(v);
0196 if(PS_SUCCEEDED(ps_getstring(v,-1,&err)))
0197 {
0198 printf(_SC("Error [%s]\n"),err);
0199 EXFAIL_OUT(ret);
0200 }
0201 }
0202
0203
0204 ps_getinteger(v,-1,&res);
0205
0206 if (res>=0)
0207 {
0208 ret = EXSUCCEED;
0209 }
0210 else
0211 {
0212 ret = EXFAIL;
0213 }
0214
0215 ps_pop(v,3);
0216
0217 ps_close(v);
0218
0219 out:
0220 return ret;
0221 }
0222
0223 #else
0224
0225
0226
0227
0228
0229
0230
0231 expublic int cmd_provision(cmd_mapping_t *p_cmd_map, int argc, char **argv, int *p_have_next)
0232 {
0233 fprintf(stderr, "Pscript not compiled for this platform!\n");
0234 return EXFAIL;
0235 }
0236
0237 #endif
0238