| 1 |
/* External declarations for convert-db. |
| 2 |
* |
| 3 |
* IRC Services is copyright (c) 1996-2009 Andrew Church. |
| 4 |
* E-mail: <achurch@achurch.org> |
| 5 |
* Parts written by Andrew Kempe and others. |
| 6 |
* This program is free but copyrighted software; see the file GPL.txt for |
| 7 |
* details. |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef CONVERT_DB_H |
| 11 |
#define CONVERT_DB_H |
| 12 |
|
| 13 |
/*************************************************************************/ |
| 14 |
|
| 15 |
/* Common includes. */ |
| 16 |
|
| 17 |
#include "services.h" |
| 18 |
#include "language.h" |
| 19 |
#include "encrypt.h" |
| 20 |
#include "modules/database/fileutil.h" |
| 21 |
#include "modules/nickserv/nickserv.h" |
| 22 |
#include "modules/chanserv/chanserv.h" |
| 23 |
#include "modules/memoserv/memoserv.h" |
| 24 |
#include "modules/operserv/operserv.h" |
| 25 |
#include "modules/operserv/maskdata.h" |
| 26 |
#include "modules/operserv/news.h" |
| 27 |
#include "modules/statserv/statserv.h" |
| 28 |
|
| 29 |
/*************************************************************************/ |
| 30 |
/*************************************************************************/ |
| 31 |
|
| 32 |
/* Structure with information about each supported database type. */ |
| 33 |
|
| 34 |
typedef struct { |
| 35 |
/* Identifier (used with +xyz command-line option) */ |
| 36 |
const char *id; |
| 37 |
/* Routine to check whether databases for this program are in the given |
| 38 |
* directory; returns a program/database-type name for use in the |
| 39 |
* "Found XYZ databases" message if databases are found, NULL if not */ |
| 40 |
const char *(*check)(const char *dir); |
| 41 |
/* Routine to load databases from the given directory; prints an |
| 42 |
* appropriate error message and calls exit(1) if an error occurs. |
| 43 |
* ac/av are loaded with all option arguments passed to the program |
| 44 |
* not parsed out by the main code; av[0] will contain the program |
| 45 |
* name as usual */ |
| 46 |
void (*load)(const char *dir, int verbose, int ac, char **av); |
| 47 |
} DBTypeInfo; |
| 48 |
|
| 49 |
/* List of all available types. This macro is used twice in convert-db.c: |
| 50 |
* once with an empty PREFIX to declare all of the structures extern, and |
| 51 |
* once more with a PREFIX of & to define an array of pointers to the |
| 52 |
* structures. */ |
| 53 |
|
| 54 |
#define ALL_DB_TYPES(PREFIX) \ |
| 55 |
PREFIX dbtype_anope, \ |
| 56 |
PREFIX dbtype_auspice, \ |
| 57 |
PREFIX dbtype_bolivia, \ |
| 58 |
PREFIX dbtype_cygnus, \ |
| 59 |
PREFIX dbtype_daylight, \ |
| 60 |
PREFIX dbtype_epona, \ |
| 61 |
PREFIX dbtype_hybserv, \ |
| 62 |
PREFIX dbtype_ircs_1_2, \ |
| 63 |
PREFIX dbtype_magick_14b2, \ |
| 64 |
PREFIX dbtype_ptlink, \ |
| 65 |
PREFIX dbtype_sirv, \ |
| 66 |
PREFIX dbtype_trircd_4_26, \ |
| 67 |
PREFIX dbtype_wrecked_1_2 |
| 68 |
|
| 69 |
/*************************************************************************/ |
| 70 |
/*************************************************************************/ |
| 71 |
|
| 72 |
/* Converted data. */ |
| 73 |
extern NickGroupInfo *ngi_list; |
| 74 |
extern NickInfo *ni_list; |
| 75 |
extern ChannelInfo *ci_list; |
| 76 |
extern NewsItem *news_list; |
| 77 |
extern MaskData *md_list[256]; |
| 78 |
extern ServerStats *ss_list; |
| 79 |
extern int32 maxusercnt; |
| 80 |
extern time_t maxusertime; |
| 81 |
extern Password supass; |
| 82 |
extern int no_supass; |
| 83 |
|
| 84 |
/*************************************************************************/ |
| 85 |
|
| 86 |
/* Safe memory allocation and string duplication. */ |
| 87 |
extern void *smalloc(long size); |
| 88 |
extern void *scalloc(long els, long elsize); |
| 89 |
extern void *srealloc(void *ptr, long size); |
| 90 |
extern char *sstrdup(const char *s); |
| 91 |
/* Initialize or clear a Password structure. */ |
| 92 |
extern void init_password(Password *password); |
| 93 |
extern void clear_password(Password *password); |
| 94 |
|
| 95 |
/* Allocate a new, initialized NickInfo (and possibly NickGroupInfo) |
| 96 |
* structure. */ |
| 97 |
extern NickInfo *makenick(const char *nick, NickGroupInfo **nickgroup_ret); |
| 98 |
/* Allocate a new, initialized ChannelInfo structure. */ |
| 99 |
extern ChannelInfo *makechan(const char *name); |
| 100 |
|
| 101 |
/* Open a (Services pre-5.0 style) data file and check the version number. |
| 102 |
* Prints an error message and exits with 1 if either the file cannot be |
| 103 |
* opened or the version number is wrong. If `version_ret' is non-NULL, |
| 104 |
* the version number is stored there. */ |
| 105 |
extern dbFILE *open_db_ver(const char *dir, const char *name, |
| 106 |
int32 min_version, int32 max_version, |
| 107 |
int32 *version_ret); |
| 108 |
|
| 109 |
|
| 110 |
/* Retrieve the NickGroupInfo structure for the given nick. Returns NULL |
| 111 |
* if the nick does not exist or is forbidden (i.e. has no NickGroupInfo). */ |
| 112 |
extern NickGroupInfo *get_nickgroupinfo_by_nick(const char *nick); |
| 113 |
|
| 114 |
/* Set the OperServ privilege level (os_priv) for the nickgroup associated |
| 115 |
* with `nick' to `level', if it is not already greater than `level'. Does |
| 116 |
* nothing if `nick' is NULL or does not have an associated nickgroup. */ |
| 117 |
extern void set_os_priv(const char *nick, int16 level); |
| 118 |
|
| 119 |
/* Return the Services 5.0 channel access level that corresponds to the |
| 120 |
* given pre-5.0 level. */ |
| 121 |
extern int16 convert_acclev(int16 old); |
| 122 |
|
| 123 |
/* Add or remove various things to or from the appropriate lists. */ |
| 124 |
#define add_nickgroupinfo(ngi) LIST_INSERT((ngi), ngi_list) |
| 125 |
#define add_nickinfo(ni) LIST_INSERT((ni), ni_list) |
| 126 |
#define add_channelinfo(ci) LIST_INSERT((ci), ci_list) |
| 127 |
#define add_news(news) LIST_INSERT((news), news_list) |
| 128 |
#define add_maskdata(type,md) LIST_INSERT((md), md_list[(type)]) |
| 129 |
#define add_serverstats(ss) LIST_INSERT((ss), ss_list) |
| 130 |
#define del_nickgroupinfo(ngi) LIST_REMOVE((ngi), ngi_list) |
| 131 |
#define del_nickinfo(ni) LIST_REMOVE((ni), ni_list) |
| 132 |
#define del_channelinfo(ci) LIST_REMOVE((ci), ci_list) |
| 133 |
#define del_news(news) LIST_REMOVE((news), news_list) |
| 134 |
#define del_maskdata(type,md) LIST_REMOVE((md), md_list[(type)]) |
| 135 |
#define del_serverstats(ss) LIST_REMOVE((ss), ss_list) |
| 136 |
|
| 137 |
/*************************************************************************/ |
| 138 |
|
| 139 |
#ifdef CONVERT_DB_MAIN |
| 140 |
|
| 141 |
/* Macro to handle write errors. */ |
| 142 |
#define SAFE(x) do { \ |
| 143 |
if ((x) < 0) { \ |
| 144 |
fprintf(stderr, "Write error on %s: %s\n", \ |
| 145 |
f->filename, strerror(errno)); \ |
| 146 |
exit(1); \ |
| 147 |
} \ |
| 148 |
} while (0) |
| 149 |
|
| 150 |
#else /* !CONVERT_DB_MAIN */ |
| 151 |
|
| 152 |
/* Macro to handle read errors. */ |
| 153 |
#define SAFE(x) do { \ |
| 154 |
if ((x) < 0) { \ |
| 155 |
fprintf(stderr, "Read error on %s\n", f->filename); \ |
| 156 |
exit(1); \ |
| 157 |
} \ |
| 158 |
} while (0) |
| 159 |
|
| 160 |
/* Macro to read in a variable in machine format. */ |
| 161 |
#define read_variable(var,f) (read_db((f),&(var),sizeof(var)) == sizeof(var)) |
| 162 |
|
| 163 |
#endif /* CONVERT_DB_MAIN */ |
| 164 |
|
| 165 |
/*************************************************************************/ |
| 166 |
|
| 167 |
/* Miscellaneous externs. */ |
| 168 |
|
| 169 |
extern void usage(const char *progname); |
| 170 |
|
| 171 |
/*************************************************************************/ |
| 172 |
|
| 173 |
#endif /* CONVERT_DB_H */ |
| 174 |
|
| 175 |
/* |
| 176 |
* Local variables: |
| 177 |
* c-file-style: "stroustrup" |
| 178 |
* c-file-offsets: ((case-label . *) (statement-case-intro . *)) |
| 179 |
* indent-tabs-mode: nil |
| 180 |
* End: |
| 181 |
* |
| 182 |
* vim: expandtab shiftwidth=4: |
| 183 |
*/ |