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{0}; // 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
107 struct req_state *s{nullptr};
108 RGWRados *store{nullptr};
111 TorrentBencode dencode;
117 void init(struct req_state *p_req, RGWRados *p_store);
118 int get_torrent_file(RGWRados::Object::Read &read_op,
120 ceph::bufferlist &bl_data,
123 off_t get_data_len();
126 void set_create_date(ceph::real_time& value);
127 void set_info_name(const string& value);
128 void update(bufferlist &bl);
134 void set_exist(bool exist);
135 void set_info_pieces(char *buff);
136 void sha1(SHA1 *h, bufferlist &bl, off_t bl_len);
137 int save_torrent_file();
139 #endif /* CEPH_RGW_TORRENT_H */