*/
-struct res_items; /* Declare forward referenced structure */
-typedef void (MSG_RES_HANDLER)(LEX *lc, struct res_items *item, int index, int pass);
+struct RES_ITEM; /* Declare forward referenced structure */
+typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
/* This is the structure that defines
* the record types (items) permitted within each
* resource. It is used to define the configuration
* tables.
*/
-struct res_items {
- char *name; /* Resource name i.e. Director, ... */
+struct RES_ITEM {
+ const char *name; /* Resource name i.e. Director, ... */
MSG_RES_HANDLER *handler; /* Routine storing the resource item */
void **value; /* Where to store the item */
int code; /* item code/additional info */
/* For storing name_addr items in res_items table */
#define ITEM(x) ((void **)&res_all.x)
-#define MAX_RES_ITEMS 32 /* maximum resource items per RES */
+#define MAX_RES_ITEMS 50 /* maximum resource items per RES */
/* This is the universal header that is
* at the beginning of every resource
* record.
*/
-struct s_reshdr {
+struct RES {
+ RES *next; /* pointer to next resource of this type */
char *name; /* resource name */
char *desc; /* resource description */
int rcode; /* resource id or type */
int refcnt; /* reference count for releasing */
char item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
- struct s_reshdr *next; /* pointer to next resource of this type */
};
-typedef struct s_reshdr RES;
/*
* Master Resource configuration structure definition
* This is the structure that defines the
* resources that are available to this daemon.
*/
-struct s_res {
- char *name; /* resource name */
- struct res_items *items; /* list of resource keywords */
+struct RES_TABLE {
+ const char *name; /* resource name */
+ RES_ITEM *items; /* list of resource keywords */
int rcode; /* code if needed */
- RES *res_head; /* where to store it */
};
/* Common Resource definitions */
#define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1 /* maximum resource name length */
-#define ITEM_REQUIRED 0x1 /* item required */
-#define ITEM_DEFAULT 0x2 /* default supplied */
+#define ITEM_REQUIRED 0x1 /* item required */
+#define ITEM_DEFAULT 0x2 /* default supplied */
+#define ITEM_NO_EQUALS 0x4 /* Don't scan = after name */
/* Message Resource */
-struct s_res_msgs {
+struct MSGS {
RES hdr;
char *mail_cmd; /* mail command */
char *operator_cmd; /* Operator command */
DEST *dest_chain; /* chain of destinations */
char send_msg[nbytes_for_bits(M_MAX+1)]; /* bit array of types */
};
-typedef struct s_res_msgs MSGS;
/* Define the Union of all the above common
* resource structure definitions.
*/
-union cu_res {
- struct s_res_msgs res_msgs;
+union CURES {
+ MSGS res_msgs;
RES hdr;
};
-typedef union cu_res CURES;
-
/* Configuration routines */
-void parse_config __PROTO((char *cf));
-void free_config_resources __PROTO(());
+int parse_config(const char *cf, int exit_on_error = 1);
+void free_config_resources(void);
+RES **save_config_resources(void);
+RES **new_res_head();
+
/* Resource routines */
RES *GetResWithName(int rcode, char *name);
RES *GetNextRes(int rcode, RES *res);
-void LockRes(void);
-void UnlockRes(void);
-void dump_resource(int type, RES *res, void sendmsg(void *sock, char *fmt, ...), void *sock);
-void free_resource(int type);
-void init_resource(int type, struct res_items *item);
-void save_resource(int type, struct res_items *item, int pass);
-
-
-void scan_error(LEX *lc, char *msg, ...); /* old way, do not use */
-void scan_to_eol(LEX *lc);
-char *res_to_str(int rcode);
-
-void store_str(LEX *lc, struct res_items *item, int index, int pass);
-void store_dir(LEX *lc, struct res_items *item, int index, int pass);
-void store_password(LEX *lc, struct res_items *item, int index, int pass);
-void store_name(LEX *lc, struct res_items *item, int index, int pass);
-void store_strname(LEX *lc, struct res_items *item, int index, int pass);
-void store_res(LEX *lc, struct res_items *item, int index, int pass);
-void store_int(LEX *lc, struct res_items *item, int index, int pass);
-void store_pint(LEX *lc, struct res_items *item, int index, int pass);
-void store_msgs(LEX *lc, struct res_items *item, int index, int pass);
-void store_int64(LEX *lc, struct res_items *item, int index, int pass);
-void store_yesno(LEX *lc, struct res_items *item, int index, int pass);
-void store_time(LEX *lc, struct res_items *item, int index, int pass);
-void store_size(LEX *lc, struct res_items *item, int index, int pass);
-
-/* Lexical scanning errors in parsing conf files */
-#define scan_err0(lc, msg) s_err(__FILE__, __LINE__, lc, msg)
-#define scan_err1(lc, msg, a1) s_err(__FILE__, __LINE__, lc, msg, a1)
-#define scan_err2(lc, msg, a1, a2) s_err(__FILE__, __LINE__, lc, msg, a1, a2)
-#define scan_err3(lc, msg, a1, a2, a3) s_err(__FILE__, __LINE__, lc, msg, a1, a2, a3)
-#define scan_err4(lc, msg, a1, a2, a3, a4) s_err(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4)
-#define scan_err5(lc, msg, a1, a2, a3, a4, a5) s_err(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5)
-#define scan_err6(lc, msg, a1, a2, a3, a4, a5, a6) s_err(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5, a6)
-
-void s_err(char *file, int line, LEX *lc, char *msg,...);
+void b_LockRes(const char *file, int line);
+void b_UnlockRes(const char *file, int line);
+void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...), void *sock);
+void free_resource(RES *res, int type);
+void init_resource(int type, RES_ITEM *item);
+void save_resource(int type, RES_ITEM *item, int pass);
+const char *res_to_str(int rcode);
+
+/* Loop through each resource of type, returning in var */
+#define foreach_res(var, type) \
+ for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
+
+#ifdef the_old_way
+#define foreach_res(var, type) \
+ for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));)
+#endif
+
+
+void store_str(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_dir(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_password(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_name(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_strname(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_res(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_int(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_pint(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_int64(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_yesno(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_time(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_size(LEX *lc, RES_ITEM *item, int index, int pass);
+void store_defs(LEX *lc, RES_ITEM *item, int index, int pass);