⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rest.pm

📁 Punjab is a jabber XMLRPC/SOAP/REST client. It is a xmlrpc, soap, or REST server that allows for p
💻 PM
📖 第 1 页 / 共 2 页
字号:
}sub vcard{    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $rest_transaction->params();    my $args   = $rest_transaction->args(); # maybe support this too?    my ($stdin)= &stdin_to_node($rest_transaction->stdin());    my $id = luniqid;    my $sid = $params->{'sid'};     my $jid = $params->{'jid'};      return if not defined $sid;    if ($punjab_session->check_session($sid)) {	$punjab_session->activity($sid,time());	$rest_transaction->request()->{'rest_type'} = 'vcard';	if ($rest_transaction->method() eq "GET") {	    $kernel->post($sid,'start_vcard', 'send_rest',			     $rest_transaction,$jid,$id);	    return;	} elsif ($rest_transaction->method() eq "POST") {	    $kernel->post($sid,'set_vcard', 'send_rest',			     $rest_transaction,$stdin,$id);	    return;	}	    } else {	$rest_transaction->error("Session does not exist");	return;    }}sub register{   # for in band registration    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $rest_transaction->params();    my $args   = $rest_transaction->args(); # maybe support this too?    my ($stdin)= &stdin_to_node($rest_transaction->stdin());        my $id = luniqid;    my $iq;    my $sid = $params->{'sid'};     return if not defined $sid;    if ($punjab_session->check_session($sid)) {	if ($rest_transaction->method() eq "GET") {	    $iq = POE::Filter::XML::Node->new('iq');	    $iq->attr('type',+IQ_GET);	    $iq->attr('id',$id);	    $iq->attr('to',$params->{'to'}) if defined $params->{'to'};	    $iq->attr('from',$params->{'from'}) if defined $params->{'from'};	    $iq->insert_tag('query',['xmlns',+NS_JABBER_REGISTER]);	    $kernel->post($sid,'send_xml',$iq);	    	    $rest_transaction->return(&str_to_node("<register/>"));	} elsif ($rest_transaction->method() eq "POST") {	    $rest_transaction->return(&str_to_node("<register/>"));	}    } else {	$rest_transaction->error("Session does not exist");	return;    }    return;}sub browse{    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $rest_transaction->params();    my $args   = $rest_transaction->args(); # maybe support this too?    my ($stdin)= &stdin_to_node($rest_transaction->stdin());    my $id    = luniqid;    my $sid   = $params->{'sid'};     my $jid   = $params->{'jid'};     my $auto  = $params->{'auto'}; # auto browse into objects    my $items = $params->{'items'}; # auto get item information    return if not defined $sid;            if ($punjab_session->check_session($sid)) {	$punjab_session->activity($sid,time());	$rest_transaction->request()->{'rest_type'} = 'browse';	$kernel->post($sid,'start_browse', 'return_browse',		      $rest_transaction,$id,$jid,$auto,$items);	 return;    } else {	$rest_transaction->error("Session does not exist");	return;    }}sub return_browse(){    my ($kernel,$session,$heap,$ret_val, $rest_transaction,$id,$jid,$sid) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1 .. ARG6];        if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());                if (not defined $heap->{'browse'}->{$sid}) {            $heap->{'browse'}->{$sid} = [];        }        if ($ret_val->attr('type') ne 'error') {            push(@{$heap->{'browse'}->{$sid}},$ret_val);        } else {            push(@{$heap->{'browse'}->{$sid}},undef);        }	if ($#{$heap->{'browse'}->{$sid}}>=2) {            # parse through the ret vals?            $kernel->yield('send_rest',$heap->{'browse'}->{$sid},$rest_transaction);            delete $heap->{'browse'}->{$sid};        }    } else {        $rest_transaction->error("Session does not exist");    }}sub pubsub{    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params  = $rest_transaction->params();    my $args    = $rest_transaction->args(); # maybe support this too?    my ($stdin) = &stdin_to_node($rest_transaction->stdin());    my $id      = luniqid;    my $sid     = $params->{'sid'};     my $to      = $params->{'to'};     return if not defined $sid;            if ($punjab_session->check_session($sid)) {	$punjab_session->activity($sid,time());	$rest_transaction->request()->{'rest_type'} = 'pubsub';		if ($rest_transaction->method() eq "GET") {	    my $piq = POE::Filter::XML::Node->new('iq');	    $piq->attr('type',+IQ_GET);	    $piq->attr('id',$id);	    	    	    if ($args->[0] eq "affiliations") {	    } elsif ($args->[0] eq "options") {	    	    } elsif ($args->[0] eq "items") {	    } elsif ($args->[0] eq "entities") {	    } elsif ($args->[0] eq "configure") {			    } else {		# send a disco for the node if node is set		#<query xmlns="http://jabber.org/protocol/disco#items" node="generic"/>	    }	    $rest_transaction->error("Not implemented");	    return;	} elsif ($rest_transaction->method() eq "POST") {	    	    my $piq = POE::Filter::XML::Node->new('iq');	    $piq->attr('type',+IQ_SET);	    $piq->attr('id',$id);	    	    	    if ($args->[0] eq "create") {	    } elsif ($args->[0] eq "publish") {	    } elsif ($args->[0] eq "retract") {	    } elsif ($args->[0] eq "subscribe") {	    } elsif ($args->[0] eq "unsubscribe") {	    } elsif ($args->[0] eq "command") {	    } elsif ($args->[0] eq "configure") {	    } elsif ($args->[0] eq "delete") {	    } elsif ($args->[0] eq "purge") {	    } elsif ($args->[0] eq "entities") {	    } elsif ($args->[0] eq "message") {		my $pm = POE::Filter::XML::Node->new('message');		$rest_transaction->error("Not implemented");		return;	    } 	    	    &debug($piq->to_str());	    $rest_transaction->error("Not implemented");	    return;	} else {	    #$kernel->post($sid,'start_pubsub', 'return_pubsub',	    #	      $rest_transaction,$id,$jid,$auto,$items);	    	    $rest_transaction->error("Not implemented");	}	return;    } else {	$rest_transaction->error("Session does not exist");	return;    }}sub return_pubsub(){    my ($kernel,$session,$heap,$ret_val, $rest_transaction,$id,$jid,$sid) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1 .. ARG6];        if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());                if (not defined $heap->{'pubsub'}->{$sid}) {            $heap->{'pubsub'}->{$sid} = [];        }        if ($ret_val->attr('type') ne 'error') {            push(@{$heap->{'pubsub'}->{$sid}},$ret_val);        } else {            push(@{$heap->{'pubsub'}->{$sid}},undef);        }	if ($#{$heap->{'pubsub'}->{$sid}}>=2) {            # parse through the ret vals?            $kernel->yield('send_rest',$heap->{'pubsub'}->{$sid},$rest_transaction);            delete $heap->{'pubsub'}->{$sid};        }    } else {        $rest_transaction->error("Session does not exist");    }}sub iqs{    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $rest_transaction->params();    my $args   = $rest_transaction->args();    my ($stdin)= &stdin_to_node($rest_transaction->stdin());       my $sid = $params->{'sid'};     my $iq_id = $params->{'id'};        return if not defined $sid;            my $iqs = POE::Filter::XML::Node->new('iqs');    my $pc        = $stdin->get_children();    if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());		if ($rest_transaction->method() eq "GET") {	    # grab the presence	    $rest_transaction->request()->{'rest_type'} = 'iqs';	    #if ($s) {		#$kernel->post('Manager'.$sid,'get_managed_iq',$iq_id,'stream_rest',$rest_transaction);	    #} else {		$kernel->post('Manager'.$sid,'get_managed_iq',$iq_id,'send_rest',$rest_transaction);			    #}	    return;	} elsif ($rest_transaction->method() eq "POST") {	    if (defined($pc)) {		# need to do more checks		foreach my $n (@$pc) {		    if ($n->name() eq "iq") {			$kernel->post($sid,'send_xml',$n);			$iqs->insert_tag($n);		    }		}	    } else {		$rest_transaction->error("Error in xml");		return;	    }	} 	$rest_transaction->return($iqs);	        } else {	$rest_transaction->error("Session does not exist");    } }sub ls {    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $rest_transaction->params();        my $resources = "<resources>";    #foreach  (keys %{$public_interfaces{'rest_shell'}}) {	#$resources .= "<resource href='".$rest_transaction->uri(1)."/".$_."'>".$_."</resource>";    #}        $resources .= "</resources>";    $rest_transaction->return(&str_to_node($resources));    }sub get_help{    my ($kernel,$heap) = @_[KERNEL, HEAP];    my $path = $heap->{'CONFIG'}->{'help'};    my $file;        if(defined($path))    {	$file = IO::File->new($path);	    } else {		$file = IO::File->new('./help/help.xml');    }        my $filter = POE::Filter::XML->new();    my @lines = $file->getlines();    my $nodes = $filter->get(\@lines);    splice(@$nodes,0,1);    # help hash is global    foreach my $node (@$nodes)    {	$help{$node->attr('id')} = $node if defined $node->attr('id');    }                }sub help{    my ($kernel,$heap,$session,$rest_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $args   = $rest_transaction->args();    my $tool   = $args->[0] if defined($args->[0]);    # reload help    $kernel->yield('get_help');    if ($rest_transaction->method() eq "GET") {	if (defined($tool)) {	    # query for the tool	    if (defined($help{$tool})) {		$rest_transaction->return($help{$tool});	    } else {		$rest_transaction->error("Help for $tool Not Found.");	    }	} else {	    # make this a PFX node?	    my $resources = "<resources>";	    #foreach (keys %{$public_interfaces{'rest_shell'}}) {		#$resources .= "<resource xlink:href='".$rest_transaction->uri(1)."/".$_."'>".$_."</resource>";	    #}	    $resources .= "</resources>";		    $rest_transaction->return(&str_to_node(qq[<help xmlns:xlink="http://www.w3.org/1999/xlink"> <name>help - an interface to the on-line reference manuals (similar to man)</name> <synopsis> finish me </synopsis> <description>Help is used for the systems documentation. Put more here. A help page consists of several parts. The elements are  &lt;name/&gt;, &lt;synonpsis/&gt;, &lt;description/&gt;, &lt;option/&gt;, &lt;resourcess/&gt;, &lt;also/&gt;, &lt;bugs/&gt;, &lt;author/&gt;, and &lt;location/&gt;. </description>  <examples>      http://localhost/help/date  </examples>  $resources </help>]));	}	return;    }    }# private functionssub send_rest {    my ($kernel,$session,$heap,$ret_val,$rest_trans) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1];    my $params = $rest_trans->params();    my $s    = $params->{'stream'};    &debug("HERE\n\n\n");    # this needs work    my $ret = POE::Filter::XML::Node->new($rest_trans->request()->{'rest_type'});    if(ref($ret_val) eq 'HASH') {	foreach my $h (keys %$ret_val) {	    my ($n) = $ret_val->{$h};	    $ret->insert_tag($n);	}    } elsif(ref($ret_val) eq 'ARRAY') {	if ($rest_trans->request()->{'rest_type'} eq "browse") {	    foreach my $r (@$ret_val) {		$ret->insert_tag($r) if defined $r;	    }	} else {	    foreach my $r (@$ret_val) {		$ret->insert_tag(&str_to_node($r->{'xml'})) if defined $r->{'xml'} and $r->{'xml'} ne "";	    }	}    } else {	if ($rest_trans->request()->{'rest_type'} eq "vcard") {	    if (defined($ret_val) and $ret_val ne "") {		if ($ret_val->attr('type') eq +IQ_ERROR) {		    $rest_trans->error($ret_val->get_tag('error')->data());		    return;		} else {		    my $v = $ret_val->get_tag('vCard');		    $v->attr('xmlns','') if defined $v;		    $ret = $v if defined $v;		}	    }	} else {	    if (defined($ret_val) and $ret_val ne "") {		if (defined $ret_val->attr('type') and $ret_val->attr('type') eq +IQ_ERROR) {		    $rest_trans->error($ret_val->get_tag('error')->data());		    return;		} else {		    $ret->insert_tag($ret_val);		}	    }	}    }    $rest_trans->return($ret);}sub check_timeout(){    my ($kernel,$session,$heap) =        @_[KERNEL, SESSION, HEAP];    my @keys = keys %{$punjab_session->registry()};    $heap->{'session_keys'} = \@keys;    $kernel->yield('check_timeout_continue');}sub check_timeout_continue(){    my ($kernel,$session,$heap) =        @_[KERNEL, SESSION, HEAP];    my $ctime = time();    my $s = pop(@{$heap->{'session_keys'}});    if (not defined $s) {        my $count = keys %{$punjab_session->registry()};        if ($count > 0) {            $kernel->delay('check_timeout', $heap->{'CONFIG'}->{'idle_check'});        }        return;    }    if (($ctime - $punjab_session->activity($s))>=$heap->{'CONFIG'}->{'timeout'}) {        $kernel->post($s,'disconnect');        $punjab_session->unregister($s);    }    $kernel->yield('check_timeout_continue');}1;__END__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -