rhack 0.4.1 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +2 -5
  3. data/LICENSE +19 -15
  4. data/README.md +66 -26
  5. data/Rakefile +42 -31
  6. data/config/cacert.pem +3895 -0
  7. data/config/rhack.yml.template +40 -0
  8. data/ext/curb-original/curb_config.h +3 -0
  9. data/ext/curb-original/curb_easy.c +3 -54
  10. data/ext/curb-original/curb_multi.c +69 -140
  11. data/ext/curb/curb_multi.c +1 -1
  12. data/lib/rhack.rb +82 -12
  13. data/lib/rhack/cookie.rb +49 -0
  14. data/lib/rhack/curl.rb +6 -0
  15. data/lib/{extensions/curb.rb → rhack/curl/easy.rb} +26 -48
  16. data/lib/rhack/curl/global.rb +175 -0
  17. data/lib/rhack/curl/itt.rb +11 -0
  18. data/lib/rhack/curl/multi.rb +37 -0
  19. data/lib/rhack/curl/post_field.rb +20 -0
  20. data/lib/rhack/curl/response.rb +91 -0
  21. data/lib/rhack/dl.rb +308 -0
  22. data/lib/rhack/frame.rb +316 -0
  23. data/lib/{extensions → rhack/js}/browser/env.js +0 -0
  24. data/lib/{extensions → rhack/js}/browser/jquery.js +0 -0
  25. data/lib/{extensions → rhack/js}/browser/xmlsax.js +0 -0
  26. data/lib/{extensions → rhack/js}/browser/xmlw3cdom_1.js +0 -0
  27. data/lib/{extensions → rhack/js}/browser/xmlw3cdom_2.js +0 -0
  28. data/lib/rhack/js/johnson.rb +71 -0
  29. data/lib/rhack/page.rb +263 -0
  30. data/lib/rhack/proxy.rb +3 -0
  31. data/lib/rhack/proxy/checker.rb +1 -1
  32. data/lib/rhack/scout.rb +342 -0
  33. data/lib/rhack/scout_squad.rb +98 -0
  34. data/lib/rhack/services.rb +1 -464
  35. data/lib/rhack/services/base.rb +59 -0
  36. data/lib/rhack/services/examples.rb +423 -0
  37. data/lib/rhack/version.rb +3 -0
  38. data/lib/rhack_in.rb +3 -2
  39. data/rhack.gemspec +28 -0
  40. metadata +104 -85
  41. data/.gemtest +0 -0
  42. data/Gemfile.lock +0 -23
  43. data/Manifest.txt +0 -60
  44. data/ext/curb/Makefile +0 -217
  45. data/lib/cache.rb +0 -44
  46. data/lib/curl-global.rb +0 -164
  47. data/lib/extensions/declarative.rb +0 -153
  48. data/lib/extensions/johnson.rb +0 -63
  49. data/lib/frame.rb +0 -848
  50. data/lib/init.rb +0 -49
  51. data/lib/rhack.yml.template +0 -19
  52. data/lib/scout.rb +0 -589
  53. data/lib/words.rb +0 -25
