[Opensrf-commits] r2209 - trunk/src/javascript (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Mar 13 01:03:49 EST 2011


Author: dbs
Date: 2011-03-13 01:03:46 -0500 (Sun, 13 Mar 2011)
New Revision: 2209

Modified:
   trunk/src/javascript/DojoSRF.js
   trunk/src/javascript/JSON_v0.js
   trunk/src/javascript/JSON_v1.js
   trunk/src/javascript/opensrf.js
   trunk/src/javascript/opensrf_xhr.js
   trunk/src/javascript/opensrf_xmpp.js
Log:
Run OpenSRF JavaScript through jslint for a light cleanup

Mostly just semicolons, and shifting a bit of code around to reduce
usage of functions/classes before they've been defined. Staying away
from the === / !== operators for null/undefined/0/''/true/false for
now.


Modified: trunk/src/javascript/DojoSRF.js
===================================================================
--- trunk/src/javascript/DojoSRF.js	2011-03-11 13:15:57 UTC (rev 2208)
+++ trunk/src/javascript/DojoSRF.js	2011-03-13 06:03:46 UTC (rev 2209)
@@ -1,32 +1,32 @@
 if(!dojo._hasResource['DojoSRF']){
 
-	dojo._hasResource['DojoSRF'] = true;
-	dojo.provide('DojoSRF');
-	dojo.provide('OpenSRF');
+    dojo._hasResource['DojoSRF'] = true;
+    dojo.provide('DojoSRF');
+    dojo.provide('OpenSRF');
 
-	// Note: this file was renamed from OpenSRF.js to DojoSRF.js,
-	// but still provides resources with the OpenSRF namespace
-	dojo.require('opensrf.md5', true);
-	dojo.require('opensrf.JSON_v1', true);
-	dojo.require('opensrf.opensrf', true);
-	dojo.require('opensrf.opensrf_xhr', true);
+    // Note: this file was renamed from OpenSRF.js to DojoSRF.js,
+    // but still provides resources with the OpenSRF namespace
+    dojo.require('opensrf.md5', true);
+    dojo.require('opensrf.JSON_v1', true);
+    dojo.require('opensrf.opensrf', true);
+    dojo.require('opensrf.opensrf_xhr', true);
 
-	OpenSRF.session_cache = {};
-	OpenSRF.CachedClientSession = function ( app ) {
-		if (this.session_cache[app]) return this.session_cache[app];
-		this.session_cache[app] = new OpenSRF.ClientSession ( app );
-		return this.session_cache[app];
-	}
+    OpenSRF.session_cache = {};
+    OpenSRF.CachedClientSession = function ( app ) {
+        if (this.session_cache[app]) return this.session_cache[app];
+        this.session_cache[app] = new OpenSRF.ClientSession ( app );
+        return this.session_cache[app];
+    };
 
-        localeRE = /^(\w\w)(-\w\w)?$/;
-        localeMatch = localeRE.exec(dojo.locale);
+    localeRE = /^(\w\w)(-\w\w)?$/;
+    localeMatch = localeRE.exec(dojo.locale);
 
-        if (!localeMatch || !localeMatch[1]) {
-                OpenSRF.locale = dojo.isIE ? navigator.userLanguage : navigator.language;
-        } else {
-                OpenSRF.locale = localeMatch[1].toLowerCase();
-        }
-        if (localeMatch && localeMatch[2]) {
-                OpenSRF.locale = OpenSRF.locale + localeMatch[2].toUpperCase();
-        }
+    if (!localeMatch || !localeMatch[1]) {
+        OpenSRF.locale = dojo.isIE ? navigator.userLanguage : navigator.language;
+    } else {
+        OpenSRF.locale = localeMatch[1].toLowerCase();
+    }
+    if (localeMatch && localeMatch[2]) {
+        OpenSRF.locale = OpenSRF.locale + localeMatch[2].toUpperCase();
+    }
 }

Modified: trunk/src/javascript/JSON_v0.js
===================================================================
--- trunk/src/javascript/JSON_v0.js	2011-03-11 13:15:57 UTC (rev 2208)
+++ trunk/src/javascript/JSON_v0.js	2011-03-13 06:03:46 UTC (rev 2209)
@@ -2,134 +2,134 @@
 var undefined;
 
 function Cast (obj, class_constructor) {
-	try {
-		if (eval(class_constructor + '["_isfieldmapper"]')) {
-			obj = eval("new " + class_constructor + "(obj)");
-		}
-	} catch( E ) {
-		alert( E + "\n");
-	} finally {
-		return obj;
-	}
+    try {
+        if (eval(class_constructor + '["_isfieldmapper"]')) {
+            obj = eval("new " + class_constructor + "(obj)");
+        }
+    } catch( E ) {
+        alert( E + "\n");
+    } finally {
+        return obj;
+    }
 }
 
 function JSON2js (json) {
 
-	json = String(json).replace( /\/\*--\s*S\w*?\s*?\s+\w+\s*--\*\//g, 'Cast(');
-	json = String(json).replace( /\/\*--\s*E\w*?\s*?\s+(\w+)\s*--\*\//g, ', "$1")');
+    json = String(json).replace( /\/\*--\s*S\w*?\s*?\s+\w+\s*--\*\//g, 'Cast(');
+    json = String(json).replace( /\/\*--\s*E\w*?\s*?\s+(\w+)\s*--\*\//g, ', "$1")');
 
-	var obj;
-	if (json != '') {
-		try {
-			eval( 'obj = ' + json );
-		} catch(E) {
-			debug("Error building JSON object with string " + E + "\nString:\n" + json );
-			return null;
-		}
-	}
-	return obj;
+    var obj;
+    if (json != '') {
+        try {
+            eval( 'obj = ' + json );
+        } catch(E) {
+            debug("Error building JSON object with string " + E + "\nString:\n" + json );
+            return null;
+        }
+    }
+    return obj;
 }
 
 
 function object2Array(obj) {
-	if( obj == null ) return null;
+    if( obj == null ) return null;
 
-	var arr = new Array();
-	for( var i  = 0; i < obj.length; i++ ) {
-		arr[i] = obj[i];
-	}
-	return arr;
+    var arr = [];
+    for( var i  = 0; i < obj.length; i++ ) {
+        arr[i] = obj[i];
+    }
+    return arr;
 }
 
 
 function js2JSON(arg) {
-	return _js2JSON(arg);
+    return _js2JSON(arg);
 }
 
 function _js2JSON(arg) {
-	var i, o, u, v;
+    var i, o, u, v;
 
-		switch (typeof arg) {
-			case 'object':
-	
-				if(arg) {
-	
-					if (arg._isfieldmapper) { /* magi-c-ast for fieldmapper objects */
-	
-						if( arg.a.constructor != Array ) {
-							var arr = new Array();
-							for( var i  = 0; i < arg.a.length; i++ ) {
-								if( arg.a[i] == null ) {
-									arr[i] = null; continue;
-								}
-	
-								if( typeof arg.a[i] != 'object' ) { 
-									arr[i] = arg.a[i];
-	
-								} else if( typeof arg.a[i] == 'object' 
-											&& arg.a[i]._isfieldmapper) {
-	
-									arr[i] = arg.a[i];
-	
-								} else {
-									arr[i] = object2Array(arg.a[i]);		
-								}
-							}
-							arg.a = arr;
-						}
-	
-						return "/*--S " + arg.classname + " --*/" + js2JSON(arg.a) + "/*--E " + arg.classname + " --*/";
-	
-					} else {
-	
-						if (arg.constructor == Array) {
-							o = '';
-							for (i = 0; i < arg.length; ++i) {
-								v = js2JSON(arg[i]);
-								if (o) {
-									o += ',';
-								}
-								if (v !== u) {
-									o += v;
-								} else {
-									o += 'null';
-								}
-							}
-							return '[' + o + ']';
-	
-						} else if (typeof arg.toString != 'undefined') {
-							o = '';
-							for (i in arg) {
-								v = js2JSON(arg[i]);
-								if (v !== u) {
-									if (o) {
-										o += ',';
-									}
-									o += js2JSON(i) + ':' + v;
-								}
-							}
-	
-							o = '{' + o + '}';
-							return o;
-	
-						} else {
-							return;
-						}
-					}
-				}
-				return 'null';
-	
-			case 'unknown':
-			case 'number':
-				return arg;
-	
-			case 'undefined':
-			case 'function':
-				return u;
-	
-			case 'string':
-			default:
-				return '"' + String(arg).replace(/(["\\])/g, '\\$1') + '"';
-		}
+        switch (typeof arg) {
+            case 'object':
+    
+                if(arg) {
+    
+                    if (arg._isfieldmapper) { /* magi-c-ast for fieldmapper objects */
+    
+                        if( arg.a.constructor != Array ) {
+                            var arr = []; 
+                            for( var i  = 0; i < arg.a.length; i++ ) {
+                                if( arg.a[i] == null ) {
+                                    arr[i] = null; continue;
+                                }
+    
+                                if( typeof arg.a[i] != 'object' ) { 
+                                    arr[i] = arg.a[i];
+    
+                                } else if( typeof arg.a[i] == 'object' 
+                                            && arg.a[i]._isfieldmapper) {
+    
+                                    arr[i] = arg.a[i];
+    
+                                } else {
+                                    arr[i] = object2Array(arg.a[i]);        
+                                }
+                            }
+                            arg.a = arr;
+                        }
+    
+                        return "/*--S " + arg.classname + " --*/" + js2JSON(arg.a) + "/*--E " + arg.classname + " --*/";
+    
+                    } else {
+    
+                        if (arg.constructor == Array) {
+                            o = '';
+                            for (i = 0; i < arg.length; ++i) {
+                                v = js2JSON(arg[i]);
+                                if (o) {
+                                    o += ',';
+                                }
+                                if (v !== u) {
+                                    o += v;
+                                } else {
+                                    o += 'null';
+                                }
+                            }
+                            return '[' + o + ']';
+    
+                        } else if (typeof arg.toString != 'undefined') {
+                            o = '';
+                            for (i in arg) {
+                                v = js2JSON(arg[i]);
+                                if (v !== u) {
+                                    if (o) {
+                                        o += ',';
+                                    }
+                                    o += js2JSON(i) + ':' + v;
+                                }
+                            }
+    
+                            o = '{' + o + '}';
+                            return o;
+    
+                        } else {
+                            return;
+                        }
+                    }
+                }
+                return 'null';
+    
+            case 'unknown':
+            case 'number':
+                return arg;
+    
+            case 'undefined':
+            case 'function':
+                return u;
+    
+            case 'string':
+            default:
+                return '"' + String(arg).replace(/(["\\])/g, '\\$1') + '"';
+        }
 
 }

Modified: trunk/src/javascript/JSON_v1.js
===================================================================
--- trunk/src/javascript/JSON_v1.js	2011-03-11 13:15:57 UTC (rev 2208)
+++ trunk/src/javascript/JSON_v1.js	2011-03-13 06:03:46 UTC (rev 2209)
@@ -1,221 +1,221 @@
-var JSON_CLASS_KEY	= '__c';
-var JSON_DATA_KEY	= '__p';
+var JSON_CLASS_KEY    = '__c';
+var JSON_DATA_KEY    = '__p';
 
 
 
-function JSON_version() { return 'wrapper' }
+function JSON_version() { return 'wrapper'; }
 
 function JSON2js(text) {
-	return decodeJS(JSON2jsRaw(text));
+    return decodeJS(JSON2jsRaw(text));
 }
 
 JSON2js.fallbackObjectifier = null;
 
 function JSON2jsRaw(text) {
-	var obj;
-	eval('obj = ' + text);
-	return obj;
+    var obj;
+    eval('obj = ' + text);
+    return obj;
 }
 
 
 /* iterates over object, arrays, or fieldmapper objects */
 function jsIterate( arg, callback ) {
-	if( arg && typeof arg == 'object' ) {
-		if( arg.constructor == Array ) {
-			for( var i = 0; i < arg.length; i++ ) 
-				callback(arg, i);
+    if( arg && typeof arg == 'object' ) {
+        if( arg.constructor == Array ) {
+            for( var i = 0; i < arg.length; i++ ) 
+                callback(arg, i);
 
-		}  else if( arg.constructor == Object ) {
-				for( var i in arg ) 
-					callback(arg, i);
+        }  else if( arg.constructor == Object ) {
+                for( var i in arg ) 
+                    callback(arg, i);
 
-		} else if( arg._isfieldmapper && arg.a ) {
-			for( var i = 0; i < arg.a.length; i++ ) 
-				callback(arg.a, i);
-		}
-	}
+        } else if( arg._isfieldmapper && arg.a ) {
+            for( var i = 0; i < arg.a.length; i++ ) 
+                callback(arg.a, i);
+        }
+    }
 }
 
 
 /* removes the class/paylod wrapper objects */
 function decodeJS(arg) {
 
-	if(arg == null) return null;
+    if(arg == null) return null;
 
-	if(	arg && typeof arg == 'object' &&
-			arg.constructor == Object &&
-			arg[JSON_CLASS_KEY] ) {
+    if(    arg && typeof arg == 'object' &&
+            arg.constructor == Object &&
+            arg[JSON_CLASS_KEY] ) {
 
         try {
-            arg = eval('new ' + arg[JSON_CLASS_KEY] + '(arg[JSON_DATA_KEY])');	
+            arg = eval('new ' + arg[JSON_CLASS_KEY] + '(arg[JSON_DATA_KEY])');    
         } catch(E) {
             if (JSON2js.fallbackObjectifier)
                 arg = JSON2js.fallbackObjectifier(arg, JSON_CLASS_KEY, JSON_DATA_KEY );
         }
 
-	}
+    }
 
     if(arg._encodehash) {
-	    jsIterate( arg.hash, 
-		    function(o, i) {
-			    o[i] = decodeJS(o[i]);
-		    }
-	    );
+        jsIterate( arg.hash, 
+            function(o, i) {
+                o[i] = decodeJS(o[i]);
+            }
+        );
     } else {
-	    jsIterate( arg, 
-		    function(o, i) {
-			    o[i] = decodeJS(o[i]);
-		    }
-	    );
+        jsIterate( arg, 
+            function(o, i) {
+                o[i] = decodeJS(o[i]);
+            }
+        );
     }
 
-	return arg;
+    return arg;
 }
 
 
 function jsClone(obj) {
-	if( obj == null ) return null;
-	if( typeof obj != 'object' ) return obj;
+    if( obj == null ) return null;
+    if( typeof obj != 'object' ) return obj;
 
-	var newobj;
-	if (obj.constructor == Array) {
-		newobj = [];
-		for( var i = 0; i < obj.length; i++ ) 
-			newobj[i] = jsClone(obj[i]);
+    var newobj;
+    if (obj.constructor == Array) {
+        newobj = [];
+        for( var i = 0; i < obj.length; i++ ) 
+            newobj[i] = jsClone(obj[i]);
 
-	} else if( obj.constructor == Object ) {
-		newobj = {};
-		for( var i in obj )
-			newobj[i] = jsClone(obj[i]);
+    } else if( obj.constructor == Object ) {
+        newobj = {};
+        for( var i in obj )
+            newobj[i] = jsClone(obj[i]);
 
-	} else if( obj._isfieldmapper && obj.a ) {
-		eval('newobj = new '+obj.classname + '();');
-		for( var i = 0; i < obj.a.length; i++ ) 
-			newobj.a[i] = jsClone(obj.a[i]);
-	}
+    } else if( obj._isfieldmapper && obj.a ) {
+        eval('newobj = new '+obj.classname + '();');
+        for( var i = 0; i < obj.a.length; i++ ) 
+            newobj.a[i] = jsClone(obj.a[i]);
+    }
 
-	return newobj;
+    return newobj;
 }
-	
+    
 
-/* adds the class/paylod wrapper objects */
+/* adds the class/payload wrapper objects */
 function encodeJS(arg) {
-	if( arg == null ) return null;	
-	if( typeof arg != 'object' ) return arg;
+    if( arg == null ) return null;    
+    if( typeof arg != 'object' ) return arg;
 
-	if( arg._isfieldmapper ) {
-      var newarr = []
+    if( arg._isfieldmapper ) {
+      var newarr = [];
       if(!arg.a) arg.a = [];
-		for( var i = 0; i < arg.a.length; i++ ) 
-			newarr[i] = encodeJS(arg.a[i]);
+      for( var i = 0; i < arg.a.length; i++ ) 
+          newarr[i] = encodeJS(arg.a[i]);
 
-		var a = {};
-		a[JSON_CLASS_KEY] = arg.classname;
-		a[JSON_DATA_KEY] = newarr;
+      var a = {};
+      a[JSON_CLASS_KEY] = arg.classname;
+      a[JSON_DATA_KEY] = newarr;
       return a;
-	}
+    }
 
-	var newobj;
+    var newobj;
 
-	if(arg.length != undefined) {
-		newobj = [];
-		for( var i = 0; i < arg.length; i++ ) 
-         newobj.push(encodeJS(arg[i]));
-      return newobj;
-	} 
+    if(arg.length != undefined) {
+        newobj = [];
+        for( var i = 0; i < arg.length; i++ ) 
+            newobj.push(encodeJS(arg[i]));
+        return newobj;
+    } 
    
-	newobj = {};
-	for( var i in arg )
-		newobj[i] = encodeJS(arg[i]);
-	return newobj;
+    newobj = {};
+    for( var i in arg )
+        newobj[i] = encodeJS(arg[i]);
+    return newobj;
 }
 
 /* turns a javascript object into a JSON string */
 function js2JSON(arg) {
-	return js2JSONRaw(encodeJS(arg));
+    return js2JSONRaw(encodeJS(arg));
 }
 
 function js2JSONRaw(arg) {
 
-	if( arg == null ) 
-		return 'null';
+    if( arg == null ) 
+        return 'null';
 
-	var o;
+    var o;
 
-	switch (typeof arg) {
+    switch (typeof arg) {
 
-		case 'object':
+        case 'object':
 
-			if (arg.constructor == Array) {
-				o = '';
-				jsIterate( arg,
-					function(obj, i) {
-						if (o) o += ',';
-						o += js2JSONRaw(obj[i]);
-					}
-				);
-				return '[' + o + ']';
+            if (arg.constructor == Array) {
+                o = '';
+                jsIterate( arg,
+                    function(obj, i) {
+                        if (o) o += ',';
+                        o += js2JSONRaw(obj[i]);
+                    }
+                );
+                return '[' + o + ']';
 
-			} else if (typeof arg.toString != 'undefined') {
-				o = '';
-				jsIterate( arg,
-					function(obj, i) {
-						if (o) o += ',';
-						o = o + js2JSONRaw(i) + ':' + js2JSONRaw(obj[i]);
-					}
-				);
-				return '{' + o + '}';
+            } else if (typeof arg.toString != 'undefined') {
+                o = '';
+                jsIterate( arg,
+                    function(obj, i) {
+                        if (o) o += ',';
+                        o = o + js2JSONRaw(i) + ':' + js2JSONRaw(obj[i]);
+                    }
+                );
+                return '{' + o + '}';
 
-			} else {
-				return 'null';
-			}
+            }
 
-		case 'number': return arg;
+            return 'null';
 
-		case 'string':
-			var s = String(arg);
-			s = s.replace(/\\/g, '\\\\');
-			s = s.replace(/"/g, '\\"');
-			s = s.replace(/\t/g, "\\t");
-			s = s.replace(/\n/g, "\\n");
-			s = s.replace(/\r/g, "\\r");
-			s = s.replace(/\f/g, "\\f");
-			return '"' + s + '"';
+        case 'number': return arg;
 
+        case 'string':
+            var s = String(arg);
+            s = s.replace(/\\/g, '\\\\');
+            s = s.replace(/"/g, '\\"');
+            s = s.replace(/\t/g, "\\t");
+            s = s.replace(/\n/g, "\\n");
+            s = s.replace(/\r/g, "\\r");
+            s = s.replace(/\f/g, "\\f");
+            return '"' + s + '"';
+
         case 'boolean':
             return (arg) ? 'true' : 'false';
 
-		default: return 'null';
-	}
+        default: return 'null';
+    }
 }
 
 
 function __tabs(c) { 
-	var s = ''; 
-	for( i = 0; i < c; i++ ) s += '\t';
-	return s;
+    var s = ''; 
+    for( i = 0; i < c; i++ ) s += '\t';
+    return s;
 }
 
 function jsonPretty(str) {
-	if(!str) return "";
-	var s = '';
-	var d = 0;
-	for( var i = 0; i < str.length; i++ ) {
-		var c = str.charAt(i);
-		if( c == '{' || c == '[' ) {
-			s += c + '\n' + __tabs(++d);
-		} else if( c == '}' || c == ']' ) {
-			s += '\n' + __tabs(--d) + '\n';
-			if( str.charAt(i+1) == ',' ) {
-				s += '\n' + __tabs(d);
-			}
-		} else if( c == ',' ) {
-			s += ',\n' + __tabs(d);
-		} else {
-			s += c;
-		}
-	}
-	return s;
+    if(!str) return "";
+    var s = '';
+    var d = 0;
+    for( var i = 0; i < str.length; i++ ) {
+        var c = str.charAt(i);
+        if( c == '{' || c == '[' ) {
+            s += c + '\n' + __tabs(++d);
+        } else if( c == '}' || c == ']' ) {
+            s += '\n' + __tabs(--d) + '\n';
+            if( str.charAt(i+1) == ',' ) {
+                s += '\n' + __tabs(d);
+            }
+        } else if( c == ',' ) {
+            s += ',\n' + __tabs(d);
+        } else {
+            s += c;
+        }
+    }
+    return s;
 }
 
 

Modified: trunk/src/javascript/opensrf.js
===================================================================
--- trunk/src/javascript/opensrf.js	2011-03-11 13:15:57 UTC (rev 2208)
+++ trunk/src/javascript/opensrf.js	2011-03-13 06:03:46 UTC (rev 2209)
@@ -46,6 +46,146 @@
 var OSRF_STATUS_NOTIMPLEMENTED = 501;
 var OSRF_STATUS_VERSIONNOTSUPPORTED = 505;
 
+/* The following classes map directly to network-serializable opensrf objects */
+
+function osrfMessage(hash) {
+    this.hash = hash;
+    if(!this.hash.locale)
+        this.hash.locale = OpenSRF.locale || 'en-US';
+    this._encodehash = true;
+}
+osrfMessage.prototype.threadTrace = function(d) { 
+    if(arguments.length == 1) 
+        this.hash.threadTrace = d; 
+    return this.hash.threadTrace; 
+};
+osrfMessage.prototype.type = function(d) { 
+    if(arguments.length == 1) 
+        this.hash.type = d; 
+    return this.hash.type; 
+};
+osrfMessage.prototype.payload = function(d) { 
+    if(arguments.length == 1) 
+        this.hash.payload = d; 
+    return this.hash.payload; 
+};
+osrfMessage.prototype.locale = function(d) { 
+    if(arguments.length == 1) 
+        this.hash.locale = d; 
+    return this.hash.locale; 
+};
+osrfMessage.prototype.serialize = function() {
+    return {
+        "__c":"osrfMessage",
+        "__p": {
+            'threadTrace' : this.hash.threadTrace,
+            'type' : this.hash.type,
+            'payload' : (this.hash.payload) ? this.hash.payload.serialize() : 'null',
+            'locale' : this.hash.locale
+        }
+    };
+};
+
+function osrfMethod(hash) {
+    this.hash = hash;
+    this._encodehash = true;
+}
+osrfMethod.prototype.method = function() {
+    if(arguments.length == 1) 
+        this.hash.method = d; 
+    return this.hash.method; 
+};
+osrfMethod.prototype.params = function() {
+    if(arguments.length == 1) 
+        this.hash.params = d; 
+    return this.hash.params; 
+};
+osrfMethod.prototype.serialize = function() {
+    return {
+        "__c":"osrfMethod",
+        "__p": {
+            'method' : this.hash.method,
+            'params' : this.hash.params
+        }
+    };
+};
+
+function osrfMethodException(hash) {
+    this.hash = hash;
+    this._encodehash = true;
+}
+osrfMethodException.prototype.status = function() {
+    if(arguments.length == 1) 
+        this.hash.status = d; 
+    return this.hash.status; 
+};
+osrfMethodException.prototype.statusCode = function() {
+    if(arguments.length == 1) 
+        this.hash.statusCode = d; 
+    return this.hash.statusCode; 
+};
+function osrfConnectStatus(hash) { 
+    this.hash = hash;
+    this._encodehash = true;
+}
+osrfConnectStatus.prototype.status = function() {
+    if(arguments.length == 1) 
+        this.hash.status = d; 
+    return this.hash.status; 
+};
+osrfConnectStatus.prototype.statusCode = function() {
+    if(arguments.length == 1) 
+        this.hash.statusCode = d; 
+    return this.hash.statusCode; 
+};
+function osrfResult(hash) {
+    this.hash = hash;
+    this._encodehash = true;
+}
+osrfResult.prototype.status = function() {
+    if(arguments.length == 1) 
+        this.hash.status = d; 
+    return this.hash.status; 
+};
+osrfResult.prototype.statusCode = function() {
+    if(arguments.length == 1) 
+        this.hash.statusCode = d; 
+    return this.hash.statusCode; 
+};
+osrfResult.prototype.content = function() {
+    if(arguments.length == 1) 
+        this.hash.content = d; 
+    return this.hash.content; 
+};
+function osrfServerError(hash) { 
+    this.hash = hash;
+    this._encodehash = true;
+}
+osrfServerError.prototype.status = function() {
+    if(arguments.length == 1) 
+        this.hash.status = d; 
+    return this.hash.status; 
+};
+osrfServerError.prototype.statusCode = function() {
+    if(arguments.length == 1) 
+        this.hash.statusCode = d; 
+    return this.hash.statusCode; 
+};
+function osrfContinueStatus(hash) { 
+    this.hash = hash;
+    this._encodehash = true;
+}
+osrfContinueStatus.prototype.status = function() {
+    if(arguments.length == 1) 
+        this.hash.status = d; 
+    return this.hash.status; 
+};
+osrfContinueStatus.prototype.statusCode = function() {
+    if(arguments.length == 1) 
+        this.hash.statusCode = d; 
+    return this.hash.statusCode; 
+};
+
 OpenSRF = {};
 OpenSRF.locale = null;
 
@@ -56,23 +196,23 @@
     str += cls+'.baseClass = '+pcls+'.prototype.constructor;';
     str += cls+'.prototype["super"] = '+pcls+'.prototype;';
     eval(str);
-}
+};
 
 
 /* general session superclass */
 OpenSRF.Session = function() {
     this.remote_id = null;
     this.state = OSRF_APP_SESSION_DISCONNECTED;
-}
+};
 
 OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_XHR; /* default to XHR */
 OpenSRF.Session.cache = {};
 OpenSRF.Session.find_session = function(thread_trace) {
     return OpenSRF.Session.cache[thread_trace];
-}
+};
 OpenSRF.Session.prototype.cleanup = function() {
     delete OpenSRF.Session.cache[this.thread];
-}
+};
 
 OpenSRF.Session.prototype.send = function(osrf_msg, args) {
     args = (args) ? args : {};
@@ -82,23 +222,23 @@
         case OSRF_TRANSPORT_TYPE_XMPP:
             return this.send_xmpp(osrf_msg, args);
     }
-}
+};
 
 OpenSRF.Session.prototype.send_xhr = function(osrf_msg, args) {
     args.thread = this.thread;
     args.rcpt = this.remote_id;
     args.rcpt_service = this.service;
     new OpenSRF.XHRequest(osrf_msg, args).send();
-}
+};
 
 OpenSRF.Session.prototype.send_xmpp = function(osrf_msg, args) {
     alert('xmpp transport not yet implemented');
-}
+};
 
 
 /* client sessions make requests */
 OpenSRF.ClientSession = function(service) {
-    this.service = service
+    this.service = service;
     this.remote_id = null;
     this.locale = OpenSRF.locale || 'en-US';
     this.last_id = 0;
@@ -106,7 +246,7 @@
     this.requests = [];
     this.onconnect = null;
     OpenSRF.Session.cache[this.thread] = this;
-}
+};
 OpenSRF.set_subclass('OpenSRF.ClientSession', 'OpenSRF.Session');
 
 
@@ -131,7 +271,7 @@
     if(this.onconnect || this.state == OSRF_APP_SESSION_CONNECTED)
         return true;
     return false;
-}
+};
 
 OpenSRF.ClientSession.prototype.disconnect = function(args) {
     this.send(
@@ -141,7 +281,7 @@
         })
     );
     this.remote_id = null;
