Skip to content

Commit

Permalink
2021.1 release code drop.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppiorunski committed Jul 15, 2021
1 parent cc7ec01 commit be9b4f5
Show file tree
Hide file tree
Showing 15 changed files with 1,402 additions and 700 deletions.
471 changes: 451 additions & 20 deletions LICENSE.txt

Large diffs are not rendered by default.

1,094 changes: 478 additions & 616 deletions RELNOTES.txt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ext/P4/clientprogressruby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ ClientProgressRuby::ClientProgressRuby(VALUE prog, int t) {
}

ClientProgressRuby::~ClientProgressRuby() {
rb_gc_mark( progress );
}

void ClientProgressRuby::Description(const StrPtr *d, int u) {
Expand Down
155 changes: 155 additions & 0 deletions ext/P4/clientuserruby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <ruby.h>
#include "undefdups.h"
#include <p4/clientapi.h>
#include <p4/strtable.h>
#include <p4/clientprog.h>
#include <p4/spec.h>
#include <p4/diff.h>
Expand Down Expand Up @@ -77,6 +78,7 @@ ClientUserRuby::ClientUserRuby(SpecMgr *s) {
rubyExcept = 0;
alive = 1;
track = false;
SetSSOHandler( ssoHandler = new P4ClientSSO( s ) );

ID idP4 = rb_intern("P4");
ID idP4OH = rb_intern("OutputHandler");
Expand Down Expand Up @@ -723,4 +725,157 @@ void ClientUserRuby::GCMark() {
rb_gc_mark( cProgress );

results.GCMark();
ssoHandler->GCMark();
}

//
// SSO handler
//

P4ClientSSO::P4ClientSSO( SpecMgr *s )
{
specMgr = s;
resultSet = 0;
ssoEnabled = 0;
result = Qnil;
}

ClientSSOStatus
P4ClientSSO::Authorize( StrDict &vars, int maxLength, StrBuf &strbuf )
{
ssoVars.Clear();

if( !ssoEnabled )
return CSS_SKIP;

if( ssoEnabled < 0 )
return CSS_UNSET;

if( resultSet )
{
strbuf.Clear();
VALUE resval = result;

//if( P4RDB_CALLS )
// std::cerr << "[P4] ClientSSO::Authorize(). Using supplied input"
// << std::endl;

if (Qtrue == rb_obj_is_kind_of(result, rb_cArray)) {
resval = rb_ary_shift(result);
}

if( resval != Qnil ) {
// Convert whatever's left into a string
ID to_s = rb_intern("to_s");
VALUE str = rb_funcall(resval, to_s, 0);
strbuf.Set(StringValuePtr(str));
}

return resultSet == 2 ? CSS_FAIL
: CSS_PASS;
}

ssoVars.CopyVars( vars );
return CSS_EXIT;
}

VALUE
P4ClientSSO::EnableSSO( VALUE e )
{
if( e == Qnil )
{
ssoEnabled = 0;
return Qtrue;
}

if( e == Qtrue )
{
ssoEnabled = 1;
return Qtrue;
}

if( e == Qfalse )
{
ssoEnabled = -1;
return Qtrue;
}

return Qfalse;
}

VALUE
P4ClientSSO::SSOEnabled()
{
if( ssoEnabled == 1 )
{
return Qtrue;
}
else if( ssoEnabled == -1 )
{
return Qfalse;
}
else
{
return Qnil;
}
}

VALUE
P4ClientSSO::SetPassResult( VALUE i )
{
resultSet = 1;
return SetResult( i );
}

VALUE
P4ClientSSO::GetPassResult()
{
if( resultSet == 1 )
{
return result;
}
else
{
return Qnil;
}
}

VALUE
P4ClientSSO::SetFailResult( VALUE i )
{
resultSet = 2;
return SetResult( i );
}

VALUE
P4ClientSSO::GetFailResult()
{
if( resultSet == 2 )
{
return result;
}
else
{
return Qnil;
}
}

VALUE
P4ClientSSO::SetResult( VALUE i )
{
//if (P4RDB_CALLS) fprintf(stderr, "[P4] P4ClientSSO::SetResult()\n");

result = i;
return Qtrue;
}

VALUE
P4ClientSSO::GetSSOVars()
{
return specMgr->StrDictToHash( &ssoVars );
}

void
P4ClientSSO::GCMark() {
if (result != Qnil) rb_gc_mark( result );
}
44 changes: 44 additions & 0 deletions ext/P4/clientuserruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,39 @@
class SpecMgr;
class ClientProgress;

class P4ClientSSO : public ClientSSO
{
public:
P4ClientSSO( SpecMgr *s );

// Client SSO methods overridden here
virtual ClientSSOStatus Authorize( StrDict &vars, int maxLength,
StrBuf &result );

// Local methods
VALUE EnableSSO( VALUE e );
VALUE SSOEnabled();
VALUE SetPassResult( VALUE i );
VALUE GetPassResult();
VALUE SetFailResult( VALUE i );
VALUE GetFailResult();
VALUE GetSSOVars();

void GCMark();

private:

VALUE SetResult( VALUE i );

int ssoEnabled;
int resultSet;

StrBufDict ssoVars;
SpecMgr * specMgr;

VALUE result;
};

class ClientUserRuby: public ClientUser, public KeepAlive {
public:
ClientUserRuby(SpecMgr *s);
Expand Down Expand Up @@ -101,6 +134,16 @@ class ClientUserRuby: public ClientUser, public KeepAlive {
return progress;
}

// SSO handler support

VALUE EnableSSO( VALUE e ) { return ssoHandler->EnableSSO( e ); }
VALUE SSOEnabled() { return ssoHandler->SSOEnabled(); }
VALUE SetSSOPassResult( VALUE i ) { return ssoHandler->SetPassResult( i ); }
VALUE GetSSOPassResult(){ return ssoHandler->GetPassResult();}
VALUE SetSSOFailResult( VALUE i ) { return ssoHandler->SetFailResult( i ); }
VALUE GetSSOFailResult(){ return ssoHandler->GetFailResult();}
VALUE GetSSOVars() { return ssoHandler->GetSSOVars(); }

// override from KeepAlive
virtual int IsAlive() {
return alive;
Expand Down Expand Up @@ -129,5 +172,6 @@ class ClientUserRuby: public ClientUser, public KeepAlive {
int alive;
int rubyExcept;
bool track;
P4ClientSSO * ssoHandler;
};

8 changes: 7 additions & 1 deletion ext/P4/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ def p4_cpu(os)
when :darwin, :linux
if cpu =~ /i686/
'x86'
elsif cpu =~ /universal/
'x86_64'
else
cpu
end
Expand All @@ -451,7 +453,9 @@ def p4_platform_label
else
'mingwx86'
end
when /darwin/
when /darwin19|darwin[2-9][0-9]/
"macosx1015#{p4_cpu(:darwin)}"
when /darwin/
"darwin90#{p4_cpu(:darwin)}"
when /solaris/
"solaris10#{p4_cpu(:solaris)}"
Expand Down Expand Up @@ -484,6 +488,8 @@ def filename
filename = 'p4api-openssl1.0.2.zip'
end
end
elsif RbConfig::CONFIG['target_os'].downcase =~ /darwin19|darwin[2-9][0-9]/
filename = 'p4api-openssl1.1.1.tgz'
else
filename = 'p4api.tgz'
if !openssl_number.to_s.empty?
Expand Down
85 changes: 84 additions & 1 deletion ext/P4/p4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,25 @@ static VALUE p4_set_enviro_file( VALUE self, VALUE rbstr )
return Qtrue;
}

static VALUE p4_get_evar( VALUE self, VALUE var )
{
P4ClientApi *p4;
const StrPtr *val;
Data_Get_Struct( self, P4ClientApi, p4 );
val = p4->GetEVar( StringValuePtr( var ) );
if( !val ) return Qnil;

return P4Utils::ruby_string( val->Text() );
}

static VALUE p4_set_evar( VALUE self, VALUE var, VALUE val )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
p4->SetEVar( StringValuePtr( var ), StringValuePtr( val ) );
return Qtrue;
}

static VALUE p4_get_host( VALUE self )
{
P4ClientApi *p4;
Expand Down Expand Up @@ -642,7 +661,7 @@ static VALUE p4_run( VALUE self, VALUE args )

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

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

/*******************************************************************************
* SSO handler support
******************************************************************************/
static VALUE p4_get_enabled_sso( VALUE self )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->GetEnableSSO();
}

static VALUE p4_set_enable_sso( VALUE self, VALUE enable )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->SetEnableSSO( enable );
}

static VALUE p4_get_sso_vars( VALUE self )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->GetSSOVars();
}

static VALUE p4_get_sso_passresult( VALUE self )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->GetSSOPassResult();
}

static VALUE p4_set_sso_passresult( VALUE self, VALUE result )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->SetSSOPassResult( result );
}

static VALUE p4_get_sso_failresult( VALUE self )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->GetSSOFailResult();
}

static VALUE p4_set_sso_failresult( VALUE self, VALUE result )
{
P4ClientApi *p4;
Data_Get_Struct( self, P4ClientApi, p4 );
return p4->SetSSOFailResult( result );
}

/*******************************************************************************
* P4::MergeData methods. Construction/destruction defined elsewhere
******************************************************************************/
Expand Down Expand Up @@ -1262,6 +1333,8 @@ void Init_P4()
rb_define_method( cP4, "set_env", RUBY_METHOD_FUNC(p4_set_env) , 2 );
rb_define_method( cP4, "enviro_file", RUBY_METHOD_FUNC(p4_get_enviro_file), 0);
rb_define_method( cP4, "enviro_file=", RUBY_METHOD_FUNC(p4_set_enviro_file), 1);
rb_define_method( cP4, "evar", RUBY_METHOD_FUNC(p4_get_evar) , 1 );
rb_define_method( cP4, "set_evar", RUBY_METHOD_FUNC(p4_set_evar) , 2 );
rb_define_method( cP4, "host", RUBY_METHOD_FUNC(p4_get_host) , 0 );
rb_define_method( cP4, "host=", RUBY_METHOD_FUNC(p4_set_host) , 1 );
rb_define_method( cP4, "ignore_file",RUBY_METHOD_FUNC(p4_get_ignore) , 0 );
Expand Down Expand Up @@ -1335,6 +1408,16 @@ void Init_P4()
rb_define_method( cP4, "progress", RUBY_METHOD_FUNC(p4_get_progress), 0);
rb_define_method( cP4, "progress=", RUBY_METHOD_FUNC(p4_set_progress), 1);

// SSO handling
rb_define_method( cP4, "loginsso", RUBY_METHOD_FUNC(p4_get_enabled_sso), 0);
rb_define_method( cP4, "loginsso=", RUBY_METHOD_FUNC(p4_set_enable_sso), 1);
rb_define_method( cP4, "ssovars", RUBY_METHOD_FUNC(p4_get_sso_vars), 0);
rb_define_method( cP4, "ssopassresult", RUBY_METHOD_FUNC(p4_get_sso_passresult), 0);
rb_define_method( cP4, "ssopassresult=", RUBY_METHOD_FUNC(p4_set_sso_passresult), 1);
rb_define_method( cP4, "ssofailresult", RUBY_METHOD_FUNC(p4_get_sso_failresult), 0);
rb_define_method( cP4, "ssofailresult=", RUBY_METHOD_FUNC(p4_set_sso_failresult), 1);


// P4::MergeData class
cP4MD = rb_define_class_under( cP4, "MergeData", rb_cObject );

Expand Down
Loading

0 comments on commit be9b4f5

Please sign in to comment.