Index: /sandbox/webservice/api/library/Errors.php
===================================================================
--- /sandbox/webservice/api/library/Errors.php	(revision 5954)
+++ /sandbox/webservice/api/library/Errors.php	(revision 5954)
@@ -0,0 +1,64 @@
+<?php
+
+class Errors {
+		
+	// Errors from -32000 to -32099 => Server error	:Reserved for implementation-defined server-errors.
+	const E_PARSE_ERROR 		= "-32700";	
+	const E_INVALID_REQUEST 	= "-32600";
+	const E_METHOD_NOT_FOUND 	= "-32601";
+	const E_INVALID_PARAMS 		= "-32602";
+	const E_INTERNAL_ERROR 		= "-32603";	
+
+	// Errors inherited from Expresso Application.	
+	const LOGIN_SUCCESS_LOGOUT 			= "1";
+	const LOGIN_SESSION_EXPIRED 		= "2";
+	const LOGIN_NOT_LOGGED_IN 			= "3";
+	const LOGIN_COOKIES_REQUIRED 		= "4";
+	const LOGIN_BADLOGIN 				= "5";
+	const LOGIN_PASSWORD_EXPIRED 		= "6";
+	const LOGIN_AUTH_INVALID 			= "7";
+	const LOGIN_SESSION_NOT_VERIFIED 	= "10";
+	const LOGIN_ACCOUNT_EXPIRED 		= "98";
+	const LOGIN_LOGIN_BLOCKED 			= "99";
+	const LOGIN_INVALID_LOGIN 			= "200";
+
+	const CATALOG_MIN_ARGUMENT_SEARCH	= "1001";	
+	
+	static private $reservedErrors = array (			
+		self::E_PARSE_ERROR 		=> "Parse error",
+		self::E_INVALID_REQUEST 	=> "Invalid Request",
+		self::E_METHOD_NOT_FOUND 	=> "Method not found",
+		self::E_INVALID_PARAMS 		=> "Invalid params",
+		self::E_INTERNAL_ERROR		=> "Internal error"	
+	);
+	
+	
+	// Errors inherited from Expresso Application.
+	static private $applicationErrors = array(			
+
+		self::LOGIN_SUCCESS_LOGOUT 			=> "You have been successfully logged out",
+		self::LOGIN_SESSION_EXPIRED 		=> "Sorry, your login has expired",
+		self::LOGIN_NOT_LOGGED_IN 			=> "You are not logged in",
+		self::LOGIN_COOKIES_REQUIRED 		=> "Cookies are required to login to this site.",
+		self::LOGIN_BADLOGIN 				=> "bad login or password",
+		self::LOGIN_PASSWORD_EXPIRED 		=> "Your password has expired, and you do not have access to change it",
+		self::LOGIN_AUTH_INVALID			=> "Your auth is invalid",
+		self::LOGIN_SESSION_NOT_VERIFIED	=> "Your session could not be verified.",
+		self::LOGIN_ACCOUNT_EXPIRED 		=> "Account is expired",
+		self::LOGIN_LOGIN_BLOCKED			=> "Blocked, too many attempts!",
+		self::LOGIN_INVALID_LOGIN			=> "Bad login or password",
+		self::CATALOG_MIN_ARGUMENT_SEARCH	=> "Your search argument must be longer than %1 characters."
+			
+			
+	);
+		
+	static public function get($code, $jsonrpc = "2.0"){
+				
+		$errors = self::$reservedErrors + self::$applicationErrors;
+		if($jsonrpc == "2.0")
+			return array ("code" => $code, "message" => $errors[$code]);		
+		else
+			return $errors[$code];
+	}			
+		
+}
Index: /sandbox/webservice/api/library/HttpRequest.php
===================================================================
--- /sandbox/webservice/api/library/HttpRequest.php	(revision 5954)
+++ /sandbox/webservice/api/library/HttpRequest.php	(revision 5954)
@@ -0,0 +1,103 @@
+<?
+/** 
+* Access the HTTP Request 
+*/  
+class HttpRequest {  
+  
+    /** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */  
+    var $add_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH');  
+  
+    /** 
+    * Construtor 
+    * Retrieve HTTP Body 
+    * @param Array Additional Headers to retrieve 
+    */  
+    function HttpRequest($add_headers = false) {  
+      
+        $this->retrieve_headers($add_headers);  
+        $this->body = @file_get_contents('php://input');  
+    }  
+      
+    /** 
+    * Retrieve the HTTP request headers from the $_SERVER superglobal 
+    * @param Array Additional Headers to retrieve 
+    */  
+    function retrieve_headers($add_headers = false) {  
+          
+        if ($add_headers) {  
+            $this->add_headers = array_merge($this->add_headers, $add_headers);  
+        }  
+      
+        if (isset($_SERVER['HTTP_METHOD'])) {  
+            $this->method = $_SERVER['HTTP_METHOD'];  
+            unset($_SERVER['HTTP_METHOD']);  
+        } else {  
+            $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;  
+        }  
+        $this->protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false;  
+        $this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;  
+          
+        $this->headers = array();  
+        foreach($_SERVER as $i=>$val) {  
+            if (strpos($i, 'HTTP_') === 0 || in_array($i, $this->add_headers)) {  
+                $name = str_replace(array('HTTP_', '_'), array('', '-'), $i);  
+                $this->headers[$name] = $val;  
+            }  
+        }  
+    }  
+      
+    /**  
+    * Retrieve HTTP Method 
+    */  
+    function method() {  
+        return $this->method;  
+    }  
+      
+    /**  
+    * Retrieve HTTP Body 
+    */  
+    function body() {  
+        return $this->body;  
+    }  
+      
+    /**  
+    * Retrieve an HTTP Header 
+    * @param string Case-Insensitive HTTP Header Name (eg: "User-Agent") 
+    */  
+    function header($name) {  
+        $name = strtoupper($name);  
+        return isset($this->headers[$name]) ? $this->headers[$name] : false;  
+    }  
+      
+    /** 
+    * Retrieve all HTTP Headers  
+    * @return array HTTP Headers 
+    */  
+    function headers() {  
+        return $this->headers;  
+    }  
+      
+    /** 
+    * Return Raw HTTP Request (note: This is incomplete) 
+    * @param bool ReBuild the Raw HTTP Request 
+    */  
+    function raw($refresh = false) {  
+      
+        if (isset($this->raw) && !$refresh) {  
+            return $this->raw; // return cached  
+        }  
+      
+        $headers = $this->headers();  
+        $this->raw = "{$this->method}\r\n";  
+          
+        foreach($headers as $i=>$header) {  
+                $this->raw .= "$i: $header\r\n";  
+        }  
+          
+        $this->raw .= "\r\n{$this->body}";  
+          
+        return $this->raw;  
+    }  
+  
+}  
+?>
Index: /sandbox/webservice/api/webservice.php
===================================================================
--- /sandbox/webservice/api/webservice.php	(revision 5687)
+++ /sandbox/webservice/api/webservice.php	(revision 5954)
@@ -1,4 +1,3 @@
 <?php