-}
+};
 
 
 OpenSRF.ClientSession.prototype.request = function(args) {
@@ -166,7 +306,7 @@
     var req = new OpenSRF.Request(this, this.last_id++, args);
     this.requests.push(req);
     return req;
-}
+};
 
 OpenSRF.ClientSession.prototype.find_request = function(reqid) {
     for(var i = 0; i < this.requests.length; i++) {
@@ -175,7 +315,7 @@
             return req;
     }
     return null;
-}
+};
 
 OpenSRF.Request = function(session, reqid, args) {
     this.session = session;
@@ -193,7 +333,7 @@
     this.timeout = args.timeout;
     this.response_queue = [];
     this.complete = false;
-}
+};
 
 OpenSRF.Request.prototype.peek_last = function(timeout) {
     if(this.response_queue.length > 0) {
@@ -202,19 +342,19 @@
         return x;
     }
     return null;
-}
+};
 
 OpenSRF.Request.prototype.peek = function(timeout) {
     if(this.response_queue.length > 0)
         return this.response_queue[0];
     return null;
-}
+};
 
 OpenSRF.Request.prototype.recv = function(timeout) {
     if(this.response_queue.length > 0)
         return this.response_queue.shift();
     return null;
-}
+};
 
 OpenSRF.Request.prototype.send = function() {
     method = new osrfMethod({'method':this.method, 'params':this.params});
@@ -233,17 +373,17 @@
         'onmethoderror' : this.onmethoderror,
         'ontransporterror' : this.ontransporterror
     });
-}
+};
 
 OpenSRF.NetMessage = function(to, from, thread, body) {
     this.to = to;
     this.from = from;
     this.thread = thread;
     this.body = body;
-}
+};
 
 OpenSRF.Stack = function() {
-}
+};
 
 // global inbound message queue
 OpenSRF.Stack.queue = [];
@@ -263,7 +403,7 @@
         var data = OpenSRF.Stack.queue.shift();
         OpenSRF.Stack.handle_message(data.ses, data.msg, data.callbacks);
     }
-}
+};
 
 OpenSRF.Stack.handle_message = function(ses, osrf_msg, callbacks) {
     
@@ -311,145 +451,6 @@
                 return callbacks.onresponse(req);
         }
     }
-}
+};
 
-/* The following classes map directly to network-serializable opensrf objects */
 
-function osrfMessage(hash) {
-    this.hash = hash;
-    if(!this.hash.locale)
-        this.hash.locale = OpenSRF.locale || 'en-US';
-    this._encodehash = true;
-}
-osrfMessage.prototype.threadTrace = function(d) { 
-    if(arguments.length == 1) 
-        this.hash.threadTrace = d; 
-    return this.hash.threadTrace; 
-}
-osrfMessage.prototype.type = function(d) { 
-    if(arguments.length == 1) 
-        this.hash.type = d; 
-    return this.hash.type; 
-}
-osrfMessage.prototype.payload = function(d) { 
-    if(arguments.length == 1) 
-        this.hash.payload = d; 
-    return this.hash.payload; 
-}
-osrfMessage.prototype.locale = function(d) { 
-    if(arguments.length == 1) 
-        this.hash.locale = d; 
-    return this.hash.locale; 
-}
-osrfMessage.prototype.serialize = function() {
-    return {
-        "__c":"osrfMessage",
-        "__p": {
-            'threadTrace' : this.hash.threadTrace,
-            'type' : this.hash.type,
-            'payload' : (this.hash.payload) ? this.hash.payload.serialize() : 'null',
-            'locale' : this.hash.locale
-        }
-    };
-}
-
-function osrfMethod(hash) {
-    this.hash = hash;
-    this._encodehash = true;
-} 
-osrfMethod.prototype.method = function() {
-    if(arguments.length == 1) 
-        this.hash.method = d; 
-    return this.hash.method; 
-}
-osrfMethod.prototype.params = function() {
-    if(arguments.length == 1) 
-        this.hash.params = d; 
-    return this.hash.params; 
-}
-osrfMethod.prototype.serialize = function() {
-    return {
-        "__c":"osrfMethod",
-        "__p": {
-            'method' : this.hash.method,
-            'params' : this.hash.params
-        }
-    };
-}
-
-function osrfMethodException(hash) {
-    this.hash = hash;
-    this._encodehash = true;
-}
-osrfMethodException.prototype.status = function() {
-    if(arguments.length == 1) 
-        this.hash.status = d; 
-    return this.hash.status; 
-}
-osrfMethodException.prototype.statusCode = function() {
-    if(arguments.length == 1) 
-        this.hash.statusCode = d; 
-    return this.hash.statusCode; 
-}
-function osrfConnectStatus(hash) { 
-    this.hash = hash;
-    this._encodehash = true;
-}
-osrfConnectStatus.prototype.status = function() {
-    if(arguments.length == 1) 
-        this.hash.status = d; 
-    return this.hash.status; 
-}
-osrfConnectStatus.prototype.statusCode = function() {
-    if(arguments.length == 1) 
-        this.hash.statusCode = d; 
-    return this.hash.statusCode; 
-}
-function osrfResult(hash) {
-    this.hash = hash;
-    this._encodehash = true;
-}
-osrfResult.prototype.status = function() {
-    if(arguments.length == 1) 
-        this.hash.status = d; 
-    return this.hash.status; 
-}
-osrfResult.prototype.statusCode = function() {
-    if(arguments.length == 1) 
-        this.hash.statusCode = d; 
-    return this.hash.statusCode; 
-}
-osrfResult.prototype.content = function() {
-    if(arguments.length == 1) 
-        this.hash.content = d; 
-    return this.hash.content; 
-}
-function osrfServerError(hash) { 
-    this.hash = hash;
-    this._encodehash = true;
-}
-osrfServerError.prototype.status = function() {
-    if(arguments.length == 1) 
-        this.hash.status = d; 
-    return this.hash.status; 
-}
-osrfServerError.prototype.statusCode = function() {
-    if(arguments.length == 1) 
-        this.hash.statusCode = d; 
-    return this.hash.statusCode; 
-}
-function osrfContinueStatus(hash) { 
-    this.hash = hash;
-    this._encodehash = true;
-}
-osrfContinueStatus.prototype.status = function() {
-    if(arguments.length == 1) 
-        this.hash.status = d; 
-    return this.hash.status; 
-}
-osrfContinueStatus.prototype.statusCode = function() {
-    if(arguments.length == 1) 
-        this.hash.statusCode = d; 
-    return this.hash.statusCode; 
-}
-

