Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Nohmad;
- use Modern::Perl '2012';
- use DateTime;
- use MIME::Base64;
- use Log::Log4perl;
- use bytes;
- use Database;
- #-------------------------------------------------------------------------------
- # Initialize logger
- #-------------------------------------------------------------------------------
- Log::Log4perl::init("log4perl.conf");
- my $logger = Log::Log4perl->get_logger();
- $Log::Log4perl::JOIN_MSG_ARRAY_CHAR = " <*> ";
- #=== FUNCTION ================================================================
- # NAME: packet
- # PURPOSE: Entry point and main function
- # PARAMETERS: $heap : POE session heap
- # $buf : content of a package, raw binary data
- # $devices : list of devices with active sessions and their data
- # $sid : POE session ID
- # RETURNS: $reply
- # DESCRIPTION: Main function that calls sub functions
- # THROWS: no exceptions
- # COMMENTS: none
- # SEE ALSO: n/a
- #===============================================================================
- sub packet {
- my ( $heap, $buf, $devices, $sid ) = @_;
- my ( @header ) = unpack("H2" x 3, $buf);
- my $msg_len = hex shift @header;
- my $pkg_id = hex shift @header;
- my $pkg_type = shift @header;
- my $pkg = substr $buf, 3;
- my $reply;
- given ($pkg_type) {
- when ('00') { $reply = _error( $heap, $pkg ); }
- when ('01') { $reply = _identification( $heap, $pkg, $devices, $sid ); }
- when ('02') { $reply = _hello( $heap, $pkg ); }
- when ('03') { $reply = _fingerprint_receipt( $heap, $pkg, $pkg_id ); }
- when ('10') { $reply = _transactions( $heap, $pkg, $pkg_id ); }
- when ('20') { $reply = _enrol_result( $pkg, $pkg_id, $heap ); }
- when ('21') { $reply = _templates( $pkg, $pkg_id, $heap->{imei} ); }
- when ('22') { $reply = _enrolment_complete( $heap, $pkg_id ); }
- when ('fe') { $reply = _enrol_request_admin( $devices, $pkg ); }
- when ('ff') { $reply = _update_firmware( $heap, $pkg ); }
- default {
- #-------------------------------------------------------------------------------
- # LOGLEVEL ERROR
- #-------------------------------------------------------------------------------
- $logger->error( "Unknown type: " . unpack( "(H2)*", $pkg ),
- $heap->{imei} || '' );
- }
- }
- return $reply;
- }
- <!-- snip -->
- sub _pending_jobs {
- my ( $heap ) = @_;
- _check_stale_lock( $heap );
- if ( exists $heap->{block_processing} ) {
- $heap->{socket_wheel}->put( $heap->{blocked_payload} )
- if exists $heap->{blocked_payload};
- #-------------------------------------------------------------------------------
- # LOGLEVEL DEBUG
- #-------------------------------------------------------------------------------
- $logger->debug( "=[HELLO] NOAC block processing =", $heap->{imei} )
- if $heap->{block_processing};
- return;
- }
- if ( exists $heap->{pending_processes} ) {
- #-------------------------------------------------------------------------------
- # LOGLEVEL DEBUG
- #-------------------------------------------------------------------------------
- $logger->debug( "=[HELLO] NOAC pending processes =", $heap->{imei} )
- if exists $heap->{pending_processes};
- return;
- }
- #Run the check
- return Database::_check4pending( $heap->{imei} );
- }
- <!-- snip -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement