[Initng-svn] r2385 - in initng: plugins/dparser plugins/find plugins/iparser src

svn at initng.thinktux.net svn at initng.thinktux.net
Mon Dec 12 12:15:13 CET 2005


Author: jimmy
Date: Mon Dec 12 12:15:12 2005
New Revision: 2385

Modified:
   initng/plugins/dparser/initng_d_parser.c
   initng/plugins/dparser/initng_d_parser.h
   initng/plugins/find/initng_find.c
   initng/plugins/find/initng_find.h
   initng/plugins/iparser/initng_i_parser.c
   initng/plugins/iparser/initng_i_parser.h
   initng/src/initng_common.c
   initng/src/initng_common.h
   initng/src/initng_env_variable.c
   initng/src/initng_plugin.h
   initng/src/initng_string_tools.c
   initng/src/initng_string_tools.h
Log:
Work on parsers.


Modified: initng/plugins/dparser/initng_d_parser.c
==============================================================================
--- initng/plugins/dparser/initng_d_parser.c	(original)
+++ initng/plugins/dparser/initng_d_parser.c	Mon Dec 12 12:15:12 2005
@@ -178,7 +178,7 @@
 }
 
 /* Load a service from a process_name or process_path */
-service_h *initng_d_parser(char *s_name)
+service_h *initng_d_parser(const char *s_name)
 {
     char filetoparse[200];
     service_h *serv = NULL;

Modified: initng/plugins/dparser/initng_d_parser.h
==============================================================================
--- initng/plugins/dparser/initng_d_parser.h	(original)
+++ initng/plugins/dparser/initng_d_parser.h	Mon Dec 12 12:15:12 2005
@@ -24,7 +24,7 @@
 #include "../../src/initng_service_cache.h"
 #include "../../src/initng_global.h"
 
-service_h *initng_d_parser(char *s_name);
+service_h *initng_d_parser(const char *s_name);
 int module_init(const char *version);
 void module_unload(void);
 

Modified: initng/plugins/find/initng_find.c
==============================================================================
--- initng/plugins/find/initng_find.c	(original)
+++ initng/plugins/find/initng_find.c	Mon Dec 12 12:15:12 2005
@@ -78,7 +78,7 @@
 }
 
 /* Load a service from a process_name or process_path */
-service_h *initng_find(char *service)
+service_h *initng_find(const char *service)
 {
     /* means that it may not be a direct service request, then we start looking in subfolders */
 
@@ -105,16 +105,17 @@
     if((tmp=search_dir(service, "daemon")))
 	return(tmp);
 
-    tmp_serv=get_find_alias(service);
-    if((!tmp_serv))
+    /* try get from alias file */
+    if(!(tmp_serv=get_find_alias(service)));
 	return(NULL);
-	
-    if((tmp=search_dir(tmp_serv, "system")))
-	return(tmp);
-	
-    if((tmp=search_dir(tmp_serv, "daemon")))
+
+    if ((tmp = parse_service(tmp_serv)))
+    {
+	free(tmp_serv);
 	return(tmp);
-	
+    }
+    
+    free(tmp_serv);
     return (NULL);
 }
 
@@ -126,8 +127,10 @@
 
     char *file_content = NULL;
     char *point = NULL;
+    char *point_result = NULL;
     char *ret = NULL;
 
+    printf("Finding alias for %s\n", from);
     /* open that file */
     if (!open_read_close(ALIAS_FILE, &file_content))
         return (NULL);
@@ -151,27 +154,35 @@
             continue;
         }
     
+	printf("parse row \"%s\"\n", point);
 	/* chek if first word is a match */
-	if(strncmp(point, from, from_len)!=0)
+	if(strncasecmp(point, from, from_len)!=0)
 	{
+	    printf("Not the one");
             JUMP_TO_NEXT_ROW(point);
             continue;
 	}
 	
-	/* check so there is an '=' after */
-        if (!point[from_len] || !point[from_len+1] || point[from_len+1] != '=')
+	printf("point[from_len]='%c', point[from_len+1]='%c'\n", point[from_len], point[from_len+1]);
+
+	
+        if (!point[from_len] || !point[from_len+1] || point[from_len] != '=')
         {
             JUMP_TO_NEXT_ROW(point);
             continue;
         }
 	
-	while(point[from_len+2+i] && point[from_len+2+i]!='\n')
+	/* Put pointer to result after the '=' */
+	point_result=&point[from_len+1];
+
+	while(point_result[i] && point_result[i]!='\n')
 	    i++;
 	
 	/* copy the rest of line */
-	ret=i_strndup(&point[from_len+2], i);
+	ret=i_strndup(point_result, i);
 	
 	free(file_content);
+	printf("ret=\"%s\", len=%i\n", ret, i);
 	return(ret);
     }
     free(file_content);

Modified: initng/plugins/find/initng_find.h
==============================================================================
--- initng/plugins/find/initng_find.h	(original)
+++ initng/plugins/find/initng_find.h	Mon Dec 12 12:15:12 2005
@@ -18,6 +18,6 @@
  * Boston, MA 02111-1307, USA.
  */
 
-service_h *initng_find(char *service);
+service_h *initng_find(const char *service);
 int module_init(const char *version);
 void module_unload(void);

Modified: initng/plugins/iparser/initng_i_parser.c
==============================================================================
--- initng/plugins/iparser/initng_i_parser.c	(original)
+++ initng/plugins/iparser/initng_i_parser.c	Mon Dec 12 12:15:12 2005
@@ -52,8 +52,8 @@
 static void err_print_line2t(char *point, const char *message, e_mt err,
                              const char *file, const char *func,
                              int codeline);
-static service_h *parse_file(char *filename, char *watch_for);
-static int parse_service_line(char **to_parse, char *watch_for,
+static service_h *parse_file(char *filename, const char *watch_for);
+static int parse_service_line(char **to_parse, const char *watch_for,
                               service_h * father, stype_h * type,
                               char *filename, service_h ** match,
                               service_h ** exact_match);
@@ -136,21 +136,35 @@
 
 
 /* Load a service from a service_to_find or process_path */
-service_h *initng_i_parser(char *service_to_find)
+service_h *initng_i_parser(const char *service_to_find)
 {
     char filetoparse[200];
-    char *tmp = NULL;
     service_h *got_serv = NULL;
+    char *path = NULL;
+    const char *service = NULL;
 
     assert(service_to_find);
-
+    
     /* Make sure the filename of 200 chars abow are more than enought */
     if (strlen(service_to_find) > 50)
     {
         F_("Service name to long, initng_i_parser can't look for this service!\n");
         return (NULL);
     }
-
+    
+    /*
+     * now set up path and service.
+     * if service_to_find is system/initial/udevd
+     * path shud be "system/initial"
+     * and service "udevd"
+     */
+    
+    /* set up a patch copy, has to be free() */
+    path=st_get_path(service_to_find);
+    
+    /* this is a pointer to a entry in service_to_find */
+    service=st_strip_path(service_to_find);
+        
     D_("initng_i_parser(%s);\n", service_to_find);
     /* example  INITNG_ROOT=/etc/initng service_to_find="deamon/sshd INITNG_EXT=".i" */
     /* TRY NO 1, try load   "/etc/initng/daemon/sshd.i" */
@@ -165,10 +179,13 @@
     strcpy(filetoparse, INITNG_ROOT "/");
     strcat(filetoparse, service_to_find);
     strcat(filetoparse, "/");
-    strcat(filetoparse, st_strip_path(service_to_find));
+    strcat(filetoparse, service);
     strcat(filetoparse, INITNG_EXT);
     if ((got_serv = parse_file(filetoparse, service_to_find)))
+    {
+	free(path);
         return (got_serv);
+    }
     filetoparse[0] = '\0';
 
     /* TRY NO 2, try load   "/etc/initng/daemon/sshd.i" */
@@ -176,7 +193,10 @@
     strcat(filetoparse, service_to_find);
     strcat(filetoparse, INITNG_EXT);
     if ((got_serv = parse_file(filetoparse, service_to_find)))
+    {
+	free(path);
         return (got_serv);
+    }
     filetoparse[0] = '\0';
 
     /* TRY NO 3, try load   "/etc/initng/daemon/sshd/default.i" */
@@ -184,65 +204,65 @@
     strcat(filetoparse, service_to_find);
     strcat(filetoparse, "/default" INITNG_EXT);
     if ((got_serv = parse_file(filetoparse, service_to_find)))
+    {
+	free(path);
         return (got_serv);
+    }
     filetoparse[0] = '\0';
 
     /* TRY NO 4, try "/etc/initng/daemon/default.i" */
-    if ((tmp = st_get_path(service_to_find)))
-    {
         strcpy(filetoparse, INITNG_ROOT "/");
-        strcat(filetoparse, tmp);
+        strcat(filetoparse, path);
         strcat(filetoparse, "/default" INITNG_EXT);
-        free(tmp);
-        tmp = NULL;
 
         if ((got_serv = parse_file(filetoparse, service_to_find)))
+	{
+	    free(path);
             return (got_serv);
-    }
+	}
     filetoparse[0] = '\0';
 
-    /* TRY NO 5, try "/etc/initng/daemon/daemon.i" */
-    if ((tmp = st_get_path(service_to_find)))
-    {
         strcpy(filetoparse, INITNG_ROOT "/");
-        strcat(filetoparse, tmp);
+        strcat(filetoparse, path);
         strcat(filetoparse, "/");
-        strcat(filetoparse, tmp);
+        strcat(filetoparse, path);
         strcat(filetoparse, INITNG_EXT);
-        free(tmp);
-        tmp = NULL;
         if ((got_serv = parse_file(filetoparse, service_to_find)))
+	{
+	    free(path);
             return (got_serv);
-    }
+	}
     filetoparse[0] = '\0';
 
     /* TRY NO 6, try "/etc/initng/sshd.i" */
     strcpy(filetoparse, INITNG_ROOT "/");
-    strcat(filetoparse, st_strip_path(service_to_find));
+    strcat(filetoparse, service);
     strcat(filetoparse, INITNG_EXT);
     if ((got_serv = parse_file(filetoparse, service_to_find)))
+    {
+	free(path);
         return (got_serv);
+    }
     filetoparse[0] = '\0';
 
     /* TRY NO 7, try "/etc/initng/daemon.i" */
-    if ((tmp = st_get_path(service_to_find)))
-    {
         strcpy(filetoparse, INITNG_ROOT "/");
-        strcat(filetoparse, tmp);
+        strcat(filetoparse, path);
         strcat(filetoparse, INITNG_EXT);
-        free(tmp);
-        tmp = NULL;
         if ((got_serv = parse_file(filetoparse, service_to_find)))
+	{
+	    free(path);
             return (got_serv);
+	}
         filetoparse[0] = '\0';
-    }
 
     D_("Was not able to parse: %s\n", service_to_find);
+    free(path);
     return (NULL);
 }
 
 /* parse a file for services */
-static service_h *parse_file(char *filename, char *watch_for)
+static service_h *parse_file(char *filename, const char *watch_for)
 {
     /* Pointer to content read, and pointer to where we are reading */
     char *file_content = NULL;
@@ -343,7 +363,7 @@
 
 
 
-static int parse_service_line(char **to_parse, char *watch_for,
+static int parse_service_line(char **to_parse, const char *watch_for,
                               service_h * father, stype_h * type,
                               char *filename, service_h ** match,
                               service_h ** exact_match)

Modified: initng/plugins/iparser/initng_i_parser.h
==============================================================================
--- initng/plugins/iparser/initng_i_parser.h	(original)
+++ initng/plugins/iparser/initng_i_parser.h	Mon Dec 12 12:15:12 2005
@@ -24,7 +24,7 @@
 #include "../../src/initng_global.h"
 #include "../../src/initng_service_cache.h"
 
-service_h *initng_i_parser(char *process_name);
+service_h *initng_i_parser(const char *process_name);
 int module_init(const char *version);
 void module_unload(void);
 

Modified: initng/src/initng_common.c
==============================================================================
--- initng/src/initng_common.c	(original)
+++ initng/src/initng_common.c	Mon Dec 12 12:15:12 2005
@@ -307,7 +307,7 @@
 }
 
 
-service_h *parse_service(char *name)
+service_h *parse_service(const char *name)
 {
     s_call *current, *safe = NULL;
     service_h *service = NULL;

Modified: initng/src/initng_common.h
==============================================================================
--- initng/src/initng_common.h	(original)
+++ initng/src/initng_common.h	Mon Dec 12 12:15:12 2005
@@ -24,7 +24,7 @@
 #include "initng.h"
 #include "initng_active_db.h"
 
-service_h *parse_service(char *name);
+service_h *parse_service(const char *name);
 active_h *load_to_active(const char *new_s_name);
 int get_service(active_h * service);
 int mark_service(active_h * service, a_state_h * state);

Modified: initng/src/initng_env_variable.c
==============================================================================
--- initng/src/initng_env_variable.c	(original)
+++ initng/src/initng_env_variable.c	Mon Dec 12 12:15:12 2005
@@ -228,7 +228,6 @@
  */
 char *fix_variables(char *from, active_h * s)
 {
-    char *tmp;                  /* tempoaray space to use */
     char *to;                   /* this is the pointer we are going to return */
     char *set;                  /* pointer to step */
     int i;                      /* temporary counter */
@@ -283,6 +282,7 @@
 
         if (strncasecmp(from, "NAME", len) == 0)
         {
+	    const char *tmp=NULL;
             if ((tmp = st_strip_path(s->name)))
             {
                 strcpy(set, tmp);
@@ -298,6 +298,7 @@
 
         if (strncasecmp(from, "CLASS", len) == 0)
         {
+	    char *tmp=NULL;
             if ((tmp = st_get_path(s->name)))
             {
                 strcpy(set, tmp);
@@ -340,7 +341,8 @@
         }
 
         /* get variable from ENV type */
-        tmp = NULL;
+	{
+    	char *tmp = NULL;
         while ((tmp = active_db_get_next_string(&ENV, s, tmp)))
         {
             if (strncasecmp(from, tmp, len) == 0 && tmp[len] == '=')
@@ -349,13 +351,14 @@
                 goto go_forward;
             }
         }
+	}
 
         /* Get the variable from the data set on an initng_variable */
         {
             s_entry *entry = NULL;
 
             /* Copy the string, so that we can put an '\0' on the end */
-            tmp = i_strndup(from, len);
+            char *tmp = i_strndup(from, len);
             if (!tmp)
                 goto print_error;
 
@@ -408,10 +411,11 @@
 
       print_error:
         /* Print a fancy error message */
-        tmp = strndup(from, len);
+	{
+        char *tmp = strndup(from, len);
         W_("Service %s Unknown variable ${%s}!\n", s->name, tmp);
         free(tmp);
-
+	}
       copy_char:
         /* Copy the char, and move on. */
         set[0] = from[0];

Modified: initng/src/initng_plugin.h
==============================================================================
--- initng/src/initng_plugin.h	(original)
+++ initng/src/initng_plugin.h	Mon Dec 12 12:15:12 2005
@@ -61,7 +61,7 @@
     /* put all hook functions here */
     int (*test_status) (active_h * service, a_state_h * status);
     int (*status_change) (active_h * service);
-    service_h *(*parser) (char *name);
+    service_h *(*parser) (const char *name);
     void (*swatcher) (h_sys_state state);
     void (*pipewatcher) (active_h * service, int datalen, process_h * process,
                          int forceflush);

Modified: initng/src/initng_string_tools.c
==============================================================================
--- initng/src/initng_string_tools.c	(original)
+++ initng/src/initng_string_tools.c	Mon Dec 12 12:15:12 2005
@@ -291,7 +291,7 @@
 
 
 /* function strips "test/go/th" to "th" */
-char *st_strip_path(char *string)
+const char *st_strip_path(const char *string)
 {
     int i = 0;
 
@@ -311,7 +311,7 @@
 }
 
 /* function strips "test/go/th" to "test/go" */
-char *st_get_path(char *string)
+char *st_get_path(const char *string)
 {
     int i = 0;
 

Modified: initng/src/initng_string_tools.h
==============================================================================
--- initng/src/initng_string_tools.h	(original)
+++ initng/src/initng_string_tools.h	Mon Dec 12 12:15:12 2005
@@ -52,9 +52,9 @@
 int st_cmp(char **string, const char *to_cmp);
 char *st_dup_next_word(char **string);
 char *st_dup_line(char **string);
-char *st_strip_path(char *string);
+const char *st_strip_path(const char *string);
 int st_strip_end(char **string);
-char *st_get_path(char *string);
+char *st_get_path(const char *string);
 
 /* to use with split_delim */
 #define WHITESPACE " \t\n\r\v"


More information about the Initng-svn mailing list