-const char loaders_rcs[] = "$Id: loaders.c,v 1.27 2001/09/22 16:36:59 jongfoster Exp $";
+const char loaders_rcs[] = "$Id: loaders.c,v 1.28 2001/10/07 15:40:39 oes Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.c,v $
*
* Revisions :
* $Log: loaders.c,v $
+ * Revision 1.28 2001/10/07 15:40:39 oes
+ * Replaced 6 boolean members of csp with one bitmap (csp->flags)
+ *
* Revision 1.27 2001/09/22 16:36:59 jongfoster
* Removing unused parameter fs from read_config_line()
*
#include <errno.h>
#include <sys/stat.h>
#include <ctype.h>
+#include <assert.h>
#ifndef _WIN32
#include <unistd.h>
* function fails, the contents of the buffer
* are lost forever.
*
- * Returns : 0 => Ok, everything else is an error.
+ * Returns : JB_ERR_OK - Success
+ * JB_ERR_MEMORY - Out of memory
+ * JB_ERR_PARSE - Cannot parse regex (Detailed message
+ * written to system log)
*
*********************************************************************/
-int create_url_spec(struct url_spec * url, char * buf)
+jb_err create_url_spec(struct url_spec * url, char * buf)
{
char *p;
struct url_spec tmp_url[1];
- /* paranoia - should never happen. */
- if ((url == NULL) || (buf == NULL))
- {
- return 1;
- }
+ assert(url);
+ assert(buf);
/* save a copy of the orignal specification */
if ((url->spec = strdup(buf)) == NULL)
{
- return 1;
+ return JB_ERR_MEMORY;
}
if ((p = strchr(buf, '/')))
if (NULL == (url->path = strdup(p)))
{
freez(url->spec);
- return 1;
+ return JB_ERR_MEMORY;
}
url->pathlen = strlen(url->path);
*p = '\0';
{
freez(url->spec);
freez(url->path);
- return 1;
+ return JB_ERR_MEMORY;
}
sprintf(rebuf, "^(%s)", url->path);
if (errcode)
{
size_t errlen = regerror(errcode,
- url->preg, buf, sizeof(buf));
+ url->preg, rebuf, sizeof(rebuf));
- buf[errlen] = '\0';
+ if (errlen > (sizeof(rebuf) - (size_t)1))
+ {
+ errlen = sizeof(rebuf) - (size_t)1;
+ }
+ rebuf[errlen] = '\0';
log_error(LOG_LEVEL_ERROR, "error compiling %s: %s",
- url->spec, buf);
+ url->spec, rebuf);
freez(url->spec);
freez(url->path);
freez(url->preg);
- return 1;
+ return JB_ERR_PARSE;
}
}
#endif
#ifdef REGEX
freez(url->preg);
#endif /* def REGEX */
- return 1;
+ return JB_ERR_MEMORY;
}
/* split domain into components */
*tmp_url = dsplit(url->domain);
+ if (tmp_url->dbuf == NULL)
+ {
+ freez(url->spec);
+ freez(url->path);
+ freez(url->domain);
+#ifdef REGEX
+ freez(url->preg);
+#endif /* def REGEX */
+ return JB_ERR_MEMORY;
+ }
+
url->dbuf = tmp_url->dbuf;
url->dcnt = tmp_url->dcnt;
url->dvec = tmp_url->dvec;
url->unanchored = tmp_url->unanchored;
- return 0; /* OK */
+ return JB_ERR_OK;
}
#ifndef LOADERS_H_INCLUDED
#define LOADERS_H_INCLUDED
-#define LOADERS_H_VERSION "$Id: loaders.h,v 1.9 2001/07/30 22:08:36 jongfoster Exp $"
+#define LOADERS_H_VERSION "$Id: loaders.h,v 1.10 2001/09/22 16:36:59 jongfoster Exp $"
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/loaders.h,v $
*
* Revisions :
* $Log: loaders.h,v $
+ * Revision 1.10 2001/09/22 16:36:59 jongfoster
+ * Removing unused parameter fs from read_config_line()
+ *
* Revision 1.9 2001/07/30 22:08:36 jongfoster
* Tidying up #defines:
* - All feature #defines are now of the form FEATURE_xxx
-extern int create_url_spec(struct url_spec * url, char * buf);
+extern jb_err create_url_spec(struct url_spec * url, char * buf);
extern void free_url(struct url_spec *url);
extern void add_loader(int (*loader)(struct client_state *),