fargo 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/fargo/base32.c +61 -0
- data/ext/fargo/base32.h +16 -0
- data/ext/fargo/extconf.rb +8 -0
- data/ext/fargo/fargo_tth.c +34 -0
- data/ext/fargo/sboxes.c +515 -0
- data/ext/fargo/tiger.c +245 -0
- data/ext/fargo/tiger.h +41 -0
- data/ext/fargo/tigertree.c +184 -0
- data/ext/fargo/tigertree.h +48 -0
- data/ext/fargo/tth.c +100 -0
- data/ext/fargo/tth.h +18 -0
- data/lib/fargo/client.rb +47 -118
- data/lib/fargo/protocol/dc.rb +52 -0
- data/lib/fargo/{connection → protocol}/download.rb +56 -88
- data/lib/fargo/protocol/hub.rb +81 -0
- data/lib/fargo/search.rb +21 -16
- data/lib/fargo/search_result.rb +6 -6
- data/lib/fargo/supports/chat.rb +10 -7
- data/lib/fargo/supports/downloads.rb +73 -117
- data/lib/fargo/supports/file_list.rb +21 -10
- data/lib/fargo/supports/nick_list.rb +23 -14
- data/lib/fargo/supports/persistence.rb +28 -23
- data/lib/fargo/supports/searches.rb +30 -9
- data/lib/fargo/supports/timeout.rb +8 -5
- data/lib/fargo/supports/uploads.rb +5 -5
- data/lib/fargo/utils.rb +5 -4
- data/lib/fargo/version.rb +1 -1
- data/lib/fargo.rb +8 -10
- metadata +41 -19
- data/lib/fargo/connection/base.rb +0 -126
- data/lib/fargo/connection/hub.rb +0 -120
- data/lib/fargo/connection/search.rb +0 -19
- data/lib/fargo/connection/upload.rb +0 -85
- data/lib/fargo/publisher.rb +0 -42
- data/lib/fargo/server.rb +0 -52
data/ext/fargo/base32.c
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
|
3
|
+
#include "base32.h"
|
4
|
+
|
5
|
+
char base32_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
6
|
+
|
7
|
+
char* base32_encode(const unsigned char* buffer, int len)
|
8
|
+
{
|
9
|
+
unsigned char* digest = NULL;
|
10
|
+
if (len > 0) {
|
11
|
+
int i, j = 0;
|
12
|
+
int bits_remain = 0;
|
13
|
+
unsigned short value = 0;
|
14
|
+
unsigned long digest_len = len*8;
|
15
|
+
digest_len = 1 + ((digest_len % 5) == 0 ? (digest_len / 5) : (digest_len / 5) + 1);
|
16
|
+
|
17
|
+
digest = (unsigned char*)malloc(digest_len);
|
18
|
+
if (digest != NULL) {
|
19
|
+
for (i = 0; i < len; i++) {
|
20
|
+
value = (value << 8) | buffer[i];
|
21
|
+
bits_remain += 8;
|
22
|
+
while (bits_remain > 5 && j < 1023) {
|
23
|
+
int idx = (value >> (bits_remain-5)) & 0x1F;
|
24
|
+
digest[j++] = base32_alphabet[idx];
|
25
|
+
bits_remain -= 5;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
if (bits_remain > 0) {
|
29
|
+
int idx = (value << (5-bits_remain)) & 0x1F;
|
30
|
+
digest[j++] = base32_alphabet[idx];
|
31
|
+
}
|
32
|
+
digest[j] = '\0';
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return digest;
|
36
|
+
}
|
37
|
+
|
38
|
+
#if 0
|
39
|
+
char* base32_decode(const unsigned char* buffer, int len)
|
40
|
+
{
|
41
|
+
int i, j = 0;
|
42
|
+
int bits_remain = 0;
|
43
|
+
unsigned short value = 0;
|
44
|
+
|
45
|
+
for (i = 0; i < len; i++) {
|
46
|
+
value |= (buffer[i] << bits_remain);
|
47
|
+
bits_remain += 8;
|
48
|
+
while (bits_remain > 5 && j < 1023) {
|
49
|
+
base32_digest[j++] = (value & 0x1F) < 26 ? 'A'+(value & 0x1F) : '2' + (value & 0x1F);
|
50
|
+
value >>= 5;
|
51
|
+
bits_remain -= 5;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
if (bits_remain > 0) {
|
55
|
+
base32_digest[j++] = (value & 0x1F) < 26 ? 'A'+(value & 0x1F) : '2' + (value & 0x1F);
|
56
|
+
}
|
57
|
+
base32_digest[j] = '\0';
|
58
|
+
return base32_digest;
|
59
|
+
}
|
60
|
+
|
61
|
+
#endif
|
data/ext/fargo/base32.h
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#ifndef __BASE32_H
|
2
|
+
#define __BASE32_H
|
3
|
+
|
4
|
+
#if defined(__cplusplus)
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
// user must call free() funtion on pointer returned from these functions
|
9
|
+
|
10
|
+
char* base32_encode(const unsigned char* in, int inlen);
|
11
|
+
|
12
|
+
#if defined(__cplusplus)
|
13
|
+
}
|
14
|
+
#endif
|
15
|
+
|
16
|
+
#endif // ifndef __BASE32_H
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include "tth.h"
|
4
|
+
|
5
|
+
#ifndef RUBY_19
|
6
|
+
# define RSTRING_LEN(s) (RSTRING(s)->len)
|
7
|
+
# define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
8
|
+
# define RARRAY_LEN(s) (RARRAY(s)->len)
|
9
|
+
# define RARRAY_PTR(s) (RARRAY(s)->ptr)
|
10
|
+
#endif
|
11
|
+
|
12
|
+
VALUE rb_tth_file(VALUE self, VALUE filename) {
|
13
|
+
char *file = RSTRING_PTR(filename);
|
14
|
+
|
15
|
+
char* tthl = NULL;
|
16
|
+
size_t tthl_size;
|
17
|
+
char* hash = tth(file, &tthl, &tthl_size);
|
18
|
+
if (tthl != NULL) {
|
19
|
+
free(tthl);
|
20
|
+
}
|
21
|
+
|
22
|
+
if (hash != NULL) {
|
23
|
+
return rb_str_new(hash, strlen(hash));
|
24
|
+
} else {
|
25
|
+
return Qnil;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
Init_tth() {
|
30
|
+
VALUE cFargo = rb_define_module("Fargo");
|
31
|
+
VALUE cTTH = rb_define_module_under(cFargo, "TTH");
|
32
|
+
|
33
|
+
rb_define_method(cTTH, "file_tth", rb_tth_file, 1);
|
34
|
+
}
|