Example #1
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;
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}
XML * TASKINDEX_stdout_reqdecline (WFTK_ADAPTOR * ad, va_list args)
{
   const char *process;
   const char *id;

   if (args) process = va_arg (args, char *);
   if (!process) {
      xml_set (ad->parms, "error", "No request given.");
      return (XML *) 0;
   }
   id = va_arg (args, char *);
   if (!id) {
      xml_set (ad->parms, "error", "No request given.");
      return (XML *) 0;
   }
   printf ("REQ decline:%s:%s\n", process, id);
   return (XML *) 0;
}
XML * TASKINDEX_stdout_taskreject (WFTK_ADAPTOR * ad, va_list args)
{
   const char *process;
   const char *id;

   if (args) process = va_arg (args, char *);
   if (!process) {
      xml_set (ad->parms, "error", "No task given.");
      return (XML *) 0;
   }
   id = va_arg (args, char *);
   if (!id) {
      xml_set (ad->parms, "error", "No task given.");
      return (XML *) 0;
   }
   printf ("TASK reject:%s:%s\n", process, id);
   return (XML *) 0;
}
XML * TASKINDEX_stdout_procerror (WFTK_ADAPTOR * ad, va_list args)
{
   const char *id;

   if (args) id = va_arg (args, char *);
   if (!id) {
      xml_set (ad->parms, "error", "No process given.");
      return (XML *) 0;
   }
   printf ("PROC error:%s\n", id);
   return (XML *) 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;
}
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;
}
Example #10
0
XML * DSREP_localxml_info (WFTK_ADAPTOR * ad, va_list args) {
    XML * info;

    info = xml_create ("info");
    xml_set (info, "type", "dsrep");
    xml_set (info, "name", "localxml");
    xml_set (info, "ver", "1.0.0");
    xml_set (info, "compiled", __TIME__ " " __DATE__);
    xml_set (info, "author", "Michael Roberts");
    xml_set (info, "contact", "*****@*****.**");
    xml_set (info, "extra_functions", "0");

    return (info);
}
XML * TASKINDEX_stdout_info (WFTK_ADAPTOR * ad, va_list args) {
   XML * info;

   info = xml_create ("info");
   xml_set (info, "type", "taskindex");
   xml_set (info, "name", "stdout");
   xml_set (info, "ver", "1.0.0");
   xml_set (info, "compiled", __TIME__ " " __DATE__);
   xml_set (info, "author", "Michael Roberts");
   xml_set (info, "contact", "*****@*****.**");
   xml_set (info, "extra_functions", "0");

   return (info);
}
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;
}
Example #13
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;
}
Example #14
0
XML * ACTION_system_init (WFTK_ADAPTOR * ad, va_list args) {
   xml_set (ad->parms, "spec", "wftk");
   return (XML *) 0;
}