--- get_server/get_server.module	2007-12-18 11:31:58.000000000 +1100
+++ ./get_server.module	2008-04-08 10:03:09.000000000 +1000
@@ -1,5 +1,5 @@
-<?php
-// $Id: get_server.module,v 1.5 2007/12/18 00:31:58 sime Exp $
+<?
+// $CVS$
 
 function get_server_server_info() {
   return array(
@@ -23,6 +23,7 @@
   // Get Server leverages existing rending code for the return data.
   // We look for a protocol name like 'xml' or 'json' (amfphp not supported here).
   $protocol = array_shift($args);
+  
 
   foreach ($method['#args'] AS $key => $argument) {
     
@@ -38,12 +39,31 @@
       default :
         $return[$key] = $args[$key];
     }
-  }
+  }  
+
   $result = services_method_call($method['#method'], $return);
-  $response = get_server_encode_response($protocol, $result);
+
+  $response = null;
+  
+  foreach (module_implements('services_encode_response') as $module) {
+    $function = $module .'_services_encode_response';
+    if($output = $function($protocol, $result, $method)) {
+      $response = $output;
+    }
+  }
+  
+  if(!$response) {
+      // Assume testing
+      $response = "<p>No renderer available for '$protocol', should be 'xml' or 'json'.</p>";
+      $response .= "<pre>". print_r($result, TRUE) ."</pre>";
+  }
+  
+  print $response;
+  exit;
 }
 
-function get_server_encode_response($protocol, $result) {
+function get_server_services_encode_response($protocol, $result, $method) {
+  
   switch ($protocol) {
     case 'xml':
     case 'xmlrpc':    
@@ -66,22 +86,16 @@
       return;
 
     case 'json':
-      print drupal_to_js(array('#error' => FALSE, '#data' => $result));
-      return;
+      return drupal_to_js(array('#error' => FALSE, '#data' => $result));
 
     case 'print':
+    case 'rss':
       if (is_array($result)) {
-        print_r($result);
+        return print_r($result,true);
       }
       else {
-        print $result;
-        return;
+        return $result;
       }
-
-    default:
-      // Assume testing
-      print "<p>No renderer available for '$protocol', should be 'xml' or 'json'.</p>";
-      print "<pre>". print_r($result, TRUE) ."</pre>";
   }      
 }
 
@@ -147,8 +161,3 @@
     return theme('page', $return);
   }  
 }
-
-
-
-
-
