root/vowfsc/db.h

Revision 55, 4.8 kB (checked in by nlawren2, 5 months ago)

Committed, and dead

Line 
1 #pragma once
2
3 #include <postgresql/libpq-fe.h>
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include "xdelta3.h"
10
11 #define BUFFER_SIZE     1024
12
13 typedef struct file file_t;
14 struct file{
15 #define db_int( name)           int name;
16 #define db_long( name)          long name;
17 #define db_string( name )       char *name;
18 #include "file.db"
19 };
20
21 typedef struct dir dir_t;
22 struct dir{
23 #define db_int( name)           int name;
24 #define db_long( name)          long name;
25 #define db_string( name )       char *name;
26 #include "dir.db"
27 };
28
29 typedef struct stream stream_t;
30 struct stream{
31 #define db_int( name)           int name;
32 #define db_long( name)          long name;
33 #define db_string( name )       char *name;
34 #include "stream.db"
35 };
36
37
38 /* Given a file path, db_get_file_id splits it into
39  * a directory and a file name, normalizes the directory
40  * and then passes it onto the database to get the
41  * file_id as an integer.
42  */
43 int db_get_file_id( char *file_path ); // TESTED
44
45
46 /* Given a file id, db_get_file_max_revision queries the
47  * database to get the revision id of the most current
48  * file.
49  */
50 int db_get_file_max_revision( int file_id ); // TESTED
51
52
53 /* db_get_file returns a struct containing statistical
54  * data on the file.  To see the contents of the struct,
55  * look at the file.db file.
56  */
57 file_t *db_get_file( int file_id ); // TESTED
58 file_t *db_get_file_rev( int file_id, int revision_id ); // TESTED
59
60
61 /* db_get_file_data returns the undiffed data from
62  * revision given, or if no revision is given, it
63  * returns the data from the most current file.
64  */
65 char *db_get_file_data( int file_id ); // TESTED
66 char *db_get_file_rev_data( int file_id, int revision_id ); // TESTED
67
68
69 /* Permissions and/or other meta data is stored in
70  * the file's stream.  These functions work like
71  * db_get_file_data
72  */
73 stream_t *db_get_file_stream( int file_id );
74 stream_t *db_get_file_rev_stream( int file_id, int revision_id );
75
76
77 /* Looks first to see if the given stream exists, and
78  * returns it's stream id if it does.  If not, it creates
79  * a new stream and returns the new stream's id.
80  */
81 int db_create_stream( char *stream_name, char *stream );
82
83
84 /* Copies the file to a new reversion, and sets the delete flag
85  * in the new file.  It then returns the revision number of the
86  * new file.
87  */
88 int db_remove_file(int file_id); // TESTED
89 #define db_delete_file(file_id) db_remove_file(file_id)
90
91
92 /* This creates a blank file for writing.  If the file
93  * allready exists, then it removes the delete flag and
94  * revisions it. 
95  */
96 int db_create_file(char *file_path, int stream_id ); // TESTED
97
98
99 /* Branches a file by creating a new file based on a
100  * given revision and a file_id.  This is used for
101  * moving files to new directories, etc. 
102  *
103  * db_branch_file returns the file_id of the new
104  * file or NULL in the case of a failture.
105  */
106 int db_branch_file(int file_id, int revision_id, char *new_file_path );
107
108
109 /* For revisioning an existing file, this function
110  * modifies the data in an existing file given by
111  * file_id
112  */
113 int db_modify_file_data(int file_id, char *data, int data_len ); // TESTED
114
115
116 /* For changing the permissions on an existing file
117  * modifies the stream in an existing file given by
118  * file_id.  If either stream_name or stream are NULL,
119  * they will be replaced with the current values.
120  */
121 int db_modify_file_stream(int file_id, char *new_stream_name, char *new_stream );
122
123
124 /* Like db_get_file_id, db_get_dir_id returns the id
125  * of a given directory string by first normalizing it
126  * and then querying the database.
127  */
128 int db_get_dir_id( char *dir_name ); // TESTED
129
130
131 /* Given a directory id, db_get_dir_max_revision queries
132  * the database to get the revision id of the most current
133  * file.
134  */
135 int db_get_dir_max_revision( int dir_id );
136
137
138 /* db_get_dir returns a struct containing statistical
139  * data on the directory.  To see the contents of the
140  * struct, look at the dir.db file.
141  */
142 dir_t *db_get_dir( int dir_id ); // TESTED
143 dir_t *db_get_dir_rev( int dir_id, int revision_id );
144
145
146 /* Get subdirs and get files both return an array of
147  * either directories or files.  The length pointer
148  * returns the number of elements in the array.
149  */
150 dir_t *db_get_dir_subdirs( int dir_id, int *length );
151 file_t *db_get_dir_files( int dir_id, int *length );
152
153
154 /* Does what it says, creates a new directory.
155  * Returns the dir_id of the new directory or null in
156  * the case of a failture.
157  */
158 int db_create_dir( char *dir_path ); // TODO
159
160
161 /* Copies the directory entry and sets the delete flag
162  */
163 int db_remove_dif( int dir_id ); // TODO
164
165
166 /* db_init and db_destoy create and destroy connections
167  * to the database respectivly.  They are wrappers around
168  * the libpq functions and will return 0 on success and
169  * non-zero on failture.
170  */
171 int db_init(char *host, int port, char *dbname, char *username, char *password); // TESTED
172 int db_destroy(); // TESTED
173
174
175 /* Creates a new blank file system
176  */
177 int db_format_fs(); // TODO
178
Note: See TracBrowser for help on using the browser.