Changeset 38

Show
Ignore:
Timestamp:
11/09/07 17:22:02 (10 months ago)
Author:
nlawren2
Message:

Added more code, duh

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • vowfsc/Makefile

    r37 r38  
    22        @echo made $@ 
    33 
    4 db: db.c db.h file.db dir.db stream.db 
    5         gcc db.c -o db 
     4db: db.o 
     5        gcc db.o -o db 
    66 
    77xdelta: xdelta.o xdelta3.o 
    88        gcc xdelta.o xdelta3.o -o xdelta 
     9 
     10db.o: db.c db.h file.db dir.db stream.db 
     11        gcc db.c -c 
    912 
    1013xdelta3.o: xdelta3.c xdelta3.h xdelta3-cfgs.h xdelta3-list.h xdelta3-decode.h 
     
    1316xdelta.o: xdelta.c 
    1417        gcc xdelta.c -c 
     18 
     19clean: 
     20        rm *.o 
  • vowfsc/db.c

    r34 r38  
    149149 
    150150 
    151 file db_get_file( int file_id ){ 
    152         file stat; 
     151file_t db_get_file( int file_id ){ 
     152        file_t stat; 
    153153 
    154154        char *pq_request[BUFFER_SIZE]; 
     
    189189 
    190190 
    191 file db_get_file( int file_id, int revision ){ 
    192         file stat; 
     191file_t db_get_file( int file_id, int revision ){ 
     192        file_t stat; 
    193193 
    194194        char *pq_request[BUFFER_SIZE]; 
     
    341341 
    342342 
    343 dir db_get_dir( int dir_id ){ 
    344         dir stat; 
     343dir_t db_get_dir( int dir_id ){ 
     344        dir_t stat; 
    345345 
    346346        char *pq_request[BUFFER_SIZE]; 
     
    381381 
    382382 
    383 dir db_get_dir( int dir_id, int revision ){ 
    384         dir stat; 
     383dir_t db_get_dir( int dir_id, int revision ){ 
     384        dir_t stat; 
    385385 
    386386        char *pq_request[BUFFER_SIZE]; 
     
    459459 
    460460 
     461stream_t db_get_stream( int stream_id ){ 
     462        stream_t stat; 
     463 
     464        char *pq_request[BUFFER_SIZE]; 
     465        sprintf(pq_request,"SELECT * " 
     466                           "FROM streamectory " 
     467                           "WHERE streamectory_id = \'%i\'", 
     468                           stream_id); 
     469        PGresult *res=PQexec(pq_conn,pq_request); 
     470 
     471        if( NUM_FILE_FIELDS ){ 
     472                NUM_FILE_FIELDS = sizeof(stream_format)/4; 
     473 
     474                if( PQnfields(pq_data) != NUM_FILE_FIELDS ){ 
     475                        NUM_FILE_FIELDS = 0; 
     476                        return NULL; 
     477                } 
     478 
     479        // Fill stream_format with column numbers 
     480#define db(type, name)  stream_format.name = PQfnumber(pq_data, #name ); 
     481#define db_string(name) stream_format.name = PQfnumber(pq_data, #name ); 
     482#include "stream.db" 
     483        } 
     484 
     485        if( PQresultStatus(res) != PGRES_TUPLES_OK ) return NULL; 
     486         
     487        if( PQnfields(pq_data) != NUM_FILE_FIELDS ) return NULL; 
     488 
     489        // Fill stat 
     490#define db(type, name)  stat.name = *(type*)PQgetvalue(pq_data, /*row*/, stream_format.name ); 
     491#define db_string(name) stat.name = strdup(PQgetvalue(pq_data, /*row*/, stream_format.name )); 
     492#include "stream.db" 
     493         
     494        // Free the result 
     495        PQfreemem(res); 
     496 
     497        return stat; 
     498} 
     499 
     500 
     501stream_t db_get_stream( int stream_id, int revision ){ 
     502        stream_t stat; 
     503 
     504        char *pq_request[BUFFER_SIZE]; 
     505        sprintf(pq_request,"SELECT * " 
     506                           "FROM streamectory " 
     507                           "WHERE streamectory_id = \'%i\' " 
     508                           "AND revision_id = \'%i\'", 
     509                           stream_id, revision); 
     510        PGresult *res=PQexec(pq_conn,pq_request); 
     511 
     512        if( NUM_FILE_FIELDS ){ 
     513                NUM_FILE_FIELDS = sizeof(stream_format)/4; 
     514 
     515                if( PQnfields(pq_data) != NUM_FILE_FIELDS ){ 
     516                        NUM_FILE_FIELDS = 0; 
     517                        return NULL; 
     518                } 
     519 
     520        // Fill stream_format with column numbers 
     521#define db(type, name)  stream_format.name = PQfnumber(pq_data, #name ); 
     522#define db_string(name) stream_format.name = PQfnumber(pq_data, #name ); 
     523#include "stream.db" 
     524        } 
     525 
     526        if( PQresultStatus(res) != PGRES_TUPLES_OK ) return NULL; 
     527         
     528        if( PQnfields(pq_data) != NUM_FILE_FIELDS ) return NULL; 
     529 
     530        // Fill stat 
     531#define db(type, name)  stat.name = *(type*)PQgetvalue(pq_data, 0, stream_format.name ); 
     532#define db_string(name) stat.name = strdup(PQgetvalue(pq_data, 0, stream_format.name )); 
     533#include "stream.db" 
     534         
     535        // Free the result 
     536        PQfreemem(res); 
     537 
     538        return stat; 
     539} 
     540 
     541 
  • vowfsc/db.h

    r37 r38  
    1313#define false   0 
    1414 
    15 typedef struct file file
     15typedef struct file file_t
    1616struct file{ 
    1717#define db( type, name) type name; 
     
    2121 
    2222 
    23 typedef struct dir dir
    24 struct dir
     23typedef struct dir dir_t
     24struct dir_t
    2525#define db( type, name ) type name; 
    2626#define db_string( name ) char *name; 
     
    2828}; 
    2929 
    30 typedef struct stream stream
     30typedef struct stream stream_t
    3131struct stream{ 
    3232#define db( type, name ) type name; 
     
    3434#include "stream.db" 
    3535}; 
     36 
    3637 
    3738/* Given a file path, db_get_file_id splits it into 
     
    5455 * look at the file.db file. 
    5556 */ 
    56 file db_get_file( int file_id ); 
    57 file db_get_file( int file_id, int revision ); 
     57file_t db_get_file( int file_id ); 
     58file_t db_get_file( int file_id, int revision ); 
    5859 
    5960/* db_get_file_data returns the undiffed data from  
     
    6970 * db_get_file_data 
    7071 */ 
    71 char *db_get_file_stream( int file_id ); // TODO 
    72 char *db_get_file_stream( int file_id, int revision ); // TODO 
     72char *db_get_file_stream( int file_id ); 
     73char *db_get_file_stream( int file_id, int revision ); 
    7374 
    7475/* Looks first to see if the given stream exists, and 
     
    8788 * revisions it.   
    8889 */ 
    89 int db_create_file(char *file_name, char *file_path, stream data); // TODO 
     90int db_create_file(char *file_name, char *file_path, stream_t stream); // TODO 
    9091 
    9192 
     
    113114 * file_id.   
    114115 */ 
    115 int db_modify_file_stream(int file_id, stream data); // TODO 
     116int db_modify_file_stream(int file_id, stream_t stream); // TODO 
    116117 
    117118 
     
    134135 * struct, look at the dir.db file. 
    135136 */ 
    136 dir db_get_dir( int dir_id ); 
    137 dir db_get_dir( int dir_id, int revision ); 
     137dir_t db_get_dir( int dir_id ); 
     138dir_t db_get_dir( int dir_id, int revision ); 
    138139 
    139140