private void RecvData(IntPtr ptr) { this.DNS_LOG_INFO("recv data from DNS server"); DnResult result = (DnResult)Marshal.PtrToStructure(ptr, typeof(DnResult)); if (result.domainName.Length != 0) { if (this.callbackObjectDic.ContainsKey(result.domainName)) { this.DNS_LOG_INFO(string.Format("recive domainName is [{0}]", result.domainName)); this.ParseRecvData(result); } else { this.DNS_LOG_ERROR(string.Format("no such domainName[{0}] in callback object dictionary", result.domainName)); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "no domainName's delegate function in callback object dictionary"; } } else { this.DNS_LOG_ERROR("the result domainName is empty"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "the result domainName is empty"; } }
public DNSErrCode SetFileSys(IApolloDNSFileSys fileSys) { if (fileSys == null) { this.DNS_LOG_ERROR("input param error"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "the input file system pointer is empty"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } this.mFileSys = fileSys; return(DNSErrCode.DNS_NO_ERROR); }
public DNSErrCode SetCurrentAPN(string APN) { if ((APN == null) || (APN.Length == 0)) { this.DNS_LOG_ERROR("input param error"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "the input APN string is illegal"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } this.mCurrentAPN = APN; this.mUploadeUserInfo = APN; return(dns_SetCurrentAPN(base.ObjectId, APN)); }
public DNSErrCode Init(bool callbackMode, int cacheTime) { if (this.mInitStatus == DNSErrCode.DNS_NO_ERROR) { this.DNS_LOG_INFO("init had been finished"); return(DNSErrCode.DNS_NO_ERROR); } this.isCallbackMode = callbackMode; if (this.mFileSys != null) { this.ReadDNSverConfig(); } this.mInitStatus = dns_Init(base.ObjectId, callbackMode, cacheTime); this.mErrCode = dns_GetErrorCode(base.ObjectId); IntPtr ptr = dns_GetErrorString(base.ObjectId); this.mErrString = Marshal.PtrToStringAnsi(ptr); return(this.mInitStatus); }
public DNSErrCode Query(string domainName, ProcessQueryResult process, string OId, string SId, string version, string userData) { QueryValue value2; if (this.mInitStatus != DNSErrCode.DNS_NO_ERROR) { this.DNS_LOG_ERROR("init failed or uninit"); this.mErrCode = this.mInitStatus; this.mErrString = "init failed or uninit"; return(this.mInitStatus); } if ((domainName == null) || (domainName.Length == 0)) { this.DNS_LOG_ERROR("domainName is null"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "domainName is null"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } if (process == null) { this.DNS_LOG_ERROR("delegate function is null"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "delegate function is null"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } this.DNS_LOG_INFO(string.Format("domainName is [{0}]", domainName)); this.mUploadeDomainName = string.Empty; if ((((OId != null) || (version != null)) || (userData != null)) && ((SId == null) || (SId.Length == 0))) { this.DNS_LOG_ERROR("OId, version or userData is not null but the SId is null"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "OId, version or userData is not null but the SId is null"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } if ((OId != null) && (OId.Length != 0)) { this.mUploadeUserInfo = this.mUploadeUserInfo + ":" + OId; } else { this.mUploadeUserInfo = this.mUploadeUserInfo + ":N"; } if ((SId != null) && (SId.Length != 0)) { this.mUploadeUserInfo = this.mUploadeUserInfo + ":" + SId; } else { this.mUploadeUserInfo = this.mUploadeUserInfo + ":N"; } if ((version != null) && (version.Length != 0)) { this.mUploadeUserInfo = this.mUploadeUserInfo + ":" + version; } else { this.mUploadeUserInfo = this.mUploadeUserInfo + ":N"; } char[] separator = new char[] { '|' }; string[] strArray = domainName.Split(separator); List <string> domainNameList = new List <string>(); foreach (string str in strArray) { if ((str.Length != 0) && !domainNameList.Contains(str)) { domainNameList.Add(str); } } if (domainNameList.Count == 0) { this.DNS_LOG_ERROR("all domainNames is empty"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "all domainNames is empty"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } if (10 < domainNameList.Count) { this.DNS_LOG_ERROR("more then ten domainNames in the list"); this.mErrCode = DNSErrCode.DNS_TOOMANY_DOMAINNAMES; this.mErrString = "more then ten domainNames in the list"; return(DNSErrCode.DNS_TOOMANY_DOMAINNAMES); } this.DNS_LOG_INFO("all param is legal"); value2.errCode = 0L; value2.errString = "no error"; value2.value = new ListView <DnValue>(); List <string> subDomainNames = new List <string>(); if ((this.mFileSys != null) && this.isCacheEnable) { this.DNS_LOG_INFO("search domainName in cache"); this.SearchDomainNameInCache(domainNameList, ref value2, ref subDomainNames); } else { this.DNS_LOG_INFO("search all domainNames in DNS server"); foreach (string str2 in domainNameList) { subDomainNames.Add(str2); } } if (subDomainNames.Count == 0) { this.DNS_LOG_INFO("all domainName's IP exist in cache"); this.UploadStatisticData(); process(value2); return(DNSErrCode.DNS_NO_ERROR); } string str3 = string.Empty; for (int i = 0; i < (subDomainNames.Count - 1); i++) { str3 = str3 + subDomainNames[i] + "|"; } str3 = str3 + subDomainNames[subDomainNames.Count - 1]; this.DNS_LOG_INFO(string.Format("send to DNS server's domainNames are [{0}]", str3)); DNSErrCode code = dns_Query(base.ObjectId, str3, OId, SId, version, userData); this.mErrCode = dns_GetErrorCode(base.ObjectId); IntPtr ptr = dns_GetErrorString(base.ObjectId); this.mErrString = Marshal.PtrToStringAnsi(ptr); if (code != DNSErrCode.DNS_NO_ERROR) { this.DNS_LOG_ERROR(string.Format("send request failed, error code is [{0}]", Convert.ToString(code))); foreach (string str4 in subDomainNames) { DnValue value3; value3.errCode = 0x455L; value3.errString = "send request error"; value3.domainName = str4; value3.IPList = new List <string>(); value2.value.Add(value3); if (0 < this.mUploadeDomainName.Length) { this.mUploadeDomainName = this.mUploadeDomainName + ":" + str4 + "_0"; } else { this.mUploadeDomainName = this.mUploadeDomainName + str4 + "_0"; } } if (subDomainNames.Count == domainNameList.Count) { value2.errCode = 0x455L; value2.errString = "send request error"; } this.UploadStatisticData(); process(value2); return(code); } if (this.callbackObjectDic.ContainsKey(str3)) { this.callbackObjectDic[str3].Add(process); } else { ListView <ProcessQueryResult> view = new ListView <ProcessQueryResult>(); view.Add(process); this.callbackObjectDic.Add(str3, view); } if (this.isCallbackMode) { process(value2); value2.value.Clear(); } this.mInitDomainNameMap.Add(str3, value2); return(DNSErrCode.DNS_NO_ERROR); }
private void ParseRecvData(DnResult result) { QueryValue value2; this.DNS_LOG_INFO("ParseRecvData begin"); value2.errCode = 0L; value2.errString = "no error"; value2.value = new ListView <DnValue>(); foreach (KeyValuePair <string, QueryValue> pair in this.mInitDomainNameMap) { if (pair.Key == result.domainName) { QueryValue value3 = pair.Value; if (value3.value.Count != 0) { foreach (DnValue value4 in value3.value) { value2.value.Add(value4); } } } } if (result.errCode == 0) { this.DNS_LOG_INFO("result is success"); if (this.ParseJsonValue(ref result.value, ref value2) == DNSErrCode.DNS_NO_ERROR) { this.DNS_LOG_INFO("json parse success"); } else { this.DNS_LOG_ERROR("parse json date return from DNS server error"); this.mErrCode = DNSErrCode.DNS_JSON_PARSE_ERROR; this.mErrString = "parse json date return from DNS server error"; if (value2.value.Count == 0) { value2.errCode = 0x452L; value2.errString = "json parse error"; } } } else { this.DNS_LOG_ERROR("result is failed"); this.mErrCode = dns_GetErrorCode(base.ObjectId); IntPtr ptr = dns_GetErrorString(base.ObjectId); this.mErrString = Marshal.PtrToStringAnsi(ptr); if (value2.value.Count == 0) { value2.errCode = result.errCode; value2.errString = result.errString; } char[] separator = new char[] { '|' }; foreach (string str in result.domainName.Split(separator)) { DnValue value5; value5.errCode = result.errCode; value5.errString = result.errString; value5.domainName = str; value5.IPList = new List <string>(); value2.value.Add(value5); if (0 < this.mUploadeDomainName.Length) { this.mUploadeDomainName = this.mUploadeDomainName + ":" + str + "_0"; } else { this.mUploadeDomainName = this.mUploadeDomainName + str + "_0"; } } } foreach (KeyValuePair <string, ListView <ProcessQueryResult> > pair2 in this.callbackObjectDic) { if (pair2.Key == result.domainName) { ListView <ProcessQueryResult> view = pair2.Value; if (view.Count != 0) { this.DNS_LOG_INFO(string.Format("process delegate function for domainNames[{0}]", result.domainName)); ProcessQueryResult result2 = view[0]; this.UploadStatisticData(); result2(value2); view.RemoveAt(0); if (view.Count == 0) { this.mInitDomainNameMap.Remove(result.domainName); this.callbackObjectDic.Remove(result.domainName); } } else { this.DNS_LOG_INFO(string.Format("no delegate function for domainName[{0}]", result.domainName)); this.mErrCode = DNSErrCode.DNS_HANDLE_FAILED; this.mErrString = "no delegate function for domainName"; } return; } } this.DNS_LOG_INFO(string.Format("no such domainName[{0}] in dictionary", result.domainName)); this.mErrCode = DNSErrCode.DNS_HANDLE_FAILED; this.mErrString = "no such domainName in dictionary"; }
private DNSErrCode ParseJsonValue(ref string valueString, ref QueryValue queryValue) { if (valueString.Length == 0) { this.DNS_LOG_ERROR("input param error"); this.mErrCode = DNSErrCode.DNS_INPUT_PARAM_ERROR; this.mErrString = "the input json value string is empty"; return(DNSErrCode.DNS_INPUT_PARAM_ERROR); } this.DNS_LOG_INFO(string.Format("json value is [{0}]", valueString)); Dictionary <string, object> dictionary = Json.Deserialize(valueString) as Dictionary <string, object>; if ((dictionary != null) && (dictionary.Count != 0)) { long num = (long)dictionary["ErrCode"]; if (num == 0) { List <object> list = dictionary["Results"] as List <object>; foreach (object obj2 in list) { long num2 = 0L; string str = "no error"; string str2 = string.Empty; List <string> dataList = new List <string>(); Dictionary <string, object> dictionary2 = obj2 as Dictionary <string, object>; str2 = (string)dictionary2["Dn"]; long num3 = (long)dictionary2["ErrCode"]; num2 = num3; if (num3 == 0) { this.DNS_LOG_INFO(string.Format("domainName[{0}] is success", str2)); List <object> list3 = dictionary2["Ips"] as List <object>; foreach (object obj3 in list3) { Dictionary <string, object> dictionary3 = obj3 as Dictionary <string, object>; dataList.Add((string)dictionary3["Ip"]); } if (0 < this.mUploadeDomainName.Length) { this.mUploadeDomainName = this.mUploadeDomainName + ":" + str2 + "_2"; } else { this.mUploadeDomainName = this.mUploadeDomainName + str2 + "_2"; } } else { this.DNS_LOG_INFO(string.Format("domainName[{0}] is error", str2)); str = (string)dictionary2["ErrStr"]; if (0 < this.mUploadeDomainName.Length) { this.mUploadeDomainName = this.mUploadeDomainName + ":" + str2 + "_0"; } else { this.mUploadeDomainName = this.mUploadeDomainName + str2 + "_0"; } } int cacheTime = 0; if ((this.mDNSvrDomainName == str2) || (this.mDNSvrPortName == str2)) { this.DNS_LOG_INFO("current domainName is DNS server's domainName or port"); } else { DnValue value2; value2.errCode = num2; value2.errString = str; value2.domainName = str2; value2.IPList = dataList; queryValue.value.Add(value2); cacheTime = 1; } this.UpdateIPListIntoCacheDate(str2, dataList, cacheTime); } return(DNSErrCode.DNS_NO_ERROR); } this.mErrCode = (DNSErrCode)((int)num); this.mErrString = (string)dictionary["ErrStr"]; queryValue.errCode = num; queryValue.errString = (string)dictionary["ErrStr"]; return(DNSErrCode.DNS_NO_ERROR); } this.mErrCode = DNSErrCode.DNS_JSON_PARSE_ERROR; this.mErrString = "parse the json value error"; return(DNSErrCode.DNS_JSON_PARSE_ERROR); }