Changeset 676 for trunk/zoo-project/zoo-kernel/zoo_service_loader.c
- Timestamp:
- Jun 19, 2015, 3:58:00 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/zoo_service_loader.c
r673 r676 141 141 #endif 142 142 143 extern int getServiceFromFile (maps *, const char *, service **);144 145 /**146 * Parse the service file using getServiceFromFile or use getServiceFromYAML147 * if YAML support was activated.148 *149 * @param conf the conf maps containing the main.cfg settings150 * @param file the file name to parse151 * @param service the service to update witht the file content152 * @param name the service name153 * @return true if the file can be parsed or false154 * @see getServiceFromFile, getServiceFromYAML155 */156 int157 readServiceFile (maps * conf, char *file, service ** service, char *name)158 {159 int t = getServiceFromFile (conf, file, service);160 #ifdef YAML161 if (t < 0)162 {163 t = getServiceFromYAML (conf, file, service, name);164 }165 #endif166 return t;167 }168 143 169 144 /** … … 185 160 } 186 161 187 188 /**189 * Create the profile registry.190 *191 * The profile registry is optional (created only if the registry key is192 * available in the [main] section of the main.cfg file) and can be used to193 * store the profiles hierarchy. The registry is a directory which should194 * contain the following sub-directories:195 * * concept: direcotry containing .html files describing concept196 * * generic: directory containing .zcfg files for wps:GenericProcess197 * * implementation: directory containing .zcfg files for wps:Process198 *199 * @param m the conf maps containing the main.cfg settings200 * @param r the registry to update201 * @param reg_dir the resgitry202 * @param saved_stdout the saved stdout identifier203 * @return 0 if the resgitry is null or was correctly updated, -1 on failure204 */205 int206 createRegistry (maps* m,registry ** r, char *reg_dir, int saved_stdout)207 {208 char registryKeys[3][15]={209 "concept",210 "generic",211 "implementation"212 };213 int scount = 0,i=0;214 if (reg_dir == NULL)215 return 0;216 for(i=0;i<3;i++){217 char * tmpName =218 (char *) malloc ((strlen (reg_dir) + strlen (registryKeys[i]) + 2) *219 sizeof (char));220 sprintf (tmpName, "%s/%s", reg_dir, registryKeys[i]);221 222 DIR *dirp1 = opendir (tmpName);223 struct dirent *dp1;224 while ((dp1 = readdir (dirp1)) != NULL){225 char* extn = strstr(dp1->d_name, ".zcfg");226 if(dp1->d_name[0] != '.' && extn != NULL && strlen(extn) == 5)227 {228 int t;229 char *tmps1=230 (char *) malloc ((strlen (tmpName) + strlen (dp1->d_name) + 2) *231 sizeof (char));232 sprintf (tmps1, "%s/%s", tmpName, dp1->d_name);233 char *tmpsn = zStrdup (dp1->d_name);234 tmpsn[strlen (tmpsn) - 5] = 0;235 service* s1 = (service *) malloc (SERVICE_SIZE);236 if (s1 == NULL)237 {238 dup2 (saved_stdout, fileno (stdout));239 errorException (m, _("Unable to allocate memory."),240 "InternalError", NULL);241 return -1;242 }243 t = readServiceFile (m, tmps1, &s1, tmpsn);244 free (tmpsn);245 if (t < 0)246 {247 map *tmp00 = getMapFromMaps (m, "lenv", "message");248 char tmp01[1024];249 if (tmp00 != NULL)250 sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"),251 dp1->d_name, tmp00->value);252 else253 sprintf (tmp01, _("Unable to parse the ZCFG file: %s."),254 dp1->d_name);255 dup2 (saved_stdout, fileno (stdout));256 errorException (m, tmp01, "InternalError", NULL);257 return -1;258 }259 #ifdef DEBUG260 dumpService (s1);261 fflush (stdout);262 fflush (stderr);263 #endif264 if(strncasecmp(registryKeys[i],"implementation",14)==0){265 inheritance(*r,&s1);266 }267 addServiceToRegistry(r,registryKeys[i],s1);268 freeService (&s1);269 free (s1);270 scount++;271 }272 }273 (void) closedir (dirp1);274 }275 return 0;276 }277 278 162 /** 279 163 * Recursivelly parse zcfg starting from the ZOO-Kernel cwd. … … 288 172 * @param level the current level (number of sub-directories to reach the 289 173 * current path) 174 * @param func a pointer to a function having 4 parameters 175 * (registry*, maps*, xmlNodePtr and service*). 290 176 * @see inheritance, readServiceFile 291 177 */ 292 178 int 293 recursReaddirF ( maps * m, registry *r, xmlNodePtr n, char *conf_dir, char *prefix,294 int saved_stdout, int level, void (func) (maps *, xmlNodePtr, 295 service *))179 recursReaddirF ( maps * m, registry *r, xmlNodePtr n, char *conf_dir, 180 char *prefix, int saved_stdout, int level, 181 void (func) (registry *, maps *, xmlNodePtr, service *) ) 296 182 { 297 183 struct dirent *dp; … … 400 286 #endif 401 287 inheritance(r,&s1); 402 func ( m, n, s1);288 func (r, m, n, s1); 403 289 freeService (&s1); 404 290 free (s1); … … 1251 1137 int saved_stdout = dup (fileno (stdout)); 1252 1138 dup2 (fileno (stderr), fileno (stdout)); 1253 createRegistry (m,&zooRegistry,reg->value,saved_stdout); 1139 if(createRegistry (m,&zooRegistry,reg->value)<0){ 1140 map *message=getMapFromMaps(m,"lenv","message"); 1141 map *type=getMapFromMaps(m,"lenv","type"); 1142 dup2 (saved_stdout, fileno (stdout)); 1143 errorException (m, message->value, 1144 type->value, NULL); 1145 return 0; 1146 } 1254 1147 dup2 (saved_stdout, fileno (stdout)); 1148 close(saved_stdout); 1255 1149 } 1256 1150 … … 1433 1327 #endif 1434 1328 inheritance(zooRegistry,&s1); 1435 printDescribeProcessForProcess ( m, n, s1);1329 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1436 1330 freeService (&s1); 1437 1331 free (s1); … … 1511 1405 #endif 1512 1406 inheritance(zooRegistry,&s1); 1513 printDescribeProcessForProcess ( m, n, s1);1407 printDescribeProcessForProcess (zooRegistry,m, n, s1); 1514 1408 freeService (&s1); 1515 1409 free (s1); … … 2177 2071 fclose (stdin); 2178 2072 #endif 2179 2073 fprintf(stderr,"DEBUG START %s %d \n",__FILE__,__LINE__); 2180 2074 #ifdef RELY_ON_DB 2181 2075 init_sql(m);
Note: See TracChangeset
for help on using the changeset viewer.