Exemplo n.º 1
0
        public bool ClassifiedUpdate(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "Error parsing classified update request";
                m_log.DebugFormat("Classified Update Request");
                return(false);
            }

            string            result = string.Empty;
            UserClassifiedAdd ad     = new UserClassifiedAdd();
            object            Ad     = (object)ad;

            OSD.DeserializeMembers(ref Ad, (OSDMap)json["params"]);
            if (Service.ClassifiedUpdate(ad, ref result))
            {
                response.Result = OSD.SerializeMembers(ad);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
Exemplo n.º 2
0
        public bool RequestUserAppData(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("User Application Service URL Request: No Parameters!");
                return(false);
            }

            string      result = string.Empty;
            UserAppData props  = new UserAppData();
            object      Props  = (object)props;

            OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
            if (Service.RequestUserAppData(ref props, ref result))
            {
                OSDMap res = new OSDMap();
                res["result"]   = OSD.FromString("success");
                res["token"]    = OSD.FromString(result);
                response.Result = res;

                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
Exemplo n.º 3
0
        public bool UpdateUserAppData(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("User App Data Update Request");
                return(false);
            }

            string      result = string.Empty;
            UserAppData props  = new UserAppData();
            object      Props  = (object)props;

            OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
            if (Service.SetUserAppData(props, ref result))
            {
                response.Result = OSD.SerializeMembers(props);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
Exemplo n.º 4
0
        public bool PicksUpdate(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("Avatar Picks Update Request");
                return(false);
            }

            string          result = string.Empty;
            UserProfilePick pick   = new UserProfilePick();
            object          Pick   = (object)pick;

            OSD.DeserializeMembers(ref Pick, (OSDMap)json["params"]);
            if (Service.PicksUpdate(ref pick, ref result))
            {
                response.Result = OSD.SerializeMembers(pick);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = "unable to update pick";

            return(false);
        }
Exemplo n.º 5
0
        public bool UserPreferenecesUpdate(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("User Preferences Update Request");
                return(false);
            }

            string          result = string.Empty;
            UserPreferences prefs  = new UserPreferences();
            object          Prefs  = (object)prefs;

            OSD.DeserializeMembers(ref Prefs, (OSDMap)json["params"]);
            if (Service.UserPreferencesUpdate(ref prefs, ref result))
            {
                response.Result = OSD.SerializeMembers(prefs);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            m_log.InfoFormat("[PROFILES]: User preferences update error - {0}", response.Error.Message);
            return(false);
        }
Exemplo n.º 6
0
        public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
        {
            if (!json.ContainsKey("params"))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "Params missing";
                m_log.DebugFormat("Avatar Notes Request");
                return(false);
            }

            string           result = string.Empty;
            UserProfileNotes note   = new UserProfileNotes();
            object           Note   = (object)note;

            OSD.DeserializeMembers(ref Note, (OSDMap)json["params"]);
            if (Service.AvatarNotesRequest(ref note))
            {
                response.Result = OSD.SerializeMembers(note);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = "Error reading notes";
            return(false);
        }
Exemplo n.º 7
0
        public bool AvatarNotesRequest(OSDMap json, ref JsonRpcResponse response)
        {
            OSD tmpParams;

            if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "Params missing";
                m_log.DebugFormat("Avatar Notes Request");
                return(false);
            }

            UserProfileNotes note = new UserProfileNotes();
            object           Note = (object)note;

            OSD.DeserializeMembers(ref Note, (OSDMap)tmpParams);
            if (Service.AvatarNotesRequest(ref note))
            {
                response.Result = OSD.SerializeMembers(note);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = "Error reading notes";
            return(false);
        }
Exemplo n.º 8
0
        public bool ClassifiedUpdate(OSDMap json, ref JsonRpcResponse response)
        {
            OSD tmpParams;

            if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "Error parsing classified update request";
                m_log.DebugFormat("Classified Update Request");
                return(false);
            }

            string            result = string.Empty;
            UserClassifiedAdd ad     = new UserClassifiedAdd();
            object            Ad     = ad;

            OSD.DeserializeMembers(ref Ad, (OSDMap)tmpParams);
            //If no maturity bits are set, set PG maturity bit. This works
            // around a viewer bug. It simplifies the ability to search ads
            // based on maturity level. 0x4e is bits 1 (old viewers mature), 2 (pg), 3 (Mature) and 6 (Adult).
            if ((ad.Flags & 0x4e) == 0)
            {
                ad.Flags |= 0x04;
            }

            if (Service.ClassifiedUpdate(ad, ref result))
            {
                response.Result = OSD.SerializeMembers(ad);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
Exemplo n.º 9
0
        public bool PickInfoRequest(OSDMap json, ref JsonRpcResponse response)
        {
            OSD tmpParams;

            if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "no parameters supplied";
                m_log.DebugFormat("Avatar Picks Info Request");
                return(false);
            }

            string          result = string.Empty;
            UserProfilePick pick   = new UserProfilePick();
            object          Pick   = (object)pick;

            OSD.DeserializeMembers(ref Pick, (OSDMap)tmpParams);
            if (Service.PickInfoRequest(ref pick, ref result))
            {
                response.Result = OSD.SerializeMembers(pick);
                return(true);
            }

            response.Error.Code    = ErrorCode.InternalError;
            response.Error.Message = string.Format("{0}", result);
            return(false);
        }
Exemplo n.º 10
0
 public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
 {
     if(!json.ContainsKey("params"))
     {
         response.Error.Code = ErrorCode.ParseError;
         response.Error.Message = "No parameters";
         m_log.DebugFormat ("Avatar Notes Update Request");
         return false;
     }
     
     string result = string.Empty;
     UserProfileNotes note = new UserProfileNotes();
     object Notes = (object) note;
     OSD.DeserializeMembers(ref Notes, (OSDMap)json["params"]);
     if(Service.NotesUpdate(ref note, ref result))
     {
         response.Result = OSD.SerializeMembers(note);
         return true;
     }
     return true;
 }
Exemplo n.º 11
0
 public bool AvatarPropertiesRequest(OSDMap json, ref JsonRpcResponse response)
 {
     if(!json.ContainsKey("params"))
     {
         response.Error.Code = ErrorCode.ParseError;
         response.Error.Message = "no parameters supplied";
         m_log.DebugFormat ("Avatar Properties Request");
         return false;
     }
     
     string result = string.Empty;
     UserProfileProperties props = new UserProfileProperties();
     object Props = (object)props;
     OSD.DeserializeMembers(ref Props, (OSDMap)json["params"]);
     if(Service.AvatarPropertiesRequest(ref props, ref result))
     {
         response.Result = OSD.SerializeMembers(props);
         return true;
     }
     
     response.Error.Code = ErrorCode.InternalError;
     response.Error.Message = string.Format("{0}", result);
     return false;
 }
Exemplo n.º 12
0
        public bool NotesUpdate(OSDMap json, ref JsonRpcResponse response)
        {
            OSD tmpParams;

            if (!json.TryGetValue("params", out tmpParams) || !(tmpParams is OSDMap))
            {
                response.Error.Code    = ErrorCode.ParseError;
                response.Error.Message = "No parameters";
                m_log.DebugFormat("Avatar Notes Update Request");
                return(false);
            }

            string           result = string.Empty;
            UserProfileNotes note   = new UserProfileNotes();
            object           Notes  = (object)note;

            OSD.DeserializeMembers(ref Notes, (OSDMap)tmpParams);
            if (Service.NotesUpdate(ref note, ref result))
            {
                response.Result = OSD.SerializeMembers(note);
                return(true);
            }
            return(true);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sends json-rpc request with a serializable type.
        /// </summary>
        /// <returns>
        /// OSD Map.
        /// </returns>
        /// <param name='parameters'>
        /// Serializable type .
        /// </param>
        /// <param name='method'>
        /// Json-rpc method to call.
        /// </param>
        /// <param name='uri'>
        /// URI of json-rpc service.
        /// </param>
        /// <param name='jsonId'>
        /// Id for our call.
        /// </param>
        public bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
        {
            if (jsonId == null)
            {
                throw new ArgumentNullException("jsonId");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            m_log.Debug("[JsonRpcRequestManager] JsonRpcRequest*: method=" + method + " uri=" + uri);

            if (string.IsNullOrWhiteSpace(uri))
            {
                return(false);
            }

            OSDMap request = new OSDMap();

            request.Add("jsonrpc", OSD.FromString("2.0"));
            request.Add("id", OSD.FromString(jsonId));
            request.Add("method", OSD.FromString(method));
            request.Add("params", OSD.SerializeMembers(parameters));

            OSDMap response;

            try
            {
                response = WebUtil.PostToService(uri, request, 10000, true);
            }
            catch (Exception e)
            {
                m_log.Debug(string.Format("JsonRpc request '{0}' to {1} failed", method, uri), e);
                return(false);
            }

            // parse JSON separately from PostToService cuz libopenmetaverse OSDJson.cs messes up bigly
            if (response.ContainsKey("_RawResult"))
            {
                // get raw string returned by webserver and
                // see if it starts with '{' and ends with '}' indicating JSON
                string raw = response["_RawResult"].ToString().Trim();
                if (raw.StartsWith("{") && raw.EndsWith("}"))
                {
                    m_log.Debug("[JsonRpcRequestManager] JsonRpcRequest*: raw=<" + raw + ">");

                    // all we need are the "key":primvalue phrases
                    Dictionary <string, object> kvps = new Dictionary <string, object> ();
                    int    rawlen = raw.Length;
                    string key    = null;
                    object val    = null;
                    for (int i = 0; i < rawlen; i++)
                    {
                        char c = raw[i];
                        switch (c)
                        {
                        // discard any key before these as the value isn't a primitive
                        case '{':
                        case '[': {
                            key = null;
                            val = null;
                            break;
                        }

                        // quoted string key or primitive value
                        case '"': {
                            StringBuilder sb = new StringBuilder(rawlen - i);
                            while (++i < rawlen)
                            {
                                c = raw[i];
                                if (c == '"')
                                {
                                    break;
                                }
                                if ((c == '\\') && (++i < rawlen))
                                {
                                    c = raw[i];
                                    switch (c)
                                    {
                                    case 'b': c = '\b'; break;

                                    case 'n': c = '\n'; break;

                                    case 'r': c = '\r'; break;

                                    case 't': c = '\t'; break;
                                    }
                                }
                                sb.Append(c);
                            }
                            val = sb.ToString();
                            break;
                        }

                        // value just before colon is a key as a string
                        case ':': {
                            key = (string)val;
                            val = null;
                            break;
                        }

                        // other primitive values: null, boolean, integer, double
                        default: {
                            if (c <= ' ')
                            {
                                break;
                            }

                            // find end of value, first of } ] , space
                            int j = i;
                            while (++j < rawlen)
                            {
                                c = raw[j];
                                if (c <= ' ')
                                {
                                    break;
                                }
                                if ((c == '}') || (c == ']') || (c == ','))
                                {
                                    break;
                                }
                            }

                            // get value as a lower case string
                            string rlc = raw.Substring(i, j - i).ToLowerInvariant();

                            // next through loop proceses the } ] , space
                            i = --j;

                            // must be one of these
                            double d;
                            int    k;
                            if (rlc == "null")
                            {
                                val = null;
                            }
                            else if (rlc == "false")
                            {
                                val = false;
                            }
                            else if (rlc == "true")
                            {
                                val = true;
                            }
                            else if (int.TryParse(rlc, out k))
                            {
                                val = k;
                            }
                            else if (double.TryParse(rlc, out d))
                            {
                                val = d;
                            }
                            else
                            {
                                throw new ApplicationException("bad json value " + rlc);
                            }
                            break;
                        }

                        // these come after a possible primitive value
                        case '}':
                        case ']':
                        case ',': {
                            if (key != null)
                            {
                                kvps[key.ToLowerInvariant()] = val;
                            }
                            key = null;
                            val = null;
                            break;
                        }
                        }
                    }
                    foreach (string kkk in kvps.Keys)
                    {
                        val = kvps[kkk];
                        m_log.Debug("[JsonRpcRequestManager] JsonRpcRequest*: kvps[" + kkk + "]=(" + val.GetType().Name + ")" + val.ToString());
                    }

                    // scan through all serializable fields of the given object
                    Type        t      = parameters.GetType();
                    FieldInfo[] fields = t.GetFields();
                    for (int i = 0; i < fields.Length; i++)
                    {
                        FieldInfo field = fields[i];
                        if (!Attribute.IsDefined(field, typeof(NonSerializedAttribute)))
                        {
                            // see if there is a like-named field present in the JSON string
                            key = field.Name.ToLowerInvariant();
                            if (kvps.TryGetValue(key, out val))
                            {
                                m_log.Debug("[JsonRpcRequestManager] JsonRpcRequest*: " + field.FieldType.Name + " " + t.Name + "." + field.Name + "=" + val.ToString());

                                // store value in given object
                                field.SetValue(parameters, val);
                            }
                        }
                    }
                    return(true);
                }
            }

            if (!response.ContainsKey("_Result"))
            {
                m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
                                  method, uri, OSDParser.SerializeJsonString(response));
                return(false);
            }
            response = (OSDMap)response["_Result"];

            OSD data;

            if (response.ContainsKey("error"))
            {
                data = response["error"];
                m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an error: {2}",
                                  method, uri, OSDParser.SerializeJsonString(data));
                return(false);
            }

            if (!response.ContainsKey("result"))
            {
                m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
                                  method, uri, OSDParser.SerializeJsonString(response));
                return(false);
            }

            data = response["result"];
            OSD.DeserializeMembers(ref parameters, (OSDMap)data);

            return(true);
        }
        /// <summary>
        /// Sends json-rpc request with a serializable type.
        /// </summary>
        /// <returns>
        /// OSD Map.
        /// </returns>
        /// <param name='parameters'>
        /// Serializable type .
        /// </param>
        /// <param name='method'>
        /// Json-rpc method to call.
        /// </param>
        /// <param name='uri'>
        /// URI of json-rpc service.
        /// </param>
        /// <param name='jsonId'>
        /// Id for our call.
        /// </param>
        public bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
        {
            if (jsonId == null)
            {
                throw new ArgumentNullException("jsonId");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            OSDMap request = new OSDMap();

            request.Add("jsonrpc", OSD.FromString("2.0"));
            request.Add("id", OSD.FromString(jsonId));
            request.Add("method", OSD.FromString(method));
            request.Add("params", OSD.SerializeMembers(parameters));

            OSDMap response;

            try
            {
                response = WebUtil.PostToService(uri, request, 10000, true);
            }
            catch (Exception e)
            {
                m_log.Debug(string.Format("JsonRpc request '{0}' failed", method), e);
                return(false);
            }

            if (!response.ContainsKey("_Result"))
            {
                m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}",
                                  method, OSDParser.SerializeJsonString(response));
                return(false);
            }
            response = (OSDMap)response["_Result"];

            OSD data;

            if (response.ContainsKey("error"))
            {
                data = response["error"];
                m_log.DebugFormat("JsonRpc request '{0}' returned an error: {1}",
                                  method, OSDParser.SerializeJsonString(data));
                return(false);
            }

            if (!response.ContainsKey("result"))
            {
                m_log.DebugFormat("JsonRpc request '{0}' returned an invalid response: {1}",
                                  method, OSDParser.SerializeJsonString(response));
                return(false);
            }

            data = response["result"];
            OSD.DeserializeMembers(ref parameters, (OSDMap)data);

            return(true);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Sends json-rpc request with a serializable type.
        /// </summary>
        /// <returns>
        /// OSD Map.
        /// </returns>
        /// <param name='parameters'>
        /// Serializable type .
        /// </param>
        /// <param name='method'>
        /// Json-rpc method to call.
        /// </param>
        /// <param name='uri'>
        /// URI of json-rpc service.
        /// </param>
        /// <param name='jsonId'>
        /// Id for our call.
        /// </param>
        public bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
        {
            if (jsonId == null)
            {
                throw new ArgumentNullException("jsonId");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (string.IsNullOrWhiteSpace(uri))
            {
                return(false);
            }

            OSDMap request = new OSDMap();

            request.Add("jsonrpc", OSD.FromString("2.0"));
            request.Add("id", OSD.FromString(jsonId));
            request.Add("method", OSD.FromString(method));
            request.Add("params", OSD.SerializeMembers(parameters));

            OSDMap response;

            try
            {
                response = WebUtil.PostToService(uri, request, 10000, true);
            }
            catch (Exception e)
            {
                m_log.Debug(string.Format("JsonRpc request '{0}' to {1} failed", method, uri), e);
                return(false);
            }

            OSD osdtmp;

            if (!response.TryGetValue("_Result", out osdtmp) || !(osdtmp is OSDMap))
            {
                m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
                                  method, uri, OSDParser.SerializeJsonString(response));
                return(false);
            }

            response = osdtmp as OSDMap;
            if (response.TryGetValue("error", out osdtmp))
            {
                m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an error: {2}",
                                  method, uri, OSDParser.SerializeJsonString(osdtmp));
                return(false);
            }

            if (!response.TryGetValue("result", out osdtmp) || !(osdtmp is OSDMap))
            {
                m_log.DebugFormat("JsonRpc request '{0}' to {1} returned an invalid response: {2}",
                                  method, uri, OSDParser.SerializeJsonString(response));
                return(false);
            }

            OSD.DeserializeMembers(ref parameters, (OSDMap)osdtmp);
            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sends json-rpc request with a serializable type.
        /// </summary>
        /// <returns>
        /// OSD Map.
        /// </returns>
        /// <param name='parameters'>
        /// Serializable type .
        /// </param>
        /// <param name='method'>
        /// Json-rpc method to call.
        /// </param>
        /// <param name='uri'>
        /// URI of json-rpc service.
        /// </param>
        /// <param name='jsonId'>
        /// Id for our call.
        /// </param>
        bool JsonRpcRequest(ref object parameters, string method, string uri, string jsonId)
        {
            if (jsonId == null)
            {
                throw new ArgumentNullException("jsonId");
            }
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Prep our payload
            OSDMap json = new OSDMap();

            json.Add("jsonrpc", OSD.FromString("2.0"));
            json.Add("id", OSD.FromString(jsonId));
            json.Add("method", OSD.FromString(method));
            // Experiment
            json.Add("params", OSD.SerializeMembers(parameters));

            string jsonRequestData = OSDParser.SerializeJsonString(json);

            byte[] content = Encoding.UTF8.GetBytes(jsonRequestData);

            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);

            // webRequest.Credentials = new NetworkCredential(rpcUser, rpcPass);
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method      = "POST";

            Stream dataStream = webRequest.GetRequestStream();

            dataStream.Write(content, 0, content.Length);
            dataStream.Close();

            WebResponse webResponse = null;

            try
            {
                webResponse = webRequest.GetResponse();
            }
            catch (WebException e)
            {
                Console.WriteLine("Web Error" + e.Message);
                Console.WriteLine("Please check input");
                return(false);
            }

            Stream rstream = webResponse.GetResponseStream();
            OSDMap mret    = (OSDMap)OSDParser.DeserializeJson(rstream);

            if (mret.ContainsKey("error"))
            {
                return(false);
            }

            // get params...
            OSD.DeserializeMembers(ref parameters, (OSDMap)mret["result"]);
            return(true);
        }