Skip to content

Commit be9b4f5

Browse files
committed
2021.1 release code drop.
1 parent cc7ec01 commit be9b4f5

15 files changed

Lines changed: 1402 additions & 700 deletions

LICENSE.txt

Lines changed: 451 additions & 20 deletions
Large diffs are not rendered by default.

RELNOTES.txt

Lines changed: 478 additions & 616 deletions
Large diffs are not rendered by default.

ext/P4/clientprogressruby.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ ClientProgressRuby::ClientProgressRuby(VALUE prog, int t) {
5656
}
5757

5858
ClientProgressRuby::~ClientProgressRuby() {
59-
rb_gc_mark( progress );
6059
}
6160

6261
void ClientProgressRuby::Description(const StrPtr *d, int u) {

ext/P4/clientuserruby.cpp

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <ruby.h>
3939
#include "undefdups.h"
4040
#include <p4/clientapi.h>
41+
#include <p4/strtable.h>
4142
#include <p4/clientprog.h>
4243
#include <p4/spec.h>
4344
#include <p4/diff.h>
@@ -77,6 +78,7 @@ ClientUserRuby::ClientUserRuby(SpecMgr *s) {
7778
rubyExcept = 0;
7879
alive = 1;
7980
track = false;
81+
SetSSOHandler( ssoHandler = new P4ClientSSO( s ) );
8082

8183
ID idP4 = rb_intern("P4");
8284
ID idP4OH = rb_intern("OutputHandler");
@@ -723,4 +725,157 @@ void ClientUserRuby::GCMark() {
723725
rb_gc_mark( cProgress );
724726

725727
results.GCMark();
728+
ssoHandler->GCMark();
726729
}
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+
}

ext/P4/clientuserruby.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,39 @@
4242
class SpecMgr;
4343
class ClientProgress;
4444

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+
4578
class ClientUserRuby: public ClientUser, public KeepAlive {
4679
public:
4780
ClientUserRuby(SpecMgr *s);
@@ -101,6 +134,16 @@ class ClientUserRuby: public ClientUser, public KeepAlive {
101134
return progress;
102135
}
103136

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+
104147
// override from KeepAlive
105148
virtual int IsAlive() {
106149
return alive;
@@ -129,5 +172,6 @@ class ClientUserRuby: public ClientUser, public KeepAlive {
129172
int alive;
130173
int rubyExcept;
131174
bool track;
175+
P4ClientSSO * ssoHandler;
132176
};
133177

ext/P4/extconf.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ def p4_cpu(os)
425425
when :darwin, :linux
426426
if cpu =~ /i686/
427427
'x86'
428+
elsif cpu =~ /universal/
429+
'x86_64'
428430
else
429431
cpu
430432
end
@@ -451,7 +453,9 @@ def p4_platform_label
451453
else
452454
'mingwx86'
453455
end
454-
when /darwin/
456+
when /darwin19|darwin[2-9][0-9]/
457+
"macosx1015#{p4_cpu(:darwin)}"
458+
when /darwin/
455459
"darwin90#{p4_cpu(:darwin)}"
456460
when /solaris/
457461
"solaris10#{p4_cpu(:solaris)}"
@@ -484,6 +488,8 @@ def filename
484488
filename = 'p4api-openssl1.0.2.zip'
485489
end
486490
end
491+
elsif RbConfig::CONFIG['target_os'].downcase =~ /darwin19|darwin[2-9][0-9]/
492+
filename = 'p4api-openssl1.1.1.tgz'
487493
else
488494
filename = 'p4api.tgz'
489495
if !openssl_number.to_s.empty?

ext/P4/p4.cpp

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,25 @@ static VALUE p4_set_enviro_file( VALUE self, VALUE rbstr )
314314
return Qtrue;
315315
}
316316

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+
317336
static VALUE p4_get_host( VALUE self )
318337
{
319338
P4ClientApi *p4;
@@ -642,7 +661,7 @@ static VALUE p4_run( VALUE self, VALUE args )
642661

643662
// Allocate storage on the stack so it's automatically reclaimed
644663
// when we exit.
645-
char **p4args = ALLOCA_N( char *, argc + 1 );
664+
char **p4args = RB_ALLOC_N( char *, argc + 1 );
646665

647666
// Copy the args across
648667
for ( i = 0; i < argc; i++ )
@@ -808,6 +827,58 @@ static VALUE p4_set_progress( VALUE self, VALUE progress )
808827
return p4->SetProgress( progress );
809828
}
810829

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+
811882
/*******************************************************************************
812883
* P4::MergeData methods. Construction/destruction defined elsewhere
813884
******************************************************************************/
@@ -1262,6 +1333,8 @@ void Init_P4()
12621333
rb_define_method( cP4, "set_env", RUBY_METHOD_FUNC(p4_set_env) , 2 );
12631334
rb_define_method( cP4, "enviro_file", RUBY_METHOD_FUNC(p4_get_enviro_file), 0);
12641335
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 );
12651338
rb_define_method( cP4, "host", RUBY_METHOD_FUNC(p4_get_host) , 0 );
12661339
rb_define_method( cP4, "host=", RUBY_METHOD_FUNC(p4_set_host) , 1 );
12671340
rb_define_method( cP4, "ignore_file",RUBY_METHOD_FUNC(p4_get_ignore) , 0 );
@@ -1335,6 +1408,16 @@ void Init_P4()
13351408
rb_define_method( cP4, "progress", RUBY_METHOD_FUNC(p4_get_progress), 0);
13361409
rb_define_method( cP4, "progress=", RUBY_METHOD_FUNC(p4_set_progress), 1);
13371410

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+
13381421
// P4::MergeData class
13391422
cP4MD = rb_define_class_under( cP4, "MergeData", rb_cObject );
13401423

0 commit comments

Comments
 (0)