p4ruby 2017.1.1699426-x64-mingw32 → 2021.1.2156749-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,7 +56,6 @@ ClientProgressRuby::ClientProgressRuby(VALUE prog, int t) {
56
56
  }
57
57
 
58
58
  ClientProgressRuby::~ClientProgressRuby() {
59
- rb_gc_mark( progress );
60
59
  }
61
60
 
62
61
  void ClientProgressRuby::Description(const StrPtr *d, int u) {
@@ -38,6 +38,7 @@
38
38
  #include <ruby.h>
39
39
  #include "undefdups.h"
40
40
  #include <p4/clientapi.h>
41
+ #include <p4/strtable.h>
41
42
  #include <p4/clientprog.h>
42
43
  #include <p4/spec.h>
43
44
  #include <p4/diff.h>
@@ -77,6 +78,7 @@ ClientUserRuby::ClientUserRuby(SpecMgr *s) {
77
78
  rubyExcept = 0;
78
79
  alive = 1;
79
80
  track = false;
81
+ SetSSOHandler( ssoHandler = new P4ClientSSO( s ) );
80
82
 
81
83
  ID idP4 = rb_intern("P4");
82
84
  ID idP4OH = rb_intern("OutputHandler");
@@ -723,4 +725,157 @@ void ClientUserRuby::GCMark() {
723
725
  rb_gc_mark( cProgress );
724
726
 
725
727
  results.GCMark();
728
+ ssoHandler->GCMark();
726
729
  }
730
+
731
+ //
732
+ // SSO handler
733
+ //
734
+
735
+ P4ClientSSO::P4ClientSSO( SpecMgr *s )
736
+ {
737
+ specMgr = s;
738
+ resultSet = 0;
739
+ ssoEnabled = 0;
740
+ result = Qnil;
741
+ }
742
+
743
+ ClientSSOStatus
744
+ P4ClientSSO::Authorize( StrDict &vars, int maxLength, StrBuf &strbuf )
745
+ {
746
+ ssoVars.Clear();
747
+
748
+ if( !ssoEnabled )
749
+ return CSS_SKIP;
750
+
751
+ if( ssoEnabled < 0 )
752
+ return CSS_UNSET;
753
+
754
+ if( resultSet )
755
+ {
756
+ strbuf.Clear();
757
+ VALUE resval = result;
758
+
759
+ //if( P4RDB_CALLS )
760
+ // std::cerr << "[P4] ClientSSO::Authorize(). Using supplied input"
761
+ // << std::endl;
762
+
763
+ if (Qtrue == rb_obj_is_kind_of(result, rb_cArray)) {
764
+ resval = rb_ary_shift(result);
765
+ }
766
+
767
+ if( resval != Qnil ) {
768
+ // Convert whatever's left into a string
769
+ ID to_s = rb_intern("to_s");
770
+ VALUE str = rb_funcall(resval, to_s, 0);
771
+ strbuf.Set(StringValuePtr(str));
772
+ }
773
+
774
+ return resultSet == 2 ? CSS_FAIL
775
+ : CSS_PASS;
776
+ }
777
+
778
+ ssoVars.CopyVars( vars );
779
+ return CSS_EXIT;
780
+ }
781
+
782
+ VALUE
783
+ P4ClientSSO::EnableSSO( VALUE e )
784
+ {
785
+ if( e == Qnil )
786
+ {
787
+ ssoEnabled = 0;
788
+ return Qtrue;
789
+ }
790
+
791
+ if( e == Qtrue )
792
+ {
793
+ ssoEnabled = 1;
794
+ return Qtrue;
795
+ }
796
+
797
+ if( e == Qfalse )
798
+ {
799
+ ssoEnabled = -1;
800
+ return Qtrue;
801
+ }
802
+
803
+ return Qfalse;
804
+ }
805
+
806
+ VALUE
807
+ P4ClientSSO::SSOEnabled()
808
+ {
809
+ if( ssoEnabled == 1 )
810
+ {
811
+ return Qtrue;
812
+ }
813
+ else if( ssoEnabled == -1 )
814
+ {
815
+ return Qfalse;
816
+ }
817
+ else
818
+ {
819
+ return Qnil;
820
+ }
821
+ }
822
+
823
+ VALUE
824
+ P4ClientSSO::SetPassResult( VALUE i )
825
+ {
826
+ resultSet = 1;
827
+ return SetResult( i );
828
+ }
829
+
830
+ VALUE
831
+ P4ClientSSO::GetPassResult()
832
+ {
833
+ if( resultSet == 1 )
834
+ {
835
+ return result;
836
+ }
837
+ else
838
+ {
839
+ return Qnil;
840
+ }
841
+ }
842
+
843
+ VALUE
844
+ P4ClientSSO::SetFailResult( VALUE i )
845
+ {
846
+ resultSet = 2;
847
+ return SetResult( i );
848
+ }
849
+
850
+ VALUE
851
+ P4ClientSSO::GetFailResult()
852
+ {
853
+ if( resultSet == 2 )
854
+ {
855
+ return result;
856
+ }
857
+ else
858
+ {
859
+ return Qnil;
860
+ }
861
+ }
862
+
863
+ VALUE
864
+ P4ClientSSO::SetResult( VALUE i )
865
+ {
866
+ //if (P4RDB_CALLS) fprintf(stderr, "[P4] P4ClientSSO::SetResult()\n");
867
+
868
+ result = i;
869
+ return Qtrue;
870
+ }
871
+
872
+ VALUE
873
+ P4ClientSSO::GetSSOVars()
874
+ {
875
+ return specMgr->StrDictToHash( &ssoVars );
876
+ }
877
+
878
+ void
879
+ P4ClientSSO::GCMark() {
880
+ if (result != Qnil) rb_gc_mark( result );
881
+ }
@@ -42,6 +42,39 @@
42
42
  class SpecMgr;
43
43
  class ClientProgress;
44
44
 
45
+ class P4ClientSSO : public ClientSSO
46
+ {
47
+ public:
48
+ P4ClientSSO( SpecMgr *s );
49
+
50
+ // Client SSO methods overridden here
51
+ virtual ClientSSOStatus Authorize( StrDict &vars, int maxLength,
52
+ StrBuf &result );
53
+
54
+ // Local methods
55
+ VALUE EnableSSO( VALUE e );
56
+ VALUE SSOEnabled();
57
+ VALUE SetPassResult( VALUE i );
58
+ VALUE GetPassResult();
59
+ VALUE SetFailResult( VALUE i );
60
+ VALUE GetFailResult();
61
+ VALUE GetSSOVars();
62
+
63
+ void GCMark();
64
+
65
+ private:
66
+
67
+ VALUE SetResult( VALUE i );
68
+
69
+ int ssoEnabled;
70
+ int resultSet;
71
+
72
+ StrBufDict ssoVars;
73
+ SpecMgr * specMgr;
74
+
75
+ VALUE result;
76
+ };
77
+
45
78
  class ClientUserRuby: public ClientUser, public KeepAlive {
46
79
  public:
47
80
  ClientUserRuby(SpecMgr *s);
@@ -101,6 +134,16 @@ public:
101
134
  return progress;
102
135
  }
103
136
 
137
+ // SSO handler support
138
+
139
+ VALUE EnableSSO( VALUE e ) { return ssoHandler->EnableSSO( e ); }
140
+ VALUE SSOEnabled() { return ssoHandler->SSOEnabled(); }
141
+ VALUE SetSSOPassResult( VALUE i ) { return ssoHandler->SetPassResult( i ); }
142
+ VALUE GetSSOPassResult(){ return ssoHandler->GetPassResult();}
143
+ VALUE SetSSOFailResult( VALUE i ) { return ssoHandler->SetFailResult( i ); }
144
+ VALUE GetSSOFailResult(){ return ssoHandler->GetFailResult();}
145
+ VALUE GetSSOVars() { return ssoHandler->GetSSOVars(); }
146
+
104
147
  // override from KeepAlive
105
148
  virtual int IsAlive() {
106
149
  return alive;
@@ -129,5 +172,6 @@ private:
129
172
  int alive;
130
173
  int rubyExcept;
131
174
  bool track;
175
+ P4ClientSSO * ssoHandler;
132
176
  };
133
177
 
data/ext/P4/extconf.rb CHANGED
@@ -6,10 +6,19 @@ require 'mkmf'
6
6
  require 'net/ftp'
7
7
  require 'P4/version'
8
8
  require 'rbconfig'
9
+ require 'openssl'
9
10
 
10
11
  # Set this to the main version directory we look up in ftp.perforce.com for the P4API
11
12
  # This is ignored if you specify the version on the command line.
12
- P4API_VERSION_DIR = 'r17.2'
13
+ # Changed the hardcoded string so that the version is now derived from version.rb file
14
+ #P4API_VERSION_DIR = 'r19.1'
15
+ def p4api_version_dir
16
+ ver=P4::Version.split(".")
17
+ p4_major = ver[0].chars.last(2).join
18
+ p4_minor = ver[1]
19
+ dir = "r" + p4_major + "." + p4_minor
20
+ end
21
+
13
22
 
14
23
  #==============================================================================
15
24
  # Provide platform variables in P4-specific format
@@ -102,6 +111,15 @@ def calculate_p4osver
102
111
  return ver
103
112
  end
104
113
 
114
+ def gcc
115
+ @gcc ||= calculate_gcc
116
+ end
117
+
118
+ def calculate_gcc
119
+ gcc = RbConfig::CONFIG["GCC"]
120
+ return gcc
121
+ end
122
+
105
123
  def uname_platform
106
124
  @uname_platform ||= calculate_uname_platform
107
125
  end
@@ -155,6 +173,13 @@ def set_platform_opts
155
173
  end
156
174
  end
157
175
 
176
+ def set_platform_cxxflags
177
+ if (p4osname == 'LINUX') && (gcc == 'yes')
178
+ $CXXFLAGS += " -std=c++11 "
179
+ end
180
+ end
181
+
182
+
158
183
  def set_platform_cppflags
159
184
  $CPPFLAGS += "-DOS_#{p4osname} "
160
185
  $CPPFLAGS += "-DOS_#{p4osname}#{p4osver} "
@@ -214,6 +239,7 @@ def set_platform_libs
214
239
  $LDFLAGS += ' -framework CoreFoundation -framework Foundation'
215
240
  end
216
241
  when 'LINUX', 'MINGW32'
242
+ $LDFLAGS += ' -Wl,--allow-multiple-definition'
217
243
  have_library('supc++')
218
244
  end
219
245
  end
@@ -399,6 +425,8 @@ def p4_cpu(os)
399
425
  when :darwin, :linux
400
426
  if cpu =~ /i686/
401
427
  'x86'
428
+ elsif cpu =~ /universal/
429
+ 'x86_64'
402
430
  else
403
431
  cpu
404
432
  end
@@ -425,7 +453,9 @@ def p4_platform_label
425
453
  else
426
454
  'mingwx86'
427
455
  end
428
- when /darwin/
456
+ when /darwin19|darwin[2-9][0-9]/
457
+ "macosx1015#{p4_cpu(:darwin)}"
458
+ when /darwin/
429
459
  "darwin90#{p4_cpu(:darwin)}"
430
460
  when /solaris/
431
461
  "solaris10#{p4_cpu(:solaris)}"
@@ -445,13 +475,36 @@ def ftp_download_dir(version)
445
475
  end
446
476
 
447
477
  def filename
478
+ openssl_number = OpenSSL::OPENSSL_VERSION.split(' ')[1].to_s
479
+ openssl_number = openssl_number.slice(0, (openssl_number.rindex('.')))
480
+
448
481
  if RbConfig::CONFIG['target_os'].downcase =~ /nt|mswin|mingw/
449
- 'p4api.zip'
482
+ filename = 'p4api.zip'
483
+ if !openssl_number.to_s.empty?
484
+ case openssl_number.to_s
485
+ when /1.1/
486
+ filename = 'p4api-openssl1.1.1.zip'
487
+ when /1.0/
488
+ filename = 'p4api-openssl1.0.2.zip'
489
+ end
490
+ end
491
+ elsif RbConfig::CONFIG['target_os'].downcase =~ /darwin19|darwin[2-9][0-9]/
492
+ filename = 'p4api-openssl1.1.1.tgz'
450
493
  else
451
- 'p4api.tgz'
494
+ filename = 'p4api.tgz'
495
+ if !openssl_number.to_s.empty?
496
+ case openssl_number.to_s
497
+ when /1.1/
498
+ filename = 'p4api-glibc2.3-openssl1.1.1.tgz'
499
+ when /1.0/
500
+ filename = 'p4api-glibc2.3-openssl1.0.2.tgz'
501
+ end
502
+ end
452
503
  end
504
+ return filename
453
505
  end
454
506
 
507
+
455
508
  def remote_files_matching(ftp, dir, regex)
456
509
  ftp.ls(dir.to_s).map { |entry|
457
510
  if match = entry.match(regex)
@@ -499,9 +552,8 @@ def download_api_via_ftp
499
552
  # At one point, we allowed the gem build to just find the most recent p4api build.
500
553
  # P4Ruby probably shouldn't do that by default.
501
554
  #version_dir = find_latest_version_dir(ftp)
502
- version_dir = P4API_VERSION_DIR
503
555
 
504
- dir = ftp_download_dir(version_dir)
556
+ dir = ftp_download_dir(p4api_version_dir)
505
557
  ftp.chdir(dir)
506
558
 
507
559
  puts "downloading #{filename} from #{dir} on ftp.perforce.com"
@@ -536,9 +588,11 @@ set_platform_opts
536
588
  # based solely on platform detection.
537
589
  set_platform_cppflags
538
590
  set_platform_cflags
591
+ set_platform_cxxflags
539
592
 
540
593
  puts "$CPPFLAGS #{$CPPFLAGS}"
541
594
  puts "$CFLAGS #{$CFLAGS}"
595
+ puts "$CXXFLAGS #{$CXXFLAGS}"
542
596
 
543
597
  # Setup additional system library definitions based on platform type before
544
598
  # we setup other libraries, in order to preserve linking order
@@ -554,15 +608,17 @@ resolve_ssl_dirs
554
608
  # If we happen to need SSL on Windows, we also need gdi32
555
609
  if RbConfig::CONFIG['target_os'].downcase =~ /mingw/
556
610
  have_library('gdi32') or raise
611
+ have_library('ole32') or raise
612
+ have_library('crypt32') or raise
557
613
  end
558
614
 
559
- do_ssl = have_library('crypto') and have_library('ssl')
560
-
561
- unless do_ssl
562
- have_library('p4sslstub') or raise
563
- end
564
-
615
+ have_library('crypto') or raise
616
+ have_library('ssl') or raise
565
617
  have_library('supp') or raise
618
+ have_library('p4script_sqlite') or raise
619
+ have_library('p4script_curl') or raise
620
+ have_library('p4script') or raise
621
+ have_library('p4script_c') or raise
566
622
  have_library('rpc') or raise
567
623
  have_library('client') or raise
568
624
 
@@ -577,4 +633,4 @@ create_p4rubyconf_header(version_info, $libs)
577
633
  # don't believe we need to rely on actually.
578
634
  create_header
579
635
 
580
- create_makefile('P4')
636
+ create_makefile('P4')
data/ext/P4/p4.cpp CHANGED
@@ -314,6 +314,25 @@ static VALUE p4_set_enviro_file( VALUE self, VALUE rbstr )
314
314
  return Qtrue;
315
315
  }
316
316
 
317
+ static VALUE p4_get_evar( VALUE self, VALUE var )
318
+ {
319
+ P4ClientApi *p4;
320
+ const StrPtr *val;
321
+ Data_Get_Struct( self, P4ClientApi, p4 );
322
+ val = p4->GetEVar( StringValuePtr( var ) );
323
+ if( !val ) return Qnil;
324
+
325
+ return P4Utils::ruby_string( val->Text() );
326
+ }
327
+
328
+ static VALUE p4_set_evar( VALUE self, VALUE var, VALUE val )
329
+ {
330
+ P4ClientApi *p4;
331
+ Data_Get_Struct( self, P4ClientApi, p4 );
332
+ p4->SetEVar( StringValuePtr( var ), StringValuePtr( val ) );
333
+ return Qtrue;
334
+ }
335
+
317
336
  static VALUE p4_get_host( VALUE self )
318
337
  {
319
338
  P4ClientApi *p4;
@@ -642,7 +661,7 @@ static VALUE p4_run( VALUE self, VALUE args )
642
661
 
643
662
  // Allocate storage on the stack so it's automatically reclaimed
644
663
  // when we exit.
645
- char **p4args = ALLOCA_N( char *, argc + 1 );
664
+ char **p4args = RB_ALLOC_N( char *, argc + 1 );
646
665
 
647
666
  // Copy the args across
648
667
  for ( i = 0; i < argc; i++ )
@@ -679,13 +698,6 @@ static VALUE p4_get_messages( VALUE self )
679
698
  return p4->GetMessages();
680
699
  }
681
700
 
682
- static VALUE p4_reset( VALUE self )
683
- {
684
- P4ClientApi *p4;
685
- Data_Get_Struct( self, P4ClientApi, p4 );
686
- return p4->Reset();
687
- }
688
-
689
701
  static VALUE p4_get_warnings( VALUE self )
690
702
  {
691
703
  P4ClientApi *p4;
@@ -815,6 +827,58 @@ static VALUE p4_set_progress( VALUE self, VALUE progress )
815
827
  return p4->SetProgress( progress );
816
828
  }
817
829
 
830
+ /*******************************************************************************
831
+ * SSO handler support
832
+ ******************************************************************************/
833
+ static VALUE p4_get_enabled_sso( VALUE self )
834
+ {
835
+ P4ClientApi *p4;
836
+ Data_Get_Struct( self, P4ClientApi, p4 );
837
+ return p4->GetEnableSSO();
838
+ }
839
+
840
+ static VALUE p4_set_enable_sso( VALUE self, VALUE enable )
841
+ {
842
+ P4ClientApi *p4;
843
+ Data_Get_Struct( self, P4ClientApi, p4 );
844
+ return p4->SetEnableSSO( enable );
845
+ }
846
+
847
+ static VALUE p4_get_sso_vars( VALUE self )
848
+ {
849
+ P4ClientApi *p4;
850
+ Data_Get_Struct( self, P4ClientApi, p4 );
851
+ return p4->GetSSOVars();
852
+ }
853
+
854
+ static VALUE p4_get_sso_passresult( VALUE self )
855
+ {
856
+ P4ClientApi *p4;
857
+ Data_Get_Struct( self, P4ClientApi, p4 );
858
+ return p4->GetSSOPassResult();
859
+ }
860
+
861
+ static VALUE p4_set_sso_passresult( VALUE self, VALUE result )
862
+ {
863
+ P4ClientApi *p4;
864
+ Data_Get_Struct( self, P4ClientApi, p4 );
865
+ return p4->SetSSOPassResult( result );
866
+ }
867
+
868
+ static VALUE p4_get_sso_failresult( VALUE self )
869
+ {
870
+ P4ClientApi *p4;
871
+ Data_Get_Struct( self, P4ClientApi, p4 );
872
+ return p4->GetSSOFailResult();
873
+ }
874
+
875
+ static VALUE p4_set_sso_failresult( VALUE self, VALUE result )
876
+ {
877
+ P4ClientApi *p4;
878
+ Data_Get_Struct( self, P4ClientApi, p4 );
879
+ return p4->SetSSOFailResult( result );
880
+ }
881
+
818
882
  /*******************************************************************************
819
883
  * P4::MergeData methods. Construction/destruction defined elsewhere
820
884
  ******************************************************************************/
@@ -1269,6 +1333,8 @@ void Init_P4()
1269
1333
  rb_define_method( cP4, "set_env", RUBY_METHOD_FUNC(p4_set_env) , 2 );
1270
1334
  rb_define_method( cP4, "enviro_file", RUBY_METHOD_FUNC(p4_get_enviro_file), 0);
1271
1335
  rb_define_method( cP4, "enviro_file=", RUBY_METHOD_FUNC(p4_set_enviro_file), 1);
1336
+ rb_define_method( cP4, "evar", RUBY_METHOD_FUNC(p4_get_evar) , 1 );
1337
+ rb_define_method( cP4, "set_evar", RUBY_METHOD_FUNC(p4_set_evar) , 2 );
1272
1338
  rb_define_method( cP4, "host", RUBY_METHOD_FUNC(p4_get_host) , 0 );
1273
1339
  rb_define_method( cP4, "host=", RUBY_METHOD_FUNC(p4_set_host) , 1 );
1274
1340
  rb_define_method( cP4, "ignore_file",RUBY_METHOD_FUNC(p4_get_ignore) , 0 );
@@ -1305,7 +1371,6 @@ void Init_P4()
1305
1371
  rb_define_method( cP4, "connect", RUBY_METHOD_FUNC(p4_connect) , 0 );
1306
1372
  rb_define_method( cP4, "connected?",RUBY_METHOD_FUNC(p4_connected) , 0 );
1307
1373
  rb_define_method( cP4, "disconnect", RUBY_METHOD_FUNC(p4_disconnect) , 0 );
1308
- rb_define_method( cP4, "reset", RUBY_METHOD_FUNC(p4_reset), 0 );
1309
1374
 
1310
1375
  // Running commands - general purpose commands
1311
1376
  rb_define_method( cP4, "run", RUBY_METHOD_FUNC(p4_run) ,-2 );
@@ -1343,6 +1408,16 @@ void Init_P4()
1343
1408
  rb_define_method( cP4, "progress", RUBY_METHOD_FUNC(p4_get_progress), 0);
1344
1409
  rb_define_method( cP4, "progress=", RUBY_METHOD_FUNC(p4_set_progress), 1);
1345
1410
 
1411
+ // SSO handling
1412
+ rb_define_method( cP4, "loginsso", RUBY_METHOD_FUNC(p4_get_enabled_sso), 0);
1413
+ rb_define_method( cP4, "loginsso=", RUBY_METHOD_FUNC(p4_set_enable_sso), 1);
1414
+ rb_define_method( cP4, "ssovars", RUBY_METHOD_FUNC(p4_get_sso_vars), 0);
1415
+ rb_define_method( cP4, "ssopassresult", RUBY_METHOD_FUNC(p4_get_sso_passresult), 0);
1416
+ rb_define_method( cP4, "ssopassresult=", RUBY_METHOD_FUNC(p4_set_sso_passresult), 1);
1417
+ rb_define_method( cP4, "ssofailresult", RUBY_METHOD_FUNC(p4_get_sso_failresult), 0);
1418
+ rb_define_method( cP4, "ssofailresult=", RUBY_METHOD_FUNC(p4_set_sso_failresult), 1);
1419
+
1420
+
1346
1421
  // P4::MergeData class
1347
1422
  cP4MD = rb_define_class_under( cP4, "MergeData", rb_cObject );
1348
1423