@@ -0,0 +1,40 @@
1
+ # By default, Scout uses randomly chosen ua (string from specified fiel)
2
+ # for User-Agent header
3
+ useragents:
4
+ desktop: config/uas.txt
5
+ mobile: config/uas.mobile.txt
6
+
7
+ # Options for RMTools::Logger. The logger will be initialized as RHACK::L constant
8
+ logger:
9
+ :out: log/rhack.log
10
+ :color_log: true
11
+
12
+ scout:
13
+ timeout: 60
14
+ # Curl::Error subclasses names for <domain> that will retrigger Scout#load!
15
+ # By default an error will keep Scout from having request done
16
+ retry:
17
+ example.com:
18
+ - TimeoutError
19
+ # Path to cacert needed to use SSL.
20
+ # Defaults ("") to that of http://curl.haxx.se/ca/cacert.pem being stored next to this file
21
+ cacert: ""
22
+
23
+ # Defaults to a file @ RAILS_PATH/config/RAILS_ENV.yml
24
+ # Rhack is intended to use a database only for caching,
25
+ # so I've came to a conclusion that Redis is the most suitable choice
26
+ # redis.conf can be generated using `rake redis:config`
27
+ # Delete this block to disable Redis connection at all
28
+ db:
29
+ redis:
30
+ configfilename: config/redis.conf
31
+ socket: tmp/sockets/redis.socket
32
+ port: 0
33
+ hostname: localhost
34
+ dbfilename: db/redis-dump.rdb
35
+ db: 0
36
+ save:
37
+ # "run BGSAVE every minute if anything have changed"
38
+ - 60 1
39
+ # You can change it to whatever you want and just use Redis#bgsave before exit Ruby
40
+
@@ -231,5 +231,8 @@
231
231
  #define HAVE_CURLOPT_NEW_DIRECTORY_PERMS 1
232
232
  #define HAVE_CURLOPT_TELNETOPTIONS 1
233
233
  #define HAVE_CURLE_OBSOLETE 1
234
+ #define HAVE_RUBY19_HASH 1
235
+ #define HAVE_RUBY19_ST_H 1
234
236
  #define HAVE_CURL_EASY_ESCAPE 1
237
+ #define HAVE_RB_THREAD_BLOCKING_REGION 1
235
238
  #endif
@@ -211,10 +211,6 @@ static void ruby_curl_easy_free(ruby_curl_easy *rbce) {
211
211
  if (rbce->curl) {
212
212
  curl_easy_cleanup(rbce->curl);
213
213
  }
214
-
215
- if (rbce->first) {
216
- curl_formfree(rbce->first);
217
- }
218
214
  }
219
215
 
