~ubuntu-branches/ubuntu/oneiric/eggdrop/oneiric

« back to all changes in this revision

Viewing changes to src/mod/filesys.mod/filedb3.h

  • Committer: Bazaar Package Importer
  • Author(s): Guilherme de S. Pastore
  • Date: 2004-06-17 09:15:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040617091528-64rrw1sa33lkfhmh
Tags: 1.6.16-2
* Fixed typo on README.Debian
* Fixed hyphens in manual page
* Converted debian/rules to CDBS
* Set path to binary on example config file
* Changed LANGDIR on src/eggdrop.h (Closes: #254824)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * Written by Fabian Knittel <fknittel@gmx.de>
6
6
 *
7
 
 * $Id: filedb3.h,v 1.11 2002/01/02 03:46:38 guppy Exp $
 
7
 * $Id: filedb3.h,v 1.16 2004/01/09 05:56:38 wcc Exp $
8
8
 */
9
9
/*
10
 
 * Copyright (C) 1999, 2000, 2001, 2002 Eggheads Development Team
 
10
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Eggheads Development Team
11
11
 *
12
12
 * This program is free software; you can redistribute it and/or
13
13
 * modify it under the terms of the GNU General Public License
27
27
#ifndef _EGG_MOD_FILESYS_FILEDB3_H
28
28
#define _EGG_MOD_FILESYS_FILEDB3_H
29
29
 
30
 
#include <time.h>       /* for time_t */
 
30
/*
 
31
 * FIXME: These really should be in the .c files that include this header
 
32
 */
 
33
#ifdef HAVE_CONFIG_H
 
34
# include "config.h"
 
35
#endif
 
36
 
 
37
/* for time_t */
 
38
#ifdef TIME_WITH_SYS_TIME
 
39
# include <sys/time.h>
 
40
# include <time.h>
 
41
#else
 
42
# ifdef HAVE_SYS_TIME_H
 
43
#  include <sys/time.h>
 
44
# else
 
45
#  include <time.h>
 
46
# endif
 
47
#endif
31
48
 
32
49
/* Top of each DB */
33
50
typedef struct {
34
 
  char version;                         /* DB version                   */
35
 
  time_t timestamp;                     /* Last updated                 */
 
51
  char version;                 /* DB version                   */
 
52
  time_t timestamp;             /* Last updated                 */
36
53
} filedb_top;
37
54
 
38
55
/* Header of each entry */
39
56
typedef struct {
40
 
  time_t uploaded;                      /* Upload time                  */
41
 
  unsigned int size;                    /* File size                    */
42
 
  unsigned short int stat;              /* Misc information             */
43
 
  unsigned short int gots;              /* Number of gets               */
44
 
  unsigned short int filename_len;      /* Length of filename buf       */
45
 
  unsigned short int desc_len;          /* Length of description buf    */
46
 
  unsigned short int sharelink_len;     /* Length of sharelink buf      */
47
 
  unsigned short int chan_len;          /* Length of channel name buf   */
48
 
  unsigned short int uploader_len;      /* Length of uploader buf       */
49
 
  unsigned short int flags_req_len;     /* Length of flags buf          */
50
 
  unsigned short int buffer_len;        /* Length of additional buffer  */
 
57
  time_t uploaded;              /* Upload time                  */
 
58
  unsigned int size;            /* File size                    */
 
59
  unsigned short int stat;      /* Misc information             */
 
60
  unsigned short int gots;      /* Number of gets               */
 
61
  unsigned short int filename_len;      /* Length of filename buf       */
 
62
  unsigned short int desc_len;  /* Length of description buf    */
 
63
  unsigned short int sharelink_len;     /* Length of sharelink buf      */
 
64
  unsigned short int chan_len;  /* Length of channel name buf   */
 
65
  unsigned short int uploader_len;      /* Length of uploader buf       */
 
66
  unsigned short int flags_req_len;     /* Length of flags buf          */
 
67
  unsigned short int buffer_len;        /* Length of additional buffer  */
51
68
} filedb_header;
52
69
 
53
70
/* Structure used to pass data between lower level
54
71
 * and higher level functions.
55
72
 */
56
73
typedef struct {
57
 
  time_t uploaded;                      /* Upload time                  */
58
 
  unsigned int size;                    /* File size                    */
59
 
  unsigned short int stat;              /* Misc information             */
60
 
  unsigned short int gots;              /* Number of gets               */
61
 
  unsigned short int _type;             /* Type of entry (private)      */
 
74
  time_t uploaded;              /* Upload time                  */
 
75
  unsigned int size;            /* File size                    */
 
76
  unsigned short int stat;      /* Misc information             */
 
77
  unsigned short int gots;      /* Number of gets               */
 
78
  unsigned short int _type;     /* Type of entry (private)      */
62
79
 
63
80
  /* NOTE: These three are only valid during one db open/close. Entry
64
81
   *       movements often invalidate them too, so make sure you know
65
82
   *       what you're doing before using/relying on them.
66
83
   */
67
 
  long pos;                             /* Last position in the filedb  */
68
 
  unsigned short int dyn_len;           /* Length of dynamic data in DB */
69
 
  unsigned short int buf_len;           /* Length of additional buffer  */
 
84
  long pos;                     /* Last position in the filedb  */
 
85
  unsigned short int dyn_len;   /* Length of dynamic data in DB */
 
86
  unsigned short int buf_len;   /* Length of additional buffer  */
70
87
 
71
 
  char *filename;                       /* Filename                     */
72
 
  char *desc;                           /* Description                  */
73
 
  char *sharelink;                      /* Share link. Points to remote
74
 
                                           file on linked bot.          */
75
 
  char *chan;                           /* Channel name                 */
76
 
  char *uploader;                       /* Uploader                     */
77
 
  char *flags_req;                      /* Required flags               */
 
88
  char *filename;               /* Filename                     */
 
89
  char *desc;                   /* Description                  */
 
90
  char *sharelink;              /* Share link. Points to remote
 
91
                                 * file on linked bot.          */
 
92
  char *chan;                   /* Channel name                 */
 
93
  char *uploader;               /* Uploader                     */
 
94
  char *flags_req;              /* Required flags               */
78
95
} filedb_entry;
79
96
 
80
97
 
82
99
 *   Macros
83
100
 */
84
101
 
85
 
#define my_free(ptr)                                                    \
86
 
  if (ptr) {                                                            \
87
 
    nfree(ptr);                                                         \
88
 
    ptr = NULL;                                                         \
 
102
#define my_free(ptr)                                                    \
 
103
  if (ptr) {                                                            \
 
104
    nfree(ptr);                                                         \
 
105
    ptr = NULL;                                                         \
89
106
  }
90
107
 
91
108
/* Copy entry to target -- Uses dynamic memory allocation, which
92
109
 * means you'll eventually have to free the memory again. 'target'
93
110
 * will be overwritten.
94
111
 */
95
 
#define malloc_strcpy(target, entry)                                    \
96
 
do {                                                                    \
97
 
  if (entry) {                                                          \
98
 
    (target) = nrealloc((target), strlen(entry) + 1);                   \
99
 
    strcpy((target), (entry));                                          \
100
 
  } else                                                                \
101
 
    my_free(target);                                                    \
 
112
#define malloc_strcpy(target, entry)                                    \
 
113
do {                                                                    \
 
114
  if (entry) {                                                          \
 
115
    (target) = nrealloc((target), strlen(entry) + 1);                   \
 
116
    strcpy((target), (entry));                                          \
 
117
  } else                                                                \
 
118
    my_free(target);                                                    \
102
119
} while (0)
103
120
 
104
121
/* Macro to calculate the total length of dynamic data. */
105
 
#define filedb_tot_dynspace(fdh) ((fdh).filename_len + (fdh).desc_len + \
106
 
        (fdh).chan_len + (fdh).uploader_len + (fdh).flags_req_len + \
107
 
        (fdh).sharelink_len)
 
122
#define filedb_tot_dynspace(fdh) ((fdh).filename_len + (fdh).desc_len + \
 
123
        (fdh).chan_len + (fdh).uploader_len + (fdh).flags_req_len + \
 
124
        (fdh).sharelink_len)
108
125
 
109
 
#define filedb_zero_dynspace(fdh) {                                     \
110
 
        (fdh).filename_len      = 0;                                    \
111
 
        (fdh).desc_len          = 0;                                    \
112
 
        (fdh).chan_len          = 0;                                    \
113
 
        (fdh).uploader_len      = 0;                                    \
114
 
        (fdh).flags_req_len     = 0;                                    \
115
 
        (fdh).sharelink_len     = 0;                                    \
 
126
#define filedb_zero_dynspace(fdh) {                                     \
 
127
        (fdh).filename_len      = 0;                                    \
 
128
        (fdh).desc_len          = 0;                                    \
 
129
        (fdh).chan_len          = 0;                                    \
 
130
        (fdh).uploader_len      = 0;                                    \
 
131
        (fdh).flags_req_len     = 0;                                    \
 
132
        (fdh).sharelink_len     = 0;                                    \
116
133
}
117
134
 
118
135
/* Memory debugging makros */
128
145
 *  Constants
129
146
 */
130
147
 
131
 
#define FILEDB_VERSION1 0x0001
132
 
#define FILEDB_VERSION2 0x0002  /* DB version used for 1.3, 1.4         */
133
 
#define FILEDB_VERSION3 0x0003
134
 
#define FILEDB_NEWEST_VER FILEDB_VERSION3       /* Newest DB version    */
135
 
 
136
 
#define POS_NEW         0       /* Position which indicates that the
137
 
                                   entry wants to be repositioned.      */
138
 
 
139
 
#define FILE_UNUSED     0x0001  /* Deleted entry.                       */
140
 
#define FILE_DIR        0x0002  /* It's actually a directory.           */
141
 
#define FILE_SHARE      0x0004  /* Can be shared on the botnet.         */
142
 
#define FILE_HIDDEN     0x0008  /* Hidden file.                         */
143
 
#define FILE_ISLINK     0x0010  /* The file is a link to another bot.   */
144
 
 
145
 
#define FILEDB_ESTDYN   50      /* Estimated dynamic length of an entry */
 
148
#define FILEDB_VERSION1 0x0001
 
149
#define FILEDB_VERSION2 0x0002  /* DB version used for 1.3, 1.4         */
 
150
#define FILEDB_VERSION3 0x0003
 
151
#define FILEDB_NEWEST_VER FILEDB_VERSION3       /* Newest DB version    */
 
152
 
 
153
#define POS_NEW         0       /* Position which indicates that the
 
154
                                 * entry wants to be repositioned.      */
 
155
 
 
156
#define FILE_UNUSED     0x0001  /* Deleted entry.                       */
 
157
#define FILE_DIR        0x0002  /* It's actually a directory.           */
 
158
#define FILE_SHARE      0x0004  /* Can be shared on the botnet.         */
 
159
#define FILE_HIDDEN     0x0008  /* Hidden file.                         */
 
160
#define FILE_ISLINK     0x0010  /* The file is a link to another bot.   */
 
161
 
 
162
#define FILEDB_ESTDYN   50      /* Estimated dynamic length of an entry */
146
163
 
147
164
enum {
148
 
  GET_HEADER,                   /* Only save minimal data               */
149
 
  GET_FILENAME,                 /* Additionally save filename           */
150
 
  GET_FULL,                     /* Save all data                        */
151
 
 
152
 
  UPDATE_HEADER,                /* Only update header                   */
153
 
  UPDATE_SIZE,                  /* Update header, enforce new buf sizes */
154
 
  UPDATE_ALL,                   /* Update additional data too           */
155
 
 
156
 
  TYPE_NEW,                     /* New entry                            */
157
 
  TYPE_EXIST                    /* Existing entry                       */
 
165
  GET_HEADER,                   /* Only save minimal data               */
 
166
  GET_FILENAME,                 /* Additionally save filename           */
 
167
  GET_FULL,                     /* Save all data                        */
 
168
 
 
169
  UPDATE_HEADER,                /* Only update header                   */
 
170
  UPDATE_SIZE,                  /* Update header, enforce new buf sizes */
 
171
  UPDATE_ALL,                   /* Update additional data too           */
 
172
 
 
173
  TYPE_NEW,                     /* New entry                            */
 
174
  TYPE_EXIST                    /* Existing entry                       */
158
175
};
159
176
 
160
177
 
175
192
static filedb_entry *_filedb_matchfile(FILE *, long, char *, char *, int);
176
193
static filedb_entry *filedb_getentry(char *, char *);
177
194
 
178
 
#endif                          /* _EGG_MOD_FILESYS_FILEDB3_H */
 
195
#endif /* _EGG_MOD_FILESYS_FILEDB3_H */