/[LeafOK_CVS]/pvpgn-1.7.4/src/bnetd/storage.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/bnetd/storage.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch point for: GNU, MAIN
Content type: text/x-csrc
Initial revision

1 sysadm 1.1 /*
2     * Copyright (C) 2002,2003 Mihai RUSU (dizzy@roedu.net)
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License
6     * as published by the Free Software Foundation; either version 2
7     * of the License, or (at your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the Free Software
16     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17     */
18    
19     #include "common/setup_before.h"
20     #include "compat/strcasecmp.h"
21     #ifdef HAVE_STRING_H
22     # include <string.h>
23     #else
24     # ifdef HAVE_STRINGS_H
25     # include <strings.h>
26     # endif
27     #endif
28     #ifdef STDC_HEADERS
29     # include <stdlib.h>
30     #else
31     # ifdef HAVE_MALLOC_H
32     # include <malloc.h>
33     # endif
34     #endif
35    
36     #include "storage.h"
37     #include "storage_file.h"
38     #ifdef WITH_SQL
39     #include "storage_sql.h"
40     #endif
41    
42     #include "compat/strdup.h"
43     #include "common/eventlog.h"
44     #include "common/xalloc.h"
45     #include "common/setup_after.h"
46    
47     t_storage *storage = NULL;
48    
49     extern int storage_init(const char *spath)
50     {
51     char *temp, *p;
52     int res;
53     char dstr[256];
54    
55     if (spath == NULL) {
56     eventlog(eventlog_level_error, __FUNCTION__, "got NULL spath");
57     return -1;
58     }
59    
60     temp = xstrdup(spath);
61     if ((p = strchr(spath, ':')) == NULL) {
62     eventlog(eventlog_level_error, __FUNCTION__, "malformed storage_path , driver not found");
63     xfree((void*)temp);
64     return -1;
65     }
66    
67     strcpy(dstr, "file");
68     #ifdef WITH_SQL
69     strcat(dstr, ", sql");
70     #endif
71     eventlog(eventlog_level_info, __FUNCTION__, "initializing storage layer (available drivers: %s)", dstr);
72    
73     *p = '\0';
74     if (strcasecmp(spath, "file") == 0) {
75     storage = &storage_file;
76     res = storage->init(p + 1);
77     if (!res)
78     eventlog(eventlog_level_info, __FUNCTION__, "using file storage driver");
79     }
80     #ifdef WITH_SQL
81     else if (strcasecmp(spath, "sql") == 0) {
82     storage = &storage_sql;
83     res = storage->init(p + 1);
84     if (!res)
85     eventlog(eventlog_level_info, __FUNCTION__, "using sql storage driver");
86     }
87     #endif
88     else {
89     eventlog(eventlog_level_fatal, __FUNCTION__, "no known driver specified (%s)", spath);
90     res = -1;
91     }
92    
93     xfree((void*)temp);
94    
95     return res;
96     }
97    
98     extern void storage_close(void)
99     {
100     storage->close();
101     }
102    

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1