00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __PROTOCOL_H
00018
#define __PROTOCOL_H
00019
00020
00021
00032
00033
00034
00035
00036
00037
00038
#ifndef LIBGIFTPROTO_EXPORT
00039
# define LIBGIFTPROTO_EXPORT
00040
#endif
00041
00042
#ifndef GIFTD_EXPORT
00043
# define GIFTD_EXPORT
00044
#endif
00045
00046
00047
00048
00049
00050
00051
#ifdef GIFT_PLUGIN
00052
# ifdef _MSC_VER
00053
# define GIFT_PLUGIN_EXPORT __declspec(dllexport)
00054
# else
00055
# define GIFT_PLUGIN_EXPORT
00056
# endif
00057
#endif
00058
00059
00060
00061
struct protocol;
00062
struct if_event;
00063
struct file_share;
00064
00065
#include "transfer_api.h"
00066
#include "if_event_api.h"
00067
00068
#include "share_hash.h"
00069
00070
00071
00072
00073
#include "protocol_ver.h"
00074
00075
00076
00081 typedef struct protocol
00082 {
00083
00089 char *
name;
00090 char *
version_str;
00092 void *
udata;
00100 void *
handle;
00106 Dataset *
hashes;
00119 Dataset *
features;
00120
00121
00146 BOOL (*init) (
struct protocol *p);
00147
00148
00149
#define FILE_LINE_FUNC __FILE__,__LINE__,__PRETTY_FUNCTION__
00150
00151
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
00152
# define DBGFN(p,...) trace(p,FILE_LINE_FUNC,__VA_ARGS__)
00153
# define DBGSOCK(p,c,...) tracesock(p,c,FILE_LINE_FUNC,__VA_ARGS__)
00154
#elif defined (__GNUC__)
00155
# define DBGFN(p,fmt...) trace(p,FILE_LINE_FUNC,fmt)
00156
# define DBGSOCK(p,c,fmt...) tracesock(p,c,FILE_LINE_FUNC,fmt)
00157
#else
00158
# define DBGFN dbg
00159
# define DBGSOCK dbgsock
00160
#endif
00161
00166 int (*trace) (
struct protocol *p,
char *file,
int line,
char *func,
00167
char *fmt, ...);
00168
00174 int (*tracesock) (
struct protocol *p, TCPC *c,
00175
char *file,
int line,
char *func,
char *fmt, ...);
00176
00182 int (*dbg) (
struct protocol *p,
char *fmt, ...);
00183
00187 int (*dbgsock) (
struct protocol *p, TCPC *c,
char *fmt, ...);
00188
00192 int (*warn) (
struct protocol *p,
char *fmt, ...);
00193
00197 int (*err) (
struct protocol *p,
char *fmt, ...);
00198
00199
#define HASH_PRIMARY 0x01
00200
#define HASH_SECONDARY 0x02
00201
#define HASH_LOCAL 0x04
00202
00223 BOOL (*hash_handler) (
struct protocol *p,
const char *type,
int opt,
00224 HashFn algofn, HashDspFn dspfn);
00225
00241 void (*support) (
struct protocol *p,
const char *feature, BOOL spt);
00242
00243 #define SHARE_LOOKUP_HASH (1)
00244 #define SHARE_LOOKUP_HPATH (2)
00245 #define SHARE_LOOKUP_PATH (3)
00266
struct file_share* (*share_lookup) (struct protocol *p, int command, ...);
00267
00268
#define UPLOAD_AUTH_ALLOW (0)
00269
#define UPLOAD_AUTH_STALE (-1)
00270
#define UPLOAD_AUTH_MAX (-2)
00271
#define UPLOAD_AUTH_MAX_PERUSER (-3)
00272
#define UPLOAD_AUTH_NOTSHARED (-4)
00273
#define UPLOAD_AUTH_HIDDEN (-5)
00274
00331 int (*upload_auth) (
struct protocol *p,
const char *user,
00332
struct file_share *share,
upload_auth_t *auth_info);
00333
00374
struct transfer* (*upload_start) (
struct protocol *p,
00375
struct chunk **
chunk,
00376
const char *user,
00377
struct file_share *share,
00378 off_t start, off_t stop);
00379
00394 void (*chunk_write) (
struct protocol *p,
00395
struct transfer *transfer,
00396
struct chunk *
chunk,
struct source *
source,
00397
unsigned char *data, size_t len);
00398
00410 void (*source_abort) (
struct protocol *p,
00411
struct transfer *transfer,
struct source *
source);
00412
00422 void (*source_status) (
struct protocol *p,
struct source *
source,
00423
enum source_status klass,
const char *disptxt);
00424
00444 void (*search_result) (
struct protocol *p,
struct if_event *event,
00445
char *user,
char *node,
char *href,
00446
unsigned int avail,
struct file_share *file);
00447
00456 void (*search_complete) (
struct protocol *p,
struct if_event *event);
00457
00466 void (*message) (
struct protocol *p,
char *message);
00467
00468
00487 BOOL (*start) (
struct protocol *p);
00488
00494 void (*destroy) (
struct protocol *p);
00495
00508 BOOL (*download_start) (
struct protocol *p,
00509
struct transfer *transfer,
00510
struct chunk *
chunk,
struct source *
source);
00511
00527 void (*download_stop) (
struct protocol *p,
00528
struct transfer *transfer,
00529
struct chunk *
chunk,
struct source *
source,
00530
int complete);
00531
00535 void (*upload_stop) (
struct protocol *p,
00536
struct transfer *transfer,
00537
struct chunk *
chunk,
struct source *
source);
00538
00549 void (*upload_avail) (
struct protocol *p,
unsigned long avail);
00550
00564 BOOL (*chunk_suspend) (
struct protocol *p,
00565
struct transfer *transfer,
00566
struct chunk *
chunk,
struct source *
source);
00567
00571 BOOL (*chunk_resume) (
struct protocol *p,
00572
struct transfer *transfer,
00573
struct chunk *
chunk,
struct source *
source);
00574
00586 BOOL (*source_add) (
struct protocol *p,
00587
struct transfer *transfer,
struct source *
source);
00588
00595 void (*source_remove) (
struct protocol *p,
00596
struct transfer *transfer,
struct source *
source);
00597
00615 BOOL (*search) (
struct protocol *p,
00616
struct if_event *event,
char *query,
char *exclude,
00617
char *realm, Dataset *meta);
00618
00631 BOOL (*browse) (
struct protocol *p,
00632
struct if_event *event,
char *user,
char *node);
00633
00646 BOOL (*locate) (
struct protocol *p,
00647
struct if_event *event,
char *htype,
char *hash);
00648
00655 void (*search_cancel) (
struct protocol *p,
struct if_event *event);
00656
00662
void* (*share_new) (
struct protocol *p,
struct file_share *file);
00663
00667 void (*share_free) (
struct protocol *p,
struct file_share *file,
00668
void *data);
00669
00679 BOOL (*share_add) (
struct protocol *p,
struct file_share *file,
void *data);
00680
00684 BOOL (*share_remove) (
struct protocol *p,
struct file_share *file,
00685
void *data);
00686
00697 void (*share_sync) (
struct protocol *p,
int begin);
00698
00705 void (*share_hide) (
struct protocol *p);
00706
00710 void (*share_show) (
struct protocol *p);
00711
00725 int (*stats) (
struct protocol *p,
00726
unsigned long *users,
unsigned long *files,
00727
double *size, Dataset **extra);
00728
00729
00747 int (*source_cmp) (
struct protocol *p,
struct source *a,
struct source *b);
00748
00754 int (*user_cmp) (
struct protocol *p,
const char *a,
const char *b);
00755 }
Protocol;
00756
00757
00758
00759 EXTERN_C_BEGIN
00760
00761
00762
00767 #define protocol_compat(p,dev_ver) \
00768
protocol_compat_ex(p,LIBGIFTPROTO_VERSION,dev_ver)
00769
00791 LIBGIFTPROTO_EXPORT
00792
int protocol_compat_ex (
Protocol *p, uint32_t link_ver, uint32_t dev_ver);
00793
00794
00795
00796 EXTERN_C_END
00797
00798
00799
00800
#endif