1 /*
  2  * Copyright (C) 2014 Glyptodon LLC
  3  *
  4  * Permission is hereby granted, free of charge, to any person obtaining a copy
  5  * of this software and associated documentation files (the "Software"), to deal
  6  * in the Software without restriction, including without limitation the rights
  7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8  * copies of the Software, and to permit persons to whom the Software is
  9  * furnished to do so, subject to the following conditions:
 10  *
 11  * The above copyright notice and this permission notice shall be included in
 12  * all copies or substantial portions of the Software.
 13  *
 14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 20  * THE SOFTWARE.
 21  */
 22 
 23 var Guacamole = Guacamole || {};
 24 
 25 /**
 26  * A Guacamole status. Each Guacamole status consists of a status code, defined
 27  * by the protocol, and an optional human-readable message, usually only
 28  * included for debugging convenience.
 29  * 
 30  * @param {Number} code The Guacamole status code, as defined by
 31  *                      Guacamole.Status.Code.
 32  * @param {String} [message] An optional human-readable message.
 33  */
 34 Guacamole.Status = function(code, message) {
 35 
 36     /**
 37      * Reference to this Guacamole.Status.
 38      * @private
 39      */
 40     var guac_status = this;
 41 
 42     /**
 43      * The Guacamole status code.
 44      * @see Guacamole.Status.Code
 45      * @type Number 
 46      */
 47     this.code = code;
 48 
 49     /**
 50      * An arbitrary human-readable message associated with this status, if any.
 51      * The human-readable message is not required, and is generally provided
 52      * for debugging purposes only. For user feedback, it is better to translate
 53      * the Guacamole status code into a message.
 54      * 
 55      * @type String
 56      */
 57     this.message = message;
 58 
 59     /**
 60      * Returns whether this status represents an error.
 61      * @returns {Boolean} true if this status represents an error, false
 62      *                    otherwise.
 63      */
 64     this.isError = function() {
 65         return guac_status.code < 0 || guac_status.code > 0x00FF;
 66     };
 67 
 68 };
 69 
 70 /**
 71  * Enumeration of all Guacamole status codes.
 72  */
 73 Guacamole.Status.Code = {
 74 
 75     /**
 76      * The operation succeeded.
 77      *
 78      * @type Number
 79      */
 80     "SUCCESS": 0x0000,
 81 
 82     /**
 83      * The requested operation is unsupported.
 84      *
 85      * @type Number
 86      */
 87     "UNSUPPORTED": 0x0100,
 88 
 89     /**
 90      * The operation could not be performed due to an internal failure.
 91      *
 92      * @type Number
 93      */
 94     "SERVER_ERROR": 0x0200,
 95 
 96     /**
 97      * The operation could not be performed as the server is busy.
 98      *
 99      * @type Number
100      */
101     "SERVER_BUSY": 0x0201,
102 
103     /**
104      * The operation was unsuccessful due to an error or otherwise unexpected
105      * condition of the upstream server.
106      *
107      * @type Number
108      */
109     "UPSTREAM_TIMEOUT": 0x0202,
110 
111     /**
112      * The operation could not be performed because the upstream server is not
113      * responding.
114      *
115      * @type Number
116      */
117     "UPSTREAM_ERROR": 0x0203,
118 
119     /**
120      * The operation could not be performed as the requested resource does not
121      * exist.
122      *
123      * @type Number
124      */
125     "RESOURCE_NOT_FOUND": 0x0204,
126 
127     /**
128      * The operation could not be performed as the requested resource is
129      * already in use.
130      *
131      * @type Number
132      */
133     "RESOURCE_CONFLICT": 0x0205,
134 
135     /**
136      * The operation could not be performed because bad parameters were given.
137      *
138      * @type Number
139      */
140     "CLIENT_BAD_REQUEST": 0x0300,
141 
142     /**
143      * Permission was denied to perform the operation, as the user is not yet
144      * authorized (not yet logged in, for example).
145      *
146      * @type Number
147      */
148     "CLIENT_UNAUTHORIZED": 0x0301,
149 
150     /**
151      * Permission was denied to perform the operation, and this permission will
152      * not be granted even if the user is authorized.
153      *
154      * @type Number
155      */
156     "CLIENT_FORBIDDEN": 0x0303,
157 
158     /**
159      * The client took too long to respond.
160      *
161      * @type Number
162      */
163     "CLIENT_TIMEOUT": 0x0308,
164 
165     /**
166      * The client sent too much data.
167      *
168      * @type Number
169      */
170     "CLIENT_OVERRUN": 0x030D,
171 
172     /**
173      * The client sent data of an unsupported or unexpected type.
174      *
175      * @type Number
176      */
177     "CLIENT_BAD_TYPE": 0x030F,
178 
179     /**
180      * The operation failed because the current client is already using too
181      * many resources.
182      *
183      * @type Number
184      */
185     "CLIENT_TOO_MANY": 0x031D
186 
187 };
188