fix logo encoding over xml-api for all functions that call skin_info internally,...
[freeside.git] / fs_selfservice / FS-SelfService / SelfService / XMLRPC.pm
index 4e0d3e9..506dce1 100644 (file)
@@ -26,19 +26,61 @@ L<freeside-selfservice-clientd>, L<freeside-selfservice-server>,L<FS::SelfServic
 
 use strict;
 use vars qw($DEBUG $AUTOLOAD);
+use XMLRPC::Lite; # for XMLRPC::Data
 use FS::SelfService;
 
 $DEBUG = 0;
 $FS::SelfService::DEBUG = $DEBUG;
 
+#false laziness w/FS::ClientAPI_XMLRPC.pm
+our %typefix_skin_info = (
+  'logo'              => 'base64',
+  'title_left_image'  => 'base64',
+  'title_right_image' => 'base64',
+  'menu_top_image'    => 'base64',
+  'menu_body_image'   => 'base64',
+  'menu_bottom_image' => 'base64',
+);
+our %typefix = (
+  'invoice_pdf'          => { 'invoice_pdf' => 'base64', },
+  'legacy_invoice_pdf'   => { 'invoice_pdf' => 'base64', },
+  'skin_info'            => \%typefix_skin_info,
+  'login_info'           => \%typefix_skin_info,
+  'logout'               => \%typefix_skin_info,
+  'access_info'          => \%typefix_skin_info,
+  'reset_passwd'         => \%typefix_skin_info,
+  'check_reset_passwd'   => \%typefix_skin_info,
+  'process_reset_passwd' => \%typefix_skin_info,
+  'invoice_logo'         => { 'logo'  => 'base64', },
+  'login_banner_image'   => { 'image' => 'base64', },
+  'quotation_print'      => { 'document' => 'base64' },
+);
+
 sub AUTOLOAD {
   my $call = $AUTOLOAD;
   $call =~ s/^FS::SelfService::XMLRPC:://;
+
   if (exists($FS::SelfService::autoload{$call})) {
+
     shift; #discard package name;
+
     $call = "FS::SelfService::$call";
+
     no strict 'refs';
-    &{$call}(@_);
+
+    my $return = &{$call}(@_);
+
+    if ( exists($typefix{$call}) ) {
+      my $typefix = $typefix{$call};
+      foreach my $field ( grep exists($return->{$_}), keys %$typefix ) {
+        my $type = $typefix->{$field};
+        $return->{$field} = XMLRPC::Data->value($return->{$field})
+                                        ->type($type);
+      }
+    }
+
+    $return;
+
   }else{
     die "No such procedure: $call";
   }