220
216
  void curl_easy_free(ruby_curl_easy *rbce) {
@@ -705,15 +701,11 @@ static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
705
701
  Data_Get_Struct(self, ruby_curl_easy, rbce);
706
702
 
707
703
  curl = rbce->curl;
708
- if (rbce->first) {
709
- curl_formfree(rbce->first);
710
- rbce->first = NULL;
711
- rbce->last = NULL;
712
- }
713
- rbce->multipart_form_post = 0;
704
+
714
705
  if ( post_body == Qnil ) {
715
706
  //rbce->postdata_buffer = Qnil;
716
- rb_easy_del("postdata_buffer");
707
+ rb_easy_del("postdata_buffer");
708
+
717
709
  } else {
718
710
  if (rb_type(post_body) == T_STRING) {
719
711
  data = StringValuePtr(post_body);
@@ -742,42 +734,6 @@ static VALUE ruby_curl_easy_post_body_set(VALUE self, VALUE post_body) {
742
734
 
743
735
  return Qnil;
744
736
  }
745
- static VALUE ruby_curl_easy_multipart_post_body_set(VALUE self, VALUE ary) {
746
- ruby_curl_easy *rbce;
747
- CURL *curl;
748
- int i;
749
-
750
- Data_Get_Struct(self, ruby_curl_easy, rbce);
751
- curl = rbce->curl;
752
- if (rbce->first) {
753
- curl_formfree(rbce->first);
754
- rbce->first = NULL;
755
- rbce->last = NULL;
756
- }
757
-
758
- // Make the multipart form
759
- rbce->multipart_form_post = 1;
760
- for (i=0; i<RARRAY_LEN(ary); i++) {
761
- if (rb_obj_is_instance_of(RARRAY_PTR(ary)[i], cCurlPostField)) {
762
- append_to_form(RARRAY_PTR(ary)[i], &(rbce->first), &(rbce->last));
763
- }
764
- else {
765
- if (rbce->first) {
766
- curl_formfree(rbce->first);
767
- rbce->first = NULL;
768
- rbce->last = NULL;
769
- }
770
- rb_raise(eCurlErrInvalidPostField, "You must use only PostFields with multipart form posts");
771
- return Qnil;
772
- }
773
- }
774
- //rbce->postdata_buffer = ary;
775
- rb_easy_set("postdata_buffer", post_body);
776
-
777
- curl_easy_setopt(curl, CURLOPT_POST, 0);
778
- curl_easy_setopt(curl, CURLOPT_HTTPPOST, rbce->first);
779
- return Qnil;
780
- }
781
737
 
782
738
  /*
783
739
  * call-seq:
@@ -2401,12 +2357,6 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
2401
2357
  }
2402
2358
  }
2403
2359
  }
2404
- static VALUE ruby_curl_easy_set_method_get(VALUE self, VALUE onoff) {
2405
- ruby_curl_easy *rbce;
2406
- Data_Get_Struct(self, ruby_curl_easy, rbce);
2407
- curl_easy_setopt(rbce->curl, CURLOPT_HTTPGET, RTEST(onoff));
2408
- return onoff;
2409
- }
2410
2360
 
2411
2361
  /*
2412
2362
  * call-seq:
@@ -3315,7 +3265,6 @@ void init_curb_easy() {
3315
3265
  rb_define_method(cCurlEasy, "encoding", ruby_curl_easy_encoding_get, 0);
3316
3266
  rb_define_method(cCurlEasy, "useragent=", ruby_curl_easy_useragent_set, 1);
3317
3267
  rb_define_method(cCurlEasy, "useragent", ruby_curl_easy_useragent_get, 0);
3318
- rb_define_method(cCurlEasy, "multipart_post_body=", ruby_curl_easy_multipart_post_body_set, 1);
3319
3268
  rb_define_method(cCurlEasy, "post_body=", ruby_curl_easy_post_body_set, 1);
3320
3269
  rb_define_method(cCurlEasy, "post_body", ruby_curl_easy_post_body_get, 0);
3321
3270
  rb_define_method(cCurlEasy, "put_data=", ruby_curl_easy_put_data_set, 1);
@@ -31,14 +31,6 @@ static VALUE idCall;
31
31
  #endif
32
32
 
33
33
  VALUE cCurlMulti;
34
- static void ruby_log(const char* str)
35
- {
36
- rb_funcall(rb_const_get(mCurl, rb_intern("L")), rb_intern("debug"), 1, rb_str_new2(str));
37
- }
38
- static void ruby_log_obj(VALUE obj)
39
- {
40
- rb_funcall(rb_const_get(mCurl, rb_intern("L")), rb_intern("debug"), 1, obj);
41
- }
42
34
 
43
35
  static long cCurlMutiDefaulttimeout = 100; /* milliseconds */
44
36
 
@@ -159,13 +151,6 @@ static VALUE ruby_curl_multi_requests(VALUE self) {
159
151
 
160
152
  return result_array;
161
153
  }
162
- static VALUE ruby_curl_multi_running(VALUE self) {
163
- ruby_curl_multi *rbcm;
164
-
165
- Data_Get_Struct(self, ruby_curl_multi, rbcm);
166
-
167
- return INT2FIX(rbcm->running);
168
- }
169
154
 
170
155
  /*
171
156
  * call-seq:
@@ -455,8 +440,6 @@ static void rb_curl_multi_run(VALUE self, CURLM *multi_handle, int *still_runnin
455
440
  raise_curl_multi_error_exception(mcode);
456
441
  }
457
442
 
458
- rb_curl_multi_read_info( self, multi_handle );
459
- if (rb_block_given_p()) rb_yield(self);
460
443
  }
461
444
 
462
445
  #ifdef _WIN32
@@ -517,78 +500,7 @@ static VALUE curb_select(void *args) {
517
500
  *
518
501
  * Run multi handles, looping selecting when data can be transfered
519
502
  */
520
- static VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
521
- ruby_curl_multi *rbcm;
522
- VALUE idle;
523
-
524
- Data_Get_Struct(self, ruby_curl_multi, rbcm);
525
-
526
- if (!(rbcm->active || rbcm->running)) {
527
- rb_scan_args(argc, argv, "01", &idle);
528
- if (idle == Qtrue) {
529
-
530
- if (rb_gv_get("$CarierThreadIsJoined") == Qtrue) {
531
- ruby_log("Nothing to perform; recalling...");
532
- return Qfalse;
533
- }
534
- ruby_log("Nothing to perform; idling...");
535
- rb_curl_multi_idle_perform(self, rbcm);
536
-
537
- }
538
- else {
539
- rb_raise(rb_eRuntimeError, "Nothing to perform");
540
- }
541
- return Qtrue;
542
- }
543
-
544
- rb_curl_multi_perform(self, rbcm);
545
- return Qtrue;
546
- }
547
-
548
- static void rb_curl_multi_idle_perform(VALUE self, ruby_curl_multi *rbcm) {
549
- struct timeval tv = {1, 0}; /* sleep time must not be lesser 1 second, otherwise multi thread will always "run" */
550
- int rc, maxfd;
551
- #ifdef _WIN32
552
- fd_set crt_fdread, crt_fdwrite, crt_fdexcep;
553
- #endif
554
- #ifdef HAVE_RB_THREAD_BLOCKING_REGION
555
- struct _select_set fdset_args;
556
- #endif
557
- fd_set fdread, fdwrite, fdexcep;
558
- FD_ZERO(&fdread);
559
- FD_ZERO(&fdwrite);
560
- FD_ZERO(&fdexcep);
561
- #ifdef _WIN32
562
- create_crt_fd(&fdread, &crt_fdread);
563
- create_crt_fd(&fdwrite, &crt_fdwrite);
564
- create_crt_fd(&fdexcep, &crt_fdexcep);
565
- #endif
566
-
567
- do {
568
- #ifdef HAVE_RB_THREAD_BLOCKING_REGION
569
- fdset_args.maxfd = 0;
570
- fdset_args.fdread = &fdread;
571
- fdset_args.fdwrite = &fdwrite;
572
- fdset_args.fdexcep = &fdexcep;
573
- fdset_args.tv = &tv;
574
- rc = rb_thread_blocking_region(curb_select, &fdset_args, RUBY_UBF_IO, 0);
575
- #else
576
- rc = rb_thread_select(0, &fdread, &fdwrite, &fdexcep, &tv);
577
- #endif
578
- if (rc == -1)
579
- rb_raise(rb_eRuntimeError, "select(): %s", strerror(errno));
580
-
581
- } while (!(RHASH_TBL(rbcm->requests)->num_entries));
582
-
583
- #ifdef _WIN32
584
- cleanup_crt_fd(&fdread, &crt_fdread);
585
- cleanup_crt_fd(&fdwrite, &crt_fdwrite);
586
- cleanup_crt_fd(&fdexcep, &crt_fdexcep);
587
- #endif
588
- rb_curl_multi_perform(self, rbcm);
589
- }
590
-
591
- void rb_curl_multi_perform(VALUE self, ruby_curl_multi *rbcm) {
503
+ VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
592
504
  CURLMcode mcode;
593
505
  ruby_curl_multi *rbcm;
594
506
  int maxfd, rc;
@@ -598,85 +510,102 @@ void rb_curl_multi_perform(VALUE self, ruby_curl_multi *rbcm) {
598
510
  #endif
599
511
  long timeout_milliseconds;
600
512
  struct timeval tv = {0, 0};
513
+ VALUE block = Qnil;
601
514
  #ifdef HAVE_RB_THREAD_BLOCKING_REGION
602
515
  struct _select_set fdset_args;
603
516
  #endif
517
+
518
+ rb_scan_args(argc, argv, "0&", &block);
519
+
520
+ Data_Get_Struct(self, ruby_curl_multi, rbcm);
521
+
604
522
  timeout_milliseconds = cCurlMutiDefaulttimeout;
605
523
 
606
524
  rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
607
-
608
- while (rbcm->running) {
525
+ rb_curl_multi_read_info( self, rbcm->handle );
526
+ if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
527
+
528
+ do {
529
+ while (rbcm->running) {
530
+
609
531
  #ifdef HAVE_CURL_MULTI_TIMEOUT
610
- /* get the curl suggested time out */
611
- mcode = curl_multi_timeout(rbcm->handle, &timeout_milliseconds);
612
- if (mcode != CURLM_OK) {
613
- raise_curl_multi_error_exception(mcode);
614
- }
532
+ /* get the curl suggested time out */
533
+ mcode = curl_multi_timeout(rbcm->handle, &timeout_milliseconds);
534
+ if (mcode != CURLM_OK) {
535
+ raise_curl_multi_error_exception(mcode);
536
+ }
615
537
  #else
616
- /* libcurl doesn't have a timeout method defined, initialize to -1 we'll pick up the default later */
617
- timeout_milliseconds = -1;
538
+ /* libcurl doesn't have a timeout method defined, initialize to -1 we'll pick up the default later */
539
+ timeout_milliseconds = -1;
618
540
  #endif
619
541
 
620
- if (timeout_milliseconds == 0) { /* no delay */
621
- rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
622
- continue;
623
- }
542
+ if (timeout_milliseconds == 0) { /* no delay */
543
+ rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
544
+ rb_curl_multi_read_info( self, rbcm->handle );
545
+ if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
546
+ continue;
547
+ }
624
548
 
625
- if (timeout_milliseconds < 0 || timeout_milliseconds > cCurlMutiDefaulttimeout) {
626
- timeout_milliseconds = cCurlMutiDefaulttimeout; /* libcurl doesn't know how long to wait, use a default timeout */
627
- /* or buggy versions libcurl sometimes reports huge timeouts... let's cap it */
628
- }
549
+ if (timeout_milliseconds < 0 || timeout_milliseconds > cCurlMutiDefaulttimeout) {
550
+ timeout_milliseconds = cCurlMutiDefaulttimeout; /* libcurl doesn't know how long to wait, use a default timeout */
551
+ /* or buggy versions libcurl sometimes reports huge timeouts... let's cap it */
552
+ }
629
553
 
630
- tv.tv_sec = 0; /* never wait longer than 1 second */
631
- tv.tv_usec = (int)(timeout_milliseconds * 1000); /* XXX: int is the right type for OSX, what about linux? */
554
+ tv.tv_sec = 0; /* never wait longer than 1 second */
555
+ tv.tv_usec = (int)(timeout_milliseconds * 1000); /* XXX: int is the right type for OSX, what about linux? */
632
556
 
633
- FD_ZERO(&fdread);
634
- FD_ZERO(&fdwrite);
635
- FD_ZERO(&fdexcep);
557
+ FD_ZERO(&fdread);
558
+ FD_ZERO(&fdwrite);
559
+ FD_ZERO(&fdexcep);
636
560
 
637
- /* load the fd sets from the multi handle */
638
- mcode = curl_multi_fdset(rbcm->handle, &fdread, &fdwrite, &fdexcep, &maxfd);
639
- if (mcode != CURLM_OK) {
640
- raise_curl_multi_error_exception(mcode);
641
- }
642
- ruby_log_obj(INT2FIX(maxfd));
561
+ /* load the fd sets from the multi handle */
562
+ mcode = curl_multi_fdset(rbcm->handle, &fdread, &fdwrite, &fdexcep, &maxfd);
563
+ if (mcode != CURLM_OK) {
564
+ raise_curl_multi_error_exception(mcode);
565
+ }
643
566
 
644
567
  #ifdef _WIN32
645
- create_crt_fd(&fdread, &crt_fdread);
646
- create_crt_fd(&fdwrite, &crt_fdwrite);
647
- create_crt_fd(&fdexcep, &crt_fdexcep);
568
+ create_crt_fd(&fdread, &crt_fdread);
569
+ create_crt_fd(&fdwrite, &crt_fdwrite);
570
+ create_crt_fd(&fdexcep, &crt_fdexcep);
648
571
  #endif
649
572
 
650
573
  #ifdef HAVE_RB_THREAD_BLOCKING_REGION
651
- fdset_args.maxfd = maxfd+1;
652
- fdset_args.fdread = &fdread;
653
- fdset_args.fdwrite = &fdwrite;
654
- fdset_args.fdexcep = &fdexcep;
655
- fdset_args.tv = &tv;
656
- rc = rb_thread_blocking_region(curb_select, &fdset_args, RUBY_UBF_IO, 0);
574
+ fdset_args.maxfd = maxfd+1;
575
+ fdset_args.fdread = &fdread;
576
+ fdset_args.fdwrite = &fdwrite;
577
+ fdset_args.fdexcep = &fdexcep;
578
+ fdset_args.tv = &tv;
579
+ rc = rb_thread_blocking_region(curb_select, &fdset_args, RUBY_UBF_IO, 0);
657
580
  #else
658
- rc = rb_thread_select(maxfd+1, &fdread, &fdwrite, &fdexcep, &tv);
581
+ rc = rb_thread_select(maxfd+1, &fdread, &fdwrite, &fdexcep, &tv);
659
582
  #endif
660
583
 
661
584
  #ifdef _WIN32
662
- cleanup_crt_fd(&fdread, &crt_fdread);
663
- cleanup_crt_fd(&fdwrite, &crt_fdwrite);
664
- cleanup_crt_fd(&fdexcep, &crt_fdexcep);
585
+ cleanup_crt_fd(&fdread, &crt_fdread);
586
+ cleanup_crt_fd(&fdwrite, &crt_fdwrite);
587
+ cleanup_crt_fd(&fdexcep, &crt_fdexcep);
665
588
  #endif
666
589
 
667
- switch(rc) {
668
- case -1:
669
- rb_raise(rb_eRuntimeError, "select(): %s", strerror(errno));
670
- break;
671
- case 0: /* timeout */
672
- default: /* action */
673
- rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
674
- break;
590
+ switch(rc) {
591
+ case -1:
592
+ rb_raise(rb_eRuntimeError, "select(): %s", strerror(errno));
593
+ break;
594
+ case 0: /* timeout */
595
+ default: /* action */
596
+ rb_curl_multi_run( self, rbcm->handle, &(rbcm->running) );
597
+ rb_curl_multi_read_info( self, rbcm->handle );
598
+ if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
599
+ break;
600
+ }
675
601
  }
676
- }
602
+
603
+ } while( rbcm->running );
677
604
 
678
605
  rb_curl_multi_read_info( self, rbcm->handle );
679
- if (rb_block_given_p()) {rb_yield(self);}
606
+ if (block != Qnil) { rb_funcall(block, rb_intern("call"), 1, self); }
607
+
608
+ return Qtrue;
680
609
  }
681
610
 
682
611
  /* =================== INIT LIB =====================*/
@@ -661,7 +661,7 @@ static VALUE ruby_curl_multi_perform(int argc, VALUE *argv, VALUE self) {
661
661
  rb_scan_args(argc, argv, "01", &idle);
662
662
  if (idle == Qtrue) {
663
663
 
664
- if (rb_gv_get("$CarierThreadIsJoined") == Qtrue) {
664
+ if (rb_funcall(mCurl, rb_intern("joined"), 0) == Qtrue) {
665
665
  ruby_log("Nothing to perform; recalling...");
666
666
  return Qfalse;
667
667
  }
data/lib/rhack.rb CHANGED
@@ -1,17 +1,87 @@
1
1
  # encoding: utf-8
2
2
  $KCODE = 'UTF-8' if RUBY_VERSION < "1.9"
3
- require 'rmtools_dev' unless defined? RMTools
4
- requrie 'cgi'
5
- here = File.expand_path File.dirname __FILE__
3
+ require 'rmtools'
4
+ here = File.expand_path '..', __FILE__
5
+ require "rhack/version"
6
+
6
7
  require File.join(here, 'curb_core.so')
7
- require 'active_record'
8
- Dir.glob("#{here}/extensions/**.rb") { |f| require f }
8
+ require "rhack/js/johnson"
9
+
10
+ module RHACK
11
+ mattr_reader :config, :redis, :useragents
12
+
13
+ Dir.chdir ENV['APP_ROOT'] if ENV['APP_ROOT']
14
+ cfgfile = Dir['{config/,}rhack.yml'].first
15
+ @@config = cfgfile ? YAML.load(IO.read(cfgfile)) : {}
16
+
17
+ L = RMTools::RMLogger.new(config.logger || {})
18
+
19
+ db = config.db || {}
20
+ @@redis = nil
21
+ if rcfg = db.redis
22
+ begin
23
+ require 'redis'
24
+ @@redis = ::Redis.new(path: rcfg.socket, db: rcfg.db)
25
+ redis.client.connect
26
+ rescue Errno::ENOENT => errno
27
+ rfcgfile = rcfg.configfilename || File.expand_path('config/redis.conf')
28
+ cmd = %{redis-server "#{rcfgfile}"}
29
+ msg = "#{errno.message}. Trying to run redis-server: `#{cmd}`"
30
+ $stderr.puts msg
31
+ L.log msg
32
+ res = `#{cmd}`
33
+ begin
34
+ redis.client.connect
35
+ rescue => err
36
+ err.message = "Can't connect to redis using config @ #{rcfgfile}. #{err.message}"
37
+ raise err
38
+ end
39
+ rescue LoadError => loaderr
40
+ msg = "#{loaderr.message}. RHACK.redis will stay turned off"
41
+ $stderr.puts msg
42
+ L.log msg
43
+ end
44
+ end
45
+
46
+ uas = config.useragents || {}
47
+ if uas = uas.desktop.to_s and File.file? uas
48
+ @@useragents = IO.read(uas)/"\n"
49
+ else
50
+ @@useragents = ['Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1']
51
+ end
52
+
53
+ class Scout
54
+ mattr_reader :cacert
55
+ mattr_accessor :retry, :timeout
56
+
57
+ scout = RHACK.config.scout || {}
58
+ @@retry = scout.retry.b || {}
59
+ @@timeout = scout.timeout.b || 60
60
+ @@cacert = scout.cacert.b ? File.expand_path(scout.cacert) : File.expand_path('../../config/cacert.pem', __FILE__)
61
+ end
62
+
63
+ end
64
+
65
+ module Curl
66
+ # $Carier, $CarierThread, $CarierThreadIsJoined respectively
67
+ mattr_reader :carier, :carier_thread, :joined
68
+ L = RHACK::L
69
+
70
+ @@carier = Curl::Multi.new
71
+ carier.pipeline = true
72
+ $Carier ||= carier
73
+ end
74
+
75
+ class Johnson::Runtime
76
+ L = RHACK::L
77
+ end
9
78
 
10
- require "#{here}/init" unless defined? RHACK
11
- RHACK::VERSION = IO.read(File.join here, '..', 'Rakefile').match(/RHACK_VERSION = '(.+?)'/)[1]
79
+ # uhm, backward compatibility? more like historicity
80
+ HTTPAccessKit = RHACK
12
81
 
13
- require "#{here}/curl-global"
14
- require "#{here}/scout"
15
- require "#{here}/frame"
16
- require "#{here}/words"
17
- require "#{here}/cache" if defined? RHACK::CacheDir
82
+ require "rhack/curl"
83
+ require "rhack/cookie"
84
+ require "rhack/scout"
85
+ require "rhack/scout_squad"
86
+ require "rhack/frame"
87
+ require "rhack/page"