Modified: trunk/src/javascript/opensrf_xhr.js
===================================================================
--- trunk/src/javascript/opensrf_xhr.js	2011-03-11 13:15:57 UTC (rev 2208)
+++ trunk/src/javascript/opensrf_xhr.js	2011-03-13 06:03:46 UTC (rev 2209)
@@ -28,20 +28,19 @@
     this.message = osrf_msg;
     this.args = args;
     try {
-	    this.xreq =  new XMLHttpRequest();
+        this.xreq =  new XMLHttpRequest();
     } catch(e) {
-	    try { 
-		    this.xreq = new ActiveXObject("Msxml2.XMLHTTP"); 
-	    } catch (e2) {
-			this.xreq = new ActiveXObject("Microsoft.XMLHTTP"); 
-	    }
+        try { 
+            this.xreq = new ActiveXObject("Msxml2.XMLHTTP"); 
+        } catch (e2) {
+            this.xreq = new ActiveXObject("Microsoft.XMLHTTP"); 
+        }
     }
+};
 
-}
-
 OpenSRF.XHRequest.prototype.send = function() {
     var xhr_req = this;
-    var xreq = this.xreq
+    var xreq = this.xreq;
     
     if(this.args.timeout) {
         /* this is a standard blocking (non-multipart) call */
@@ -49,21 +48,21 @@
 
     } else {
 
-	/* Only Firefox supports multipart calls, but Safari / Chrome include
+    /* Only Firefox supports multipart calls, but Safari / Chrome include
            "Mozilla" in their user agent strings... sigh */
         if(!navigator.userAgent.match(/mozilla/i) || navigator.userAgent.match(/webkit/i) || navigator.userAgent.match(/msie/i)) {
             /* standard asynchronous call */
             xreq.onreadystatechange = function() {
                 if(xreq.readyState == 4)
                     xhr_req.core_handler();
-            }
+            };
             xreq.open('POST', OSRF_HTTP_TRANSLATOR, true);
 
         } else {
 
             /* asynchronous multipart call */
             xreq.multipart = true;
-            xreq.onload = function(evt) {xhr_req.core_handler();}
+            xreq.onload = function(evt) {xhr_req.core_handler();};
             xreq.open('POST', OSRF_HTTP_TRANSLATOR, true);
             xreq.setRequestHeader(OSRF_HTTP_HEADER_MULTIPART, 'true');
 
@@ -72,25 +71,26 @@
             xreq.onreadystatechange = function() {
                 if(xreq.readyState == 4 && xreq.status >= 400)
                     xhr_req.transport_error_handler();
-            }
+            };
         }
     }
 
     xreq.setRequestHeader('Content-Type', OSRF_POST_CONTENT_TYPE);
     xreq.setRequestHeader(OSRF_HTTP_HEADER_THREAD, this.args.thread);
