Module: Kernel

Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#pac(rb_pacfile_name, rb_url) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'ext/pachook/pachook.c', line 53

VALUE rb_pac(VALUE self, VALUE rb_pacfile_name, VALUE rb_url) {
    char *pacfile_name = StringValueCStr(rb_pacfile_name);
    char *url = StringValueCStr(rb_url);
    char *host = get_host_from_url(url);

    if(!pacparser_init()) {
        rb_raise(pachook_InitializeFailureError, "%s:%d could not initialize parser\n", __FILE__, __LINE__);
    }

    if(!pacparser_parse_pac_file(pacfile_name)) {
        pacparser_cleanup();
        rb_raise(pachook_PacParseFailureError, "%s:%d could not parse pac file\n", __FILE__, __LINE__);
    }

    char *proxy = pacparser_find_proxy(url, host);

    if(proxy == NULL) {
        rb_raise(pachook_DiscoveryFailureError, "%s:%d problem in finding proxy for %s\n", __FILE__, __LINE__, url);
        pacparser_cleanup();
    }

    pacparser_cleanup();
    return rb_str_new_cstr(proxy);
}