]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_torrent.h
1 #ifndef CEPH_RGW_TORRENT_H
2 #define CEPH_RGW_TORRENT_H
9 #include "common/ceph_time.h"
11 #include "rgw_rados.h"
12 #include "rgw_common.h"
14 using ceph::crypto::SHA1
;
18 #define RGW_OBJ_TORRENT "rgw.torrent"
20 #define ANNOUNCE "announce"
21 #define ANNOUNCE_LIST "announce-list"
22 #define COMMENT "comment"
23 #define CREATED_BY "created by"
24 #define CREATION_DATE "creation date"
25 #define ENCODING "encoding"
26 #define LENGTH "length"
28 #define PIECE_LENGTH "piece length"
29 #define PIECES "pieces"
30 #define INFO_PIECES "info"
31 #define GET_TORRENT "torrent"
40 void bencode_dict(bufferlist
& bl
) { bl
.append('d'); }
41 void bencode_list(bufferlist
& bl
) { bl
.append('l'); }
42 void bencode_end(bufferlist
& bl
) { bl
.append('e'); }
45 void bencode(int value
, bufferlist
& bl
)
48 char info
[100] = { 0 };
49 sprintf(info
, "%d", value
);
50 bl
.append(info
, strlen(info
));
55 void bencode(const std::string
& str
, bufferlist
& bl
)
61 void bencode(const std::string
& key
, int value
, bufferlist
& bl
)
68 void bencode(const std::string
& key
, const std::string
& value
, bufferlist
& bl
)
75 void bencode_key(const std::string
& key
, bufferlist
& bl
)
77 int len
= key
.length();
78 char info
[100] = { 0 };
79 sprintf(info
, "%d:", len
);
80 bl
.append(info
, strlen(info
));
81 bl
.append(key
.c_str(), len
);
85 /* torrent file struct */
91 int piece_length
; // each piece length
92 bufferlist sha1_bl
; // save sha1
93 string name
; // file name
94 off_t len
; // file total bytes
97 string announce
; // tracker
98 string origin
; // origin
99 time_t create_date
; // time of the file created
100 string comment
; // comment
101 string create_by
; // app name and version
102 string encoding
; // if encode use gbk rather than gtf-8 use this field
103 uint64_t sha_len
; // sha1 length
104 bool is_torrent
; // flag
105 bufferlist bl
; // bufflist ready to send
111 TorrentBencode dencode
;
117 void init(struct req_state
*p_req
, RGWRados
*p_store
);
118 void get_torrent_file(int &op_ret
, RGWRados::Object::Read
&read_op
,
119 uint64_t &total_len
, bufferlist
&bl_data
, rgw_obj
&obj
);
121 off_t
get_data_len();
124 void set_create_date(ceph::real_time
& value
);
125 void set_info_name(const string
& value
);
126 void update(bufferlist
&bl
);
132 void set_exist(bool exist
);
133 void set_info_pieces(char *buff
);
134 void sha1(SHA1
*h
, bufferlist
&bl
, off_t bl_len
);
135 int save_torrent_file();
137 #endif /* CEPH_RGW_TORRENT_H */