-include_once("http_request.class.php");
 
 $public_functions = array(
@@ -22,4 +21,6 @@
 
 include_once('../header.inc.php');
+include_once("./library/HttpRequest.php");
+include_once("./library/Errors.php");
 
 // NO COOKIES!!!!
@@ -38,5 +39,5 @@
 	if(empty($request)) {
 		$request = array();
-		$http_request = new http_request();
+		$http_request = new HttpRequest();
 		$content_type = $http_request->header('Content-Type');
 		$accept = $http_request->header('Accept');
Index: /sandbox/webservice/api/json-rpc/Catalog.php
===================================================================
--- /sandbox/webservice/api/json-rpc/Catalog.php	(revision 5889)
+++ /sandbox/webservice/api/json-rpc/Catalog.php	(revision 5954)
@@ -4,14 +4,15 @@
 
 class Catalog extends Expresso {	
-	var $userPrefs;
+	var $searchCharactersNumber;
 	var $userId;
 
 	public function __construct(){
-		$this->userPrefs   = $this->getUserPreferences();
+		$prefs = $GLOBALS['phpgw']->preferences->read();
+		$this-> searchCharactersNumber = $prefs['expressoMail']['search_characters_number'];
 	}
 	
 	private function getUserId(){
 		$userProfile = $this->getUserProfile();
-		return $userProfile['account_id'];
+		return $userProfile['contactID'];
 	}
 	
@@ -29,8 +30,9 @@
 				}
 				elseif($params['contactType'] == 2){
-					if($this->userPrefs['search_characters_number'] <= strlen($search))
+					if($this-> searchCharactersNumber <= strlen($search))
 						return $this->getGlobalContacts($search, $params['contactID']);
 					else{
-						$this-> error = str_replace("%1",$this->userPrefs['search_characters_number'],"Your search argument must be longer than %1 characters.");
+						$this-> error =	Errors::get(Errors::CATALOG_MIN_ARGUMENT_SEARCH);
+						$this-> error = str_replace("%1",$this-> searchCharactersNumber,$this->error);
 						return $this->getResponse();
 					}
Index: /sandbox/webservice/api/json-rpc/Expresso.php
===================================================================
--- /sandbox/webservice/api/json-rpc/Expresso.php	(revision 5896)
+++ /sandbox/webservice/api/json-rpc/Expresso.php	(revision 5954)
@@ -49,10 +49,16 @@
 	
 	protected function isLoggedIn($params){
-		list($sessionid, $kp3) = explode(":", $params['auth']);
-		if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){									
-			return true;
+		if($params['auth'] != null) {
+			list($sessionid, $kp3) = explode(":", $params['auth']);
+			if($GLOBALS['phpgw']->session->verify($sessionid, $kp3)){									
+				return true;
+			}
+			else{
+				$this-> error = Errors::get(Errors::LOGIN_AUTH_INVALID);
+				return false;
+			}
 		}
 		else{
-			$this-> error = "You are not logged in";
+			$this-> error = Errors::get(Errors::LOGIN_NOT_LOGGED_IN);
 			return false;
 		}		
@@ -67,10 +73,5 @@
 		if(!$this-> isLoggedIn($params)) 
 		{				
-			if($params['auth'] != "") 
-			{	
-				$this->error  = "Your auth is invalid";
-				
-			}
-			elseif($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password']))					
+			if($sessionid = $GLOBALS['phpgw']->session->create($params['user'], $params['password']))					
 			{
 				$this->error  = null;
@@ -82,5 +83,5 @@
 			else
 			{				
-				$this-> error = $GLOBALS['phpgw']->session->reason;
+				$this-> error = Errors::get($GLOBALS['phpgw']->session->cd_reason);
 			}			
 		}
Index: ndbox/webservice/api/http_request.class.php
===================================================================
--- /sandbox/webservice/api/http_request.class.php	(revision 5595)
+++ 	(revision )
@@ -1,103 +1,0 @@
-<?
-/** 
-* Access the HTTP Request 
-*/  
-class http_request {  
-  
-    /** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */  
-    var $add_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH');  
-  
-    /** 
-    * Construtor 
-    * Retrieve HTTP Body 
-    * @param Array Additional Headers to retrieve 
-    */  
-    function http_request($add_headers = false) {  
-      
-        $this->retrieve_headers($add_headers);  
-        $this->body = @file_get_contents('php://input');  
-    }  
-      
-    /** 
-    * Retrieve the HTTP request headers from the $_SERVER superglobal 
-    * @param Array Additional Headers to retrieve 
-    */  
-    function retrieve_headers($add_headers = false) {  
-          
-        if ($add_headers) {  
-            $this->add_headers = array_merge($this->add_headers, $add_headers);  
-        }  
-      
-        if (isset($_SERVER['HTTP_METHOD'])) {  
-            $this->method = $_SERVER['HTTP_METHOD'];  
-            unset($_SERVER['HTTP_METHOD']);  
-        } else {  
-            $this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;  
-        }  
-        $this->protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false;  
-        $this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false;  
-          
-        $this->headers = array();  
-        foreach($_SERVER as $i=>$val) {  
-            if (strpos($i, 'HTTP_') === 0 || in_array($i, $this->add_headers)) {  
-                $name = str_replace(array('HTTP_', '_'), array('', '-'), $i);  
-                $this->headers[$name] = $val;  
-            }  
-        }  
-    }  
-      
-    /**  
-    * Retrieve HTTP Method 
-    */  
-    function method() {  
-        return $this->method;  
-    }  
-      
-    /**  
-    * Retrieve HTTP Body 
-    */  
-    function body() {  
-        return $this->body;  
-    }  
-      
-    /**  
-    * Retrieve an HTTP Header 
-    * @param string Case-Insensitive HTTP Header Name (eg: "User-Agent") 
-    */  
-    function header($name) {  
-        $name = strtoupper($name);  
-        return isset($this->headers[$name]) ? $this->headers[$name] : false;  
-    }  
-      
-    /** 
-    * Retrieve all HTTP Headers  
-    * @return array HTTP Headers 
-    */  
-    function headers() {  
-        return $this->headers;  
-    }  
-      
-    /** 
-    * Return Raw HTTP Request (note: This is incomplete) 
-    * @param bool ReBuild the Raw HTTP Request 
-    */  
-    function raw($refresh = false) {  
-      
-        if (isset($this->raw) && !$refresh) {  
-            return $this->raw; // return cached  
-        }  
-      
-        $headers = $this->headers();  
-        $this->raw = "{$this->method}\r\n";  
-          
-        foreach($headers as $i=>$header) {  
-                $this->raw .= "$i: $header\r\n";  
-        }  
-          
-        $this->raw .= "\r\n{$this->body}";  
-          
-        return $this->raw;  
-    }  
-  
-}  
-?>
