var xmlrpc = require('xmlrpc'),
Url = require('url');

function api(host) {
  var hostParts = {};
        
  if(typeof host == 'string')
  {
      if (host.indexOf('http') !== 0) {
          host = 'http://' + host;
      }
      hostParts = Url.parse(host);
      
      if(hostParts.auth)
      {
          var authParts = hostParts.auth.split(':');
          hostParts.user = authParts[0];
          hostParts.pass = authParts[1];
      }
  }
  else if(host)
  {
      hostParts = host;
  }
  
  
  if(!hostParts.hostname) hostParts.hostname = 'localhost';
  if(!hostParts.port) hostParts.port = 9001;
  
  
  this.client = xmlrpc.createClient({
      host: hostParts.hostname,
      port: hostParts.port,
      path: '/RPC2',
      basic_auth: {
          user: hostParts.user,
          pass: hostParts.pass
      }
  });
}

api.prototype._call = function(method, args, callback)
{
    this.client.methodCall(method, args, callback);
};

['supervisor.addProcessGroup',
  'supervisor.clearAllProcessLogs',
  'supervisor.clearLog',
  'supervisor.clearProcessLog',
  'supervisor.clearProcessLogs',
  'supervisor.getAPIVersion',
  'supervisor.getAllConfigInfo',
  'supervisor.getAllProcessInfo',
  'supervisor.getIdentification',
  'supervisor.getPID',
  'supervisor.getProcessInfo',
  'supervisor.getState',
  'supervisor.getSupervisorVersion',
  'supervisor.getVersion',
  'supervisor.readLog',
  'supervisor.readMainLog',
  'supervisor.readProcessLog',
  'supervisor.readProcessStderrLog',
  'supervisor.readProcessStdoutLog',
  'supervisor.reloadConfig',
  'supervisor.removeProcessGroup',
  'supervisor.restart',
  'supervisor.sendProcessStdin',
  'supervisor.sendRemoteCommEvent',
  'supervisor.signalProcess',
  'supervisor.signalProcessGroup',
  'supervisor.shutdown',
  'supervisor.startAllProcesses',
  'supervisor.startProcess',
  'supervisor.startProcessGroup',
  'supervisor.stopAllProcesses',
  'supervisor.stopProcess',
  'supervisor.stopProcessGroup',
  'supervisor.tailProcessLog',
  'supervisor.tailProcessStderrLog',
  'supervisor.tailProcessStdoutLog',
  'system.listMethods',
  'system.methodHelp',
  'system.methodSignature',
  'system.multicall'].forEach(function(property){
  api.prototype[property.split('.').pop()] = function(){
    var args = Array.prototype.slice.call(arguments);
    callback = args.pop();
    this._call(property, args, callback);
  };
});

module.exports = api;

@@ -130,24 +130,141 @@
 tring')%0A  %7B%0A
+      if (host.indexOf('unix') === 0) %7B%0A%0A          hostParts.socketPath = Url.parse(host).pathname;%0A      %7Delse%7B%0A    
       if (ho
@@ -291,16 +291,20 @@
 == 0) %7B%0A
+    
         
@@ -336,18 +336,26 @@
 ;%0A      
+  
-%7D%0A
+  %7D%0A    
       ho
@@ -394,16 +394,20 @@
  %0A      
+    
 if(hostP
@@ -423,18 +423,26 @@
 )%0A      
+ 
-%7B%0A
+   %7B%0A    
         
@@ -486,16 +486,20 @@
 t(':');%0A
+    
         
@@ -533,32 +533,36 @@
 s%5B0%5D;%0A          
+    
 hostParts.pass =
@@ -576,16 +576,28 @@
 rts%5B1%5D;%0A
+          %7D%0A
       %7D%0A
@@ -764,17 +764,46 @@
 1;%0A  %0A  
-%0A
+if(hostParts.socketPath)%7B%0A    
   this.c
@@ -832,16 +832,150 @@
 lient(%7B%0A
+          socketPath: hostParts.socketPath,%0A          path: '/RPC2',%0A      %7D);%0A  %7Delse%7B%0A      this.client = xmlrpc.createClient(%7B%0A    
       ho
@@ -998,16 +998,20 @@
 stname,%0A
+    
       po
@@ -1032,24 +1032,28 @@
 port,%0A      
+ 
+   
 path: '/RPC2
@@ -1061,16 +1061,20 @@
 ,%0A      
+  
+  
 basic_au
@@ -1079,16 +1079,20 @@
 auth: %7B%0A
+    
         
@@ -1125,16 +1125,20 @@
         
+    
 pass: ho
@@ -1160,15 +1160,27 @@
     
+ 
+   
 %7D%0A  
-%7D);
+    %7D);%0A  %7D
 %0A%7D%0A%0A

add unix socket support