示例#1
0
XML * DSREP_localxml_init (WFTK_ADAPTOR * ad, va_list args) {
    struct stat statbuf;
    const char * parms;
    char directory[256];
    char * end;

    parms = xml_attrval (ad->parms, "parm");
    if (!*parms) parms = config_get_value (ad->session, "dsrep.localxml.directory");

    /* Check for existence, return error if the directory doesn't exist or if it isn't a directory. */
    strcpy (directory, parms);
    end = directory + strlen (directory) - 1;
    if (*end == '\\') *end = '\0';

    if (stat (directory, &statbuf) == -1) {
        xml_set (ad->parms, "error", "Directory not found.");
        return (XML *) 0;
    }
    if (!(statbuf.st_mode & S_IFDIR)) {
        xml_set (ad->parms, "error", "Directory not directory.");
        return (XML *) 0;
    }

    strcat (directory, "\\");
    xml_set (ad->parms, "dir", directory);
    strcpy (directory, "localxml:");
    strcat (directory, xml_attrval (ad->parms, "dir"));
    xml_set (ad->parms, "spec", directory);
    return (XML *) 0;
}
XML * TASKINDEX_stdout_procput (WFTK_ADAPTOR * ad, va_list args)
{
   XML * datasheet = (XML *) 0;

   if (args) datasheet = va_arg (args, XML *);
   if (!datasheet) {
      xml_set (ad->parms, "error", "No process given.");
      return (XML *) 0;
   }
   printf ("PROC put:%s:%s:%s\n", xml_attrval (datasheet, "id"),
                                  xml_attrval (datasheet, "label"),
                                  xml_attrval (datasheet, "state"));
   return (XML *) 0;
}
示例#3
0
XML * DSREP_localxml_load (WFTK_ADAPTOR * ad, va_list args) {
    char path[256];
    char *id = (char *) 0;
    FILE *file;
    XML * ret;

    if (args) id = va_arg (args, char *);
    if (!id) {
        xml_set (ad->parms, "error", "No ID given.");
        return (XML *) 0;
    }

    strcpy (path, xml_attrval (ad->parms, "dir"));
    strcat (path, id);
    strcat (path, ".xml");
    file = fopen (path, "r");
    if (!file) {
        xml_set (ad->parms, "error", "Couldn't open file for reading.");
        return (XML *) 0;
    }

    ret = xml_read (file);
    fclose (file);

    return ret;
}
示例#4
0
XML * DSREP_localxml_new  (WFTK_ADAPTOR * ad, va_list args)
{
    char path[256];
    struct stat statbuf;
    char * id = (char *) 0;
    FILE * file;
    XML * ret = xml_create ("datasheet");

    if (args) id = va_arg (args, char *);
    if (id) {
        strcpy (path, xml_attrval (ad->parms, "dir"));
        strcat (path, id);
        strcat (path, ".xml");
        if (stat (path, &statbuf) == -1) {
            file = fopen (path, "w");
            if (file) {
                xml_set (ret, "id", id);
                xml_write (file, ret);
                fclose (file);
            } else {
                xml_set (ad->parms, "error", "Couldn't open file for writing.");
            }
        } else {
            xml_set (ad->parms, "error", "File already exists.");
        }
    }
    return ret;
}
XML * TASKINDEX_stdout_reqput (WFTK_ADAPTOR * ad, va_list args)
{
   XML * task = (XML *) 0;

   if (args) task = va_arg (args, XML *);
   if (!task) {
      xml_set (ad->parms, "error", "No request given.");
      return (XML *) 0;
   }
   printf ("REQ put:%s:%s:%s:%s:%s\n", xml_attrval (task, "process"),
                                       xml_attrval (task, "id"),
                                       xml_attrval (task, "label"),
                                       xml_attrval (task, "role"),
                                       xml_attrval (task, "user"));
   return (XML *) 0;
}
示例#6
0
const char * config_get_value (void * session, const char * valuename) {
   XML * mark = config_get_option (session, valuename);
   if (mark) return (xml_attrval (mark, "value"));

   if (!strcmp (valuename, "pdrep.localxml.directory")) return PROCDEF_DIRECTORY;
   if (!strcmp (valuename, "dsrep.localxml.directory")) return DATASHEET_DIRECTORY;
   if (!strcmp (valuename, "user.localxml.directory")) return USER_DIRECTORY;
   if (!strcmp (valuename, "group.localxml.directory")) return GROUP_DIRECTORY;
   if (!strcmp (valuename, "taskindex.odbc.?.conn")) return ODBC_CONNECTION;
   return "";
}
示例#7
0
XML * config_find_option (XML * xml, const char * name) {
   int len;
   XML * x;
   char * mark = strchr (name, '.');

   if (mark) len = mark - name;
   else      len = strlen (name);

   x = xml_firstelem (xml);
   while (x) {
      if (!strncmp (xml_attrval (x, "name"), name, len) ||
          !strncmp (xml_attrval (x, "id"), name, len)   ||
          !strncmp ("?", name, len)) {
         if (mark) {
            return (config_find_option (x, mark + 1));
         }
         return (x);
      }
      x = xml_nextelem (x);
   }
   return NULL;
}
示例#8
0
XML * PDREP_localxml_version  (WFTK_ADAPTOR * ad, va_list args)
{
   char path[256];
   char * id = (char *) 0;
   FILE * file;
   XML * index;
   XML * value;

   xml_set (ad->parms, "error", "");
   if (args) id = va_arg (args, char *);
   if (!id) {
      xml_set (ad->parms, "error", "No ID given.");
      return (XML *) 0;
   }

   strcpy (path, xml_attrval (ad->parms, "dir"));
   strcat (path, id);
   strcat (path, "__versions.xml");
   file = fopen (path, "r");
   if (!file) {
      xml_set (ad->parms, "error", "Procdef master file not found.");
      return (XML *) 0;
   }

   index = xml_read (file);
   if (!index) {
      xml_set (ad->parms, "error", "Procdef master file corrupted.");
      return (XML *) 0;
   }

   value = xml_create ("value");
   xml_set (value, "value", xml_attrval (index, "ver"));

   xml_free (index);
   fclose (file);

   return value;
}
示例#9
0
XML * DSREP_localxml_delete (WFTK_ADAPTOR * ad, va_list args) {
    char path[256];
    char * id = (char *) 0;

    if (args) id = va_arg (args, char *);
    if (!id) {
        xml_set (ad->parms, "error", "No ID given.");
        return (XML *) 0;
    }

    strcpy (path, xml_attrval (ad->parms, "dir"));
    strcat (path, id);
    strcat (path, ".xml");
    if (-1 == unlink (path)) {
        if (errno == EACCES) xml_set (ad->parms, "error", "Insufficient filesystem access.");
    }
    return (XML *) 0;
}
示例#10
0
XML * ACTION_system_do  (WFTK_ADAPTOR * ad, va_list args)
{
   XML * action = (XML *) 0;
   const char * aname;
   char * content;

   if (args) action = va_arg (args, XML *);
   if (action) {
      aname = xml_attrval (action, "action");
      if (!strcmp (aname, "exec")) {
         /* TODO: Line by line, run the content of the action through the data interpreter
            and pass it over to the shell.  Primitive, yeah -- you can't break lines. */
         /* TODO: do a better parser for this, line breaks and stuff. */
         content = xml_stringcontent (action);
         system (content);
         free (content);
      }
   }
   return 0;
}
示例#11
0
XML * DSREP_localxml_save (WFTK_ADAPTOR * ad, va_list args) {
    char path[256];
    struct stat statbuf;
    XML  * ds = (XML *) 0;
    FILE * file;
    FILE * _index;
    XML  * index;
    int  counter;

    if (args) ds = va_arg (args, XML *);
    if (!ds) {
        xml_set (ad->parms, "error", "No datasheet given.");
        return (XML *) 0;
    }

    if (*xml_attrval (ds, "id")) {
        strcpy (path, xml_attrval (ad->parms, "dir"));
        strcat (path, xml_attrval (ds, "id"));
        strcat (path, ".xml");
        file = fopen (path, "w");
    } else {
        /* Find a unique ID. */
        strcpy (path, xml_attrval (ad->parms, "dir"));
        strcat (path, "index");
        if (stat (path, &statbuf) == -1) {
            _index = fopen (path, "w");
            if (!_index) {
                xml_set (ad->parms, "error", "Unable to create index file.");
                return (XML *) 0;
            }
            index = xml_create ("index");
        } else {
            _index = fopen (path, "r+");
            if (_index) {
                index = xml_read (_index);
                rewind (_index);
            } else {
                xml_set (ad->parms, "error", "Unable to create index file.");
                return (XML *) 0;
            }
        }
        if (!index) {
            xml_set (ad->parms, "error", "Directory index file corrupt.");
            return (XML *) 0;
        }

        if (!xml_attrval (index, "counter")) xml_set (index, "counter", "0");

        counter = xml_attrvalnum (index, "counter");
        do {
            counter ++;
            xml_setnum (ds, "id", counter);
            strcpy (path, xml_attrval (ad->parms, "dir"));
            strcat (path, xml_attrval (ds, "id"));
            strcat (path, ".xml");
        } while (stat (path, &statbuf) != -1);
        file = fopen (path, "w");

        xml_setnum (index, "counter", counter);
        xml_write (_index, index);
        fclose (_index);
    }

    if (file) {
        xml_write (file, ds);
        fclose (file);
    } else {
        xml_set (ad->parms, "error", "Couldn't open file for writing.");
        return (XML *) 0;
    }

    return ds;
}
示例#12
0
static
int
fw_load_conf(struct fw_ctx *fctx, xmlNodePtr node)
{
	int mult, val;
	char *s;
	
	if (!node)
		return -1;
	
	memset(fctx, 0, sizeof(*fctx));
	fctx->chmod = -1;
	
	for (node = node->xml_children; node; node = node->next)
	{
		if (xml_isnode(node, "path"))
			fctx->path = xml_getcontent(node);
		else if (xml_isnode(node, "cmd"))
			fctx->cmd = xml_getcontent(node);
		else if (xml_isnode(node, "interval"))
		{
			mult = 1;
			s = xml_attrval(node, "unit");
			if (!s)
				s = xml_attrval(node, "units");
			if (s)
			{
				if (!strcmp(s, "sec") || !strcmp(s, "secs") || !strcmp(s, "seconds"))
					;
				else if (!strcmp(s, "min") || !strcmp(s, "mins") || !strcmp(s, "minutes"))
					mult = 60;
				else if (!strcmp(s, "hour") || !strcmp(s, "hours"))
					mult = 3600;
				else if (!strcmp(s, "day") || !strcmp(s, "days"))
					mult = 86400;
				else
				{
					log_log(MODNAME, "Invalid \"unit\" attribute value \"%s\"\n", s);
					return -1;
				}
			}
			val = xml_atoi(node, 0);
			if (val == 0)
			{
				log_log(MODNAME, "Invalid interval (%s) specified\n", xml_getcontent(node));
				return -1;
			}
			fctx->interval = val * mult;
		}
		else if (xml_isnode(node, "chmod") || xml_isnode(node, "mode"))
			fctx->chmod = xml_atoi(node, fctx->chmod);
	}
	
	if (!fctx->path || fctx->interval == 0)
	{
		log_log(MODNAME, "Either path or interval not specified\n");
		return -1;
	}
	
	fctx->path = config_homedir(fctx->path);
	fctx->cmd = config_homedir(fctx->cmd);
	
	return 0;
}