-    if(this.args.rcpt)
+    if(this.args.rcpt) {
         xreq.setRequestHeader(OSRF_HTTP_HEADER_TO, this.args.rcpt);
-    else
+    } else {
         xreq.setRequestHeader(OSRF_HTTP_HEADER_SERVICE, this.args.rcpt_service);
+    }
 
     var post = 'osrf-msg=' + encodeURIComponent(js2JSON([this.message.serialize()]));
     xreq.send(post);
 
     if(this.args.timeout) /* this was a blocking call, manually run the handler */
-        this.core_handler()
+        this.core_handler();
 
     return this;
-}
+};
 
 OpenSRF.XHRequest.prototype.core_handler = function() {
     sender = this.xreq.getResponseHeader(OSRF_HTTP_HEADER_FROM);
@@ -110,7 +110,7 @@
             onmethoderror : this.method_error_handler()
         }
     );
-}
+};
 
 
 OpenSRF.XHRequest.prototype.method_error_handler = function() {
@@ -120,14 +120,16 @@
             xhr.args.onmethoderror(req, status, status_text);
         if(xhr.args.onerror)  
             xhr.args.onerror(xhr.message, xhr.args.rcpt || xhr.args.rcpt_service, xhr.args.thread);
-    }
-}
+    };
+};
 
 OpenSRF.XHRequest.prototype.transport_error_handler = function() {
-    if(this.args.ontransporterror) 
+    if(this.args.ontransporterror) {
         this.args.ontransporterror(this.xreq);
-    if(this.args.onerror) 
+    }
+    if(this.args.onerror) {
         this.args.onerror(this.message, this.args.rcpt || this.args.rcpt_service, this.args.thread);
-}
+    }
+};
 
 

Modified: trunk/src/javascript/opensrf_xmpp.js
===================================================================
--- trunk/src/javascript/opensrf_xmpp.js	2011-03-11 13:15:57 UTC (rev 2208)
+++ trunk/src/javascript/opensrf_xmpp.js	2011-03-13 06:03:46 UTC (rev 2209)
@@ -8,12 +8,12 @@
 
 
 // ------------------------------------------------------------------
-//		Houses the jabber transport code
+//        Houses the jabber transport code
 //
 // 1. jabber_connection - high level jabber component
 // 2. jabber_message - message class
 // 3. jabber_socket - socket handling code (shouldn't have to 
-//		use this class directly)
+//        use this class directly)
 //
 // Requires oils_utils.js
 // ------------------------------------------------------------------
@@ -36,12 +36,12 @@
 /** Initializes a jabber_connection object */
 function jabber_connection( username, password, resource ) {
 
-	this.username		= username;
-	this.password		= password;
-	this.resource		= resource;
-	this.socket			= new jabber_socket();
+    this.username        = username;
+    this.password        = password;
+    this.resource        = resource;
+    this.socket            = new jabber_socket();
 
-	this.host			= "";
+    this.host            = "";
 
 }
 
@@ -49,46 +49,46 @@
   * in milliseconds 
  */
 jabber_connection.prototype.connect = function( host, port, timeout ) {
-	this.host = host;
-	return this.socket.connect( 
-			this.username, this.password, this.resource, host, port, timeout );
-}
+    this.host = host;
+    return this.socket.connect( 
+            this.username, this.password, this.resource, host, port, timeout );
+};
 
 /** Sends a message to 'recipient' with the provided message 
   * thread and body 
   */
 jabber_connection.prototype.send = function( recipient, thread, body ) {
-	var jid = this.username+"@"+this.host+"/"+this.resource;
-	var msg = new jabber_message( jid, recipient, thread, body );
-	return this.socket.tcp_send( msg.to_string() );
-}
+    var jid = this.username+"@"+this.host+"/"+this.resource;
+    var msg = new jabber_message( jid, recipient, thread, body );
+    return this.socket.tcp_send( msg.to_string() );
+};
 
 /** This method will wait at most 'timeout' milliseconds
   * for a Jabber message to arrive.  If one arrives
   * it is returned to the caller, other it returns null
   */
 jabber_connection.prototype.recv = function( timeout ) {
-	return this.socket.recv( timeout );
-}
+    return this.socket.recv( timeout );
+};
 
 /** Disconnects from the jabber server */
 jabber_connection.prototype.disconnect = function() {
-	return this.socket.disconnect();
-}
+    return this.socket.disconnect();
+};
 
 /** Returns true if we are currently connected to the 
   * Jabber server
   */
 jabber_connection.prototype.connected = function() {
-	return this.socket.connected();
-}
+    return this.socket.connected();
+};
 
 
 
 // ------------------------------------------------------------------
 // JABBER_MESSAGE
 // High level message handling code
-	
+    
 
 jabber_message.prototype = new transport_message();
 jabber_message.prototype.constructor = jabber_message;
@@ -97,21 +97,21 @@
 /** Builds a jabber_message object */
 function jabber_message( sender, recipient, thread, body ) {
 
-	if( sender == null || recipient == null || recipient.length < 1 ) { return; }
+    if( sender == null || recipient == null || recipient.length < 1 ) { return; }
 
-	this.doc = new DOMParser().parseFromString("<message></message>", "text/xml");
-	this.root = this.doc.documentElement;
-	this.root.setAttribute( "from", sender );
-	this.root.setAttribute( "to", recipient );
+    this.doc = new DOMParser().parseFromString("<message></message>", "text/xml");
+    this.root = this.doc.documentElement;
+    this.root.setAttribute( "from", sender );
+    this.root.setAttribute( "to", recipient );
 
-	var body_node = this.doc.createElement("body");
-	body_node.appendChild( this.doc.createTextNode( body ) );
+    var body_node = this.doc.createElement("body");
+    body_node.appendChild( this.doc.createTextNode( body ) );
 
-	var thread_node = this.doc.createElement("thread");
-	thread_node.appendChild( this.doc.createTextNode( thread ) );
+    var thread_node = this.doc.createElement("thread");
+    thread_node.appendChild( this.doc.createTextNode( thread ) );
 
-	this.root.appendChild( body_node );
-	this.root.appendChild( thread_node );
+    this.root.appendChild( body_node );
+    this.root.appendChild( thread_node );
 
 }
 
@@ -120,130 +120,126 @@
   * is set to true;
   */
 jabber_message.prototype.from_xml = function( xml ) {
-	var msg = new jabber_message();
-	msg.doc = new DOMParser().parseFromString( xml, "text/xml" );
-	msg.root = msg.doc.documentElement;
+    var msg = new jabber_message();
+    msg.doc = new DOMParser().parseFromString( xml, "text/xml" );
+    msg.root = msg.doc.documentElement;
 
-	if( msg.root.getAttribute( "type" ) == "error" ) {
-		msg.is_error_msg = true;
-	} else {
-		this.is_error_msg = false;
-	}
+    if( msg.root.getAttribute( "type" ) == "error" ) {
+        msg.is_error_msg = true;
+    } else {
+        this.is_error_msg = false;
+    }
 
-	return msg;
-}
+    return msg;
+};
 
 /** Returns the 'from' field of the message */
 jabber_message.prototype.get_sender = function() {
-	return this.root.getAttribute( "from" );
-}
+    return this.root.getAttribute( "from" );
+};
 
 /** Returns the jabber thread */
 jabber_message.prototype.get_thread = function() {
-	var nodes = this.root.getElementsByTagName( "thread" );
-	var thread_node = nodes.item(0);
-	return thread_node.firstChild.nodeValue;
-}
+    var nodes = this.root.getElementsByTagName( "thread" );
+    var thread_node = nodes.item(0);
+    return thread_node.firstChild.nodeValue;
+};
 
 /** Returns the message body */
 jabber_message.prototype.get_body = function() {
-	var nodes = this.root.getElementsByTagName( "body" );
-	var body_node = nodes.item(0);
-	new Logger().transport( "Get Body returning:\n" + body_node.textContent, Logger.DEBUG );
-	return body_node.textContent;
-}
-	
+    var nodes = this.root.getElementsByTagName( "body" );
+    var body_node = nodes.item(0);
+    new Logger().transport( "Get Body returning:\n" + body_node.textContent, Logger.DEBUG );
+    return body_node.textContent;
+};
+
 /** Returns the message as a whole as an XML string */
 jabber_message.prototype.to_string = function() {
    return new XMLSerializer().serializeToString(this.root);
-}
+};
 
 
-
-
 // ------------------------------------------------------------------
 // TRANSPORT_SOCKET
 
 /** Initializes a new jabber_socket object */
 function jabber_socket() {
 
-	this.is_connected	= false;
-	this.outstream		= "";
-	this.instream		= "";
-	this.buffer			= "";
-	this.socket			= "";
+    this.is_connected    = false;
+    this.outstream        = "";
+    this.instream        = "";
+    this.buffer            = "";
+    this.socket            = "";
 
 }
 
 /** Connects to the jabber server */
 jabber_socket.prototype.connect = 
-	function( username, password, resource,  host, port, timeout ) {
+    function( username, password, resource,  host, port, timeout ) {
 
-	var starttime = new Date().getTime();
+    var starttime = new Date().getTime();
 
-	// there has to be at least some kind of timeout
-	if( ! timeout || timeout < 100 ) { timeout = 1000; }
+    // there has to be at least some kind of timeout
+    if( ! timeout || timeout < 100 ) { timeout = 1000; }
 
-	try {
+    try {
 
-		this.xpcom_init( host, port );
-		this.tcp_send( "<stream:stream to='"+host
-				+"' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>" );
+        this.xpcom_init( host, port );
+        this.tcp_send( "<stream:stream to='"+host
+                +"' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>" );
 
-		if( !this.tcp_recv( timeout ) ) {  throw 1; }
+        if( !this.tcp_recv( timeout ) ) {  throw 1; }
 
-	} catch( E ) {
-		throw new oils_ex_transport( "Could not open a socket to the transport server\n" 
-				+ "Server: " + host + " Port: " + port  );
-	}
+    } catch( E ) {
+        throw new oils_ex_transport( "Could not open a socket to the transport server\n" 
+                + "Server: " + host + " Port: " + port  );
+    }
 
-	// Send the auth packet
-	this.tcp_send( "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'><username>" 
-			+ username + "</username><password>" + password + 
-			"</password><resource>" + resource + "</resource></query></iq>" );
+    // Send the auth packet
+    this.tcp_send( "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'><username>" 
+            + username + "</username><password>" + password + 
+            "</password><resource>" + resource + "</resource></query></iq>" );
 
-	var cur = new Date().getTime();
-	var remaining = timeout - ( cur - starttime );
-	this.tcp_recv( remaining );
+    var cur = new Date().getTime();
+    var remaining = timeout - ( cur - starttime );
+    this.tcp_recv( remaining );
 
-	if( ! this.connected() ) {
-		throw new oils_ex_transport( "Connection to transport server timed out" );
-	}
+    if( ! this.connected() ) {
+        throw new oils_ex_transport( "Connection to transport server timed out" );
+    }
 
-	return true;
+    return true;
+};
 
 
-}
-
-
 /** Sets up all of the xpcom components */
 jabber_socket.prototype.xpcom_init = function( host, port ) {
 
-	var transportService =
-		Components.classes["@mozilla.org/network/socket-transport-service;1"]
-		.getService(Components.interfaces.nsISocketTransportService);
+    var transportService =
+        Components.classes["@mozilla.org/network/socket-transport-service;1"]
+        .getService(Components.interfaces.nsISocketTransportService);
 
-	this.transport = transportService.createTransport( null, 0, host, port, null);
+    this.transport = transportService.createTransport( null, 0, host, port, null);
 
-	// ------------------------------------------------------------------
-	// Build the stream objects
-	// ------------------------------------------------------------------
-	this.outstream = this.transport.openOutputStream(0,0,0);
-	
-	var stream = this.transport.openInputStream(0,0,0);
+    // ------------------------------------------------------------------
+    // Build the stream objects
+    // ------------------------------------------------------------------
+    this.outstream = this.transport.openOutputStream(0,0,0);
+    
+    var stream = this.transport.openInputStream(0,0,0);
 
-	this.instream = Components.classes["@mozilla.org/scriptableinputstream;1"]
-			.createInstance(Components.interfaces.nsIScriptableInputStream);
+    this.instream = Components.classes["@mozilla.org/scriptableinputstream;1"]
+            .createInstance(Components.interfaces.nsIScriptableInputStream);
 
-	this.instream.init(stream);
+    this.instream.init(stream);
 
-}
+};
 
 /** Send data to the TCP pipe */
 jabber_socket.prototype.tcp_send = function( data ) {
-	new Logger().transport( "Sending Data: \n" + data, Logger.INFO );
-	this.outstream.write(data,data.length);
-}
+    new Logger().transport( "Sending Data: \n" + data, Logger.INFO );
+    this.outstream.write(data,data.length);
+};
 
 
 /** Accepts data coming directly from the socket.  If we're not
@@ -252,33 +248,33 @@
   */
 jabber_socket.prototype.process_data = function( data ) {
 
-	new Logger().transport( "Received TCP data: " + data, Logger.DEBUG );
+    new Logger().transport( "Received TCP data: " + data, Logger.DEBUG );
 
-	if( ! this.connected() ) {
-		this.process_connect( data );
-		return;
-	} 
+    if( ! this.connected() ) {
+        this.process_connect( data );
+        return;
+    } 
 
-	this.buffer += data;
+    this.buffer += data;
 
-}
+};
 
 /** Processes connect data to verify we are logged in correctly */
 jabber_socket.prototype.process_connect = function( data ) {
 
-	var reg = /type=["\']result["\']/;
-	var err = /error/;
+    var reg = /type=["\']result["\']/;
+    var err = /error/;
 
-	if( reg.exec( data ) ) {
-		this.is_connected = true;
-	} else {
-		if( err.exec( data ) ) {
-			//throw new oils_ex_transport( "Server returned: \n" + data );
-			throw new oils_ex_jabber_auth( "Server returned: \n" + data );
-			// Throw exception, return something...
-		}
-	}
-}
+    if( reg.exec( data ) ) {
+        this.is_connected = true;
+    } else {
+        if( err.exec( data ) ) {
+            //throw new oils_ex_transport( "Server returned: \n" + data );
+            throw new oils_ex_jabber_auth( "Server returned: \n" + data );
+            // Throw exception, return something...
+        }
+    }
+};
 
 /** Waits up to at most 'timeout' milliseconds for data to arrive 
   * in the TCP buffer.  If there is at least one byte of data 
@@ -287,71 +283,71 @@
   */
 jabber_socket.prototype.tcp_recv = function( timeout ) {
 
-	var count = this.instream.available();
-	var did_receive = false;
+    var count = this.instream.available();
+    var did_receive = false;
 
-	// ------------------------------------------------------------------
-	// If there is any data in the tcp buffer, process it and return
-	// ------------------------------------------------------------------
-	if( count > 0 ) { 
+    // ------------------------------------------------------------------
+    // If there is any data in the tcp buffer, process it and return
+    // ------------------------------------------------------------------
+    if( count > 0 ) { 
 
-		did_receive = true;
-		while( count > 0 ) { 
-			new Logger().transport(
-				"before process data", Logger.DEBUG );
+        did_receive = true;
+        while( count > 0 ) { 
+            new Logger().transport(
+                "before process data", Logger.DEBUG );
 
-			this.process_data( this.instream.read( count ) );
+            this.process_data( this.instream.read( count ) );
 
-			new Logger().transport(
-				"after process data", Logger.DEBUG );
+            new Logger().transport(
+                "after process data", Logger.DEBUG );
 
-			count = this.instream.available();
+            count = this.instream.available();
 
-			new Logger().transport(
-				"received " + count + " bytes" , Logger.DEBUG );
-		}
+            new Logger().transport(
+                "received " + count + " bytes" , Logger.DEBUG );
+        }
 
-	} else { 
+    } else { 
 
-		// ------------------------------------------------------------------
-		// Do the timeout dance
-		// ------------------------------------------------------------------
+        // ------------------------------------------------------------------
+        // Do the timeout dance
+        // ------------------------------------------------------------------
 
-		// ------------------------------------------------------------------
-		// If there is no data in the buffer, wait up to timeout seconds
-		// for some data to arrive.  Once it arrives, suck it all out
-		// and send it on for processing
-		// ------------------------------------------------------------------
+        // ------------------------------------------------------------------
+        // If there is no data in the buffer, wait up to timeout seconds
+        // for some data to arrive.  Once it arrives, suck it all out
+        // and send it on for processing
+        // ------------------------------------------------------------------
 
-		var now, then;
-		now = new Date().getTime();
-		then = now;
+        var now, then;
+        now = new Date().getTime();
+        then = now;
 
-		// ------------------------------------------------------------------
-		// Loop and poll for data every 50 ms.
-		// ------------------------------------------------------------------
-		while( ((now-then) <= timeout) && count <= 0 ) { 
-			sleep(50);
-			count = this.instream.available();
-			now = new Date().getTime();
-		}
+        // ------------------------------------------------------------------
+        // Loop and poll for data every 50 ms.
+        // ------------------------------------------------------------------
+        while( ((now-then) <= timeout) && count <= 0 ) { 
+            sleep(50);
+            count = this.instream.available();
+            now = new Date().getTime();
+        }
 
-		// ------------------------------------------------------------------
-		// if we finally get some data, process it.
-		// ------------------------------------------------------------------
-		if( count > 0 ) {
+        // ------------------------------------------------------------------
+        // if we finally get some data, process it.
+        // ------------------------------------------------------------------
+        if( count > 0 ) {
 
-			did_receive = true;
-			while( count > 0 ) { // pull in all of the data there is
-				this.process_data( this.instream.read( count ) );
-				count = this.instream.available();
-			}
-		}
-	}
+            did_receive = true;
+            while( count > 0 ) { // pull in all of the data there is
+                this.process_data( this.instream.read( count ) );
+                count = this.instream.available();
+            }
+        }
+    }
 
-	return did_receive;
+    return did_receive;
 
-}
+};
 
 /** If a message is already sitting in the queue, it is returned.  
   * If not, this method waits till at most 'timeout' milliseconds 
@@ -360,83 +356,83 @@
   */
 jabber_socket.prototype.recv = function( timeout ) {
 
-	var now, then;
-	now = new Date().getTime();
-	then = now;
+    var now, then;
+    now = new Date().getTime();
+    then = now;
 
-	var first_pass = true;
-	while( ((now-then) <= timeout) ) {
-		
-		if( this.buffer.length == 0  || !first_pass ) {
-			if( ! this.tcp_recv( timeout ) ) {
-				return null;
-			}
-		}
-		first_pass = false;
+    var first_pass = true;
+    while( ((now-then) <= timeout) ) {
+        
+        if( this.buffer.length == 0  || !first_pass ) {
+            if( ! this.tcp_recv( timeout ) ) {
+                return null;
+            }
+        }
+        first_pass = false;
 
-		//new Logger().transport( "\n\nTCP Buffer Before: \n" + this.buffer, Logger.DEBUG );
+        //new Logger().transport( "\n\nTCP Buffer Before: \n" + this.buffer, Logger.DEBUG );
 
-		var buf = this.buffer;
-		this.buffer = "";
+        var buf = this.buffer;
+        this.buffer = "";
 
-		new Logger().transport( "CURRENT BUFFER\n" + buf,
-			Logger.DEBUG );
+        new Logger().transport( "CURRENT BUFFER\n" + buf,
+            Logger.DEBUG );
 
-		buf = buf.replace( /\n/g, '' ); // remove pesky newlines
+        buf = buf.replace( /\n/g, '' ); // remove pesky newlines
 
-		var reg = /<message.*?>.*?<\/message>/;
-		var iqr = /<iq.*?>.*?<\/iq>/;
-		var out = reg.exec(buf);
+        var reg = /<message.*?>.*?<\/message>/;
+        var iqr = /<iq.*?>.*?<\/iq>/;
+        var out = reg.exec(buf);
 
-		if( out ) { 
+        if( out ) { 
 
-			var msg_xml = out[0];
-			this.buffer = buf.substring( msg_xml.length, buf.length );
-			new Logger().transport( "Building Jabber message\n\n" + msg_xml, Logger.DEBUG );
-			var jab_msg = new jabber_message().from_xml( msg_xml );
-			if( jab_msg.is_error_msg ) {
-				new Logger().transport( "Received Jabber error message \n\n" + msg_xml, Logger.ERROR );
-			} 
+            var msg_xml = out[0];
+            this.buffer = buf.substring( msg_xml.length, buf.length );
+            new Logger().transport( "Building Jabber message\n\n" + msg_xml, Logger.DEBUG );
+            var jab_msg = new jabber_message().from_xml( msg_xml );
+            if( jab_msg.is_error_msg ) {
+                new Logger().transport( "Received Jabber error message \n\n" + msg_xml, Logger.ERROR );
+            } 
 
-			return jab_msg;
+            return jab_msg;
 
 
-		} else { 
+        } else { 
 
-			out = iqr.exec(buf);
+            out = iqr.exec(buf);
 
-			if( out ) {
-				var msg_xml = out[0];
-				this.buffer = buf.substring( msg_xml.length, buf.length );
-				process_iq_data( msg_xml );
-				return;
+            if( out ) {
+                var msg_xml = out[0];
+                this.buffer = buf.substring( msg_xml.length, buf.length );
+                process_iq_data( msg_xml );
+                return;
 
-			} else {
-				this.buffer = buf;
-			}
+            } else {
+                this.buffer = buf;
+            }
 
-		} 
-		now = new Date().getTime();
-	}
+        } 
+        now = new Date().getTime();
+    }
 
-	return null;
-}
+    return null;
+};
 
 jabber_socket.prototype.process_iq_data = function( data ) {
-	new Logger().transport( "IQ Packet received... Not Implemented\n" + data, Logger.ERROR );
-}
+    new Logger().transport( "IQ Packet received... Not Implemented\n" + data, Logger.ERROR );
+};
 
 /** Disconnects from the jabber server and closes down shop */
 jabber_socket.prototype.disconnect = function() {
-	this.tcp_send( "</stream:stream>" );
-	this.instream.close();
-	this.outstream.close();
-}
+    this.tcp_send( "</stream:stream>" );
+    this.instream.close();
+    this.outstream.close();
+};
 
 /** True if connected */
 jabber_socket.prototype.connected = function() {
-	return this.is_connected;
-}
+    return this.is_connected;
+};
 
 
 



More information about the opensrf-commits mailing list