pachook 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/pachook/extconf.rb +16 -0
- data/ext/pachook/pachook.c +88 -0
- data/lib/pachook.rb +1 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f46099f4bd430f68c3c6678416d34eaaa330cbb
|
4
|
+
data.tar.gz: 57c3d7b14189c6ef694ac52cdcb2cd8619f22424
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 919d53bcf3eede7df9c509bba4899a18d743b30929dfb5acb3dc608089ae8bc73e37f016ba28701e29b0ef6245a5b14cbaaf7565de2f6054f5721c24c5199e1c
|
7
|
+
data.tar.gz: f3d1c05823ed9ac405f2fc433066963c54d7941f4140f4708777c48e3a187c3c56b6067b9176e14d31421c751c9811f36d640fd153f9ce51ffaa9d16489e95c0
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
[
|
4
|
+
'pacparser_init', 'pacparser_parse_pac_file', 'pacparser_cleanup', 'pacparser_find_proxy'
|
5
|
+
].each { |sym| abort("missing symbol #{sym}") unless find_library('pacparser', sym) }
|
6
|
+
|
7
|
+
[
|
8
|
+
'ruby.h', 'pacparser.h', 'stdio.h', 'stdlib.h',
|
9
|
+
'string.h', 'unistd.h'
|
10
|
+
].each { |header| abort("missing library #{header}") unless have_header(header) }
|
11
|
+
|
12
|
+
[
|
13
|
+
'strdup'
|
14
|
+
].each { |func| abort("missing #{func}\(\)") unless have_func(func) }
|
15
|
+
|
16
|
+
create_makefile('pachook/pachook')
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <pacparser.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <string.h>
|
6
|
+
#include <unistd.h>
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Module handle
|
10
|
+
*/
|
11
|
+
|
12
|
+
static VALUE pachook_module;
|
13
|
+
|
14
|
+
/*
|
15
|
+
* All exceptions for this module
|
16
|
+
*/
|
17
|
+
|
18
|
+
static VALUE pachook_UrlError;
|
19
|
+
static VALUE pachook_InitializeFailureError;
|
20
|
+
static VALUE pachook_PacParseFailureError;
|
21
|
+
static VALUE pachook_DiscoveryFailureError;
|
22
|
+
|
23
|
+
/*
|
24
|
+
* General utilities
|
25
|
+
*/
|
26
|
+
|
27
|
+
char *get_host_from_url(const char *orig_url) {
|
28
|
+
char *copy_url = strdup(orig_url);
|
29
|
+
|
30
|
+
while(*copy_url != ':' && *copy_url != '\0') {
|
31
|
+
++copy_url;
|
32
|
+
}
|
33
|
+
|
34
|
+
if(copy_url[0] == '\0' || copy_url[1] != '/' || copy_url[2] != '/') {
|
35
|
+
rb_raise(pachook_UrlError, "%s:%d not a proper URL\n", __FILE__, __LINE__);
|
36
|
+
}
|
37
|
+
|
38
|
+
copy_url += 3;
|
39
|
+
char *host = copy_url;
|
40
|
+
|
41
|
+
if(*copy_url == '\0' || *copy_url == '/' || *copy_url == ':') {
|
42
|
+
rb_raise(pachook_UrlError, "%s:%d not a proper URL\n", __FILE__, __LINE__);
|
43
|
+
}
|
44
|
+
|
45
|
+
while(*copy_url != '/' && *copy_url != ':' && *copy_url != '\0') {
|
46
|
+
++copy_url;
|
47
|
+
}
|
48
|
+
|
49
|
+
*copy_url = '\0';
|
50
|
+
return host;
|
51
|
+
}
|
52
|
+
|
53
|
+
VALUE rb_pac(VALUE self, VALUE rb_pacfile_name, VALUE rb_url) {
|
54
|
+
char *pacfile_name = StringValueCStr(rb_pacfile_name);
|
55
|
+
char *url = StringValueCStr(rb_url);
|
56
|
+
char *host = get_host_from_url(url);
|
57
|
+
|
58
|
+
if(!pacparser_init()) {
|
59
|
+
rb_raise(pachook_InitializeFailureError, "%s:%d could not initialize parser\n", __FILE__, __LINE__);
|
60
|
+
}
|
61
|
+
|
62
|
+
if(!pacparser_parse_pac_file(pacfile_name)) {
|
63
|
+
pacparser_cleanup();
|
64
|
+
rb_raise(pachook_PacParseFailureError, "%s:%d could not parse pac file\n", __FILE__, __LINE__);
|
65
|
+
}
|
66
|
+
|
67
|
+
char *proxy = pacparser_find_proxy(url, host);
|
68
|
+
|
69
|
+
if(proxy == NULL) {
|
70
|
+
rb_raise(pachook_DiscoveryFailureError, "%s:%d problem in finding proxy for %s\n", __FILE__, __LINE__, url);
|
71
|
+
pacparser_cleanup();
|
72
|
+
}
|
73
|
+
|
74
|
+
pacparser_cleanup();
|
75
|
+
return rb_str_new_cstr(proxy);
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
void Init_pachook() {
|
80
|
+
pachook_module = rb_define_module("pachook");
|
81
|
+
|
82
|
+
pachook_UrlError = rb_define_class_under(pachook_module, "UrlError", rb_eStandardError);
|
83
|
+
pachook_InitializeFailureError = rb_define_class_under(pachook_module, "InitializeFailureError", rb_eStandardError);
|
84
|
+
pachook_PacParseFailureError = rb_define_class_under(pachook_module, "PacParseFailureError", rb_eStandardError);
|
85
|
+
pachook_DiscoveryFailureError = rb_define_class_under(pachook_module, "DiscoveryFailureError", rb_eStandardError);
|
86
|
+
|
87
|
+
rb_define_global_function("pac", rb_pac, 2);
|
88
|
+
}
|
data/lib/pachook.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'pachook/pachook'
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pachook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicholas Chambers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A ruby gem for hooking into PAC and javascript implementations
|
14
|
+
email: nchambers@spookyinternet.com
|
15
|
+
executables: []
|
16
|
+
extensions:
|
17
|
+
- ext/pachook/extconf.rb
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ext/pachook/extconf.rb
|
21
|
+
- ext/pachook/pachook.c
|
22
|
+
- lib/pachook.rb
|
23
|
+
homepage: http://spookypac.com/
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message: Thanks for installing!
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.4.8
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: PAC js hook
|
47
|
+
test_files: []
|