]> granicus.if.org Git - shadow/blob - lib/commonio.h
[svn-upgrade] Integrating new upstream version, shadow (20000902)
[shadow] / lib / commonio.h
1 /* $Id: commonio.h,v 1.6 2000/09/02 18:40:43 marekm Exp $ */
2
3 /*
4  * Linked list entry.
5  */
6 struct commonio_entry {
7         char *line;
8         void *eptr;  /* struct passwd, struct spwd, ... */
9         struct commonio_entry *prev, *next;
10         int changed:1;
11 };
12
13 /*
14  * Operations depending on database type: passwd, group, shadow etc.
15  */
16 struct commonio_ops {
17         /*
18          * Make a copy of the object (for example, struct passwd)
19          * and all strings pointed by it, in malloced memory.
20          */
21         void *(*dup)(const void *);
22
23         /*
24          * free() the object including any strings pointed by it.
25          */
26         void (*free)(void *);
27
28         /*
29          * Return the name of the object (for example, pw_name
30          * for struct passwd).
31          */
32         const char *(*getname)(const void *);
33
34         /*
35          * Parse a string, return object (in static area -
36          * should be copied using the dup operation above).
37          */
38         void *(*parse)(const char *);
39
40         /*
41          * Write the object to the file (this calls putpwent()
42          * for struct passwd, for example).
43          */
44         int (*put)(const void *, FILE *);
45
46         /*
47          * fgets and fputs (can be replaced by versions that
48          * understand line continuation conventions).
49          */
50         char *(*fgets)(char *, int, FILE *);
51         int (*fputs)(const char *, FILE *);
52 };
53
54 /*
55  * Database structure.
56  */
57 struct commonio_db {
58         /*
59          * Name of the data file.
60          */
61         char filename[1024];
62
63         /*
64          * Operations from above.
65          */
66         struct commonio_ops *ops;
67
68         /*
69          * Currently open file stream.
70          */
71         FILE *fp;
72
73         /*
74          * Head, tail, current position in linked list.
75          */
76         struct commonio_entry *head, *tail, *cursor;
77
78         /*
79          * Various flags.
80          */
81         int changed:1;
82         int isopen:1;
83         int locked:1;
84         int readonly:1;
85 };
86
87 extern int commonio_setname(struct commonio_db *, const char *);
88 extern int commonio_present(const struct commonio_db *);
89 extern int commonio_lock(struct commonio_db *);
90 extern int commonio_lock_nowait(struct commonio_db *);
91 extern int commonio_open(struct commonio_db *, int);
92 extern const void *commonio_locate(struct commonio_db *, const char *);
93 extern int commonio_update(struct commonio_db *, const void *);
94 extern int commonio_remove(struct commonio_db *, const char *);
95 extern int commonio_rewind(struct commonio_db *);
96 extern const void *commonio_next(struct commonio_db *);
97 extern int commonio_close(struct commonio_db *);
98 extern int commonio_unlock(struct commonio_db *);
99 extern void commonio_del_entry(struct commonio_db *, const struct commonio_entry *);
100