⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requestvalidation.java

📁 基于JAINSIP的一个proxy源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
             that the subscription has been accepted and that the user is             authorized to subscribe to the requested resource.  A 202 response             merely indicates that the subscription has been understood, and that             authorization may or may not have been granted.             */                                   Response response=messageFactory.createResponse(Response.ACCEPTED,                       request);                       if (serverTransaction!=null)                           serverTransaction.sendResponse(response);                       else sipProvider.sendResponse(response);                       if (ProxyDebug.debug)                           ProxyDebug.println("RequestValidation: validateRequest(),"+                           " 202 ACCEPTED replied:\n"+response.toString());                       return false;                   }               }           }                      // All the checks are passed:           return true;                   }        catch(Exception e) {            if (ProxyDebug.debug) {                   ProxyDebug.println(                   "RequestValidation: validateRequest(), exception raised:");                   ProxyDebug.logException(e);            }            return false;        }    }        private boolean checkURIScheme(Request request) {        try{            URI requestURI=request.getRequestURI();            String uriScheme=requestURI.getScheme();            return uriScheme.equals("sip") ||                   uriScheme.equals("sips") ||                   uriScheme.equals("tel");                }        catch(Exception e) {             if (ProxyDebug.debug) {                   ProxyDebug.println(                   "RequestValidation: checkURIScheme(), exception raised:");                   ProxyDebug.logException(e);             }             return false;        }    }        private boolean checkMaxForwards(Request request) {        try{            HeaderFactory headerFactory= proxy.getHeaderFactory();            MessageFactory messageFactory = proxy.getMessageFactory();                       MaxForwardsHeader mf = (MaxForwardsHeader) request.getHeader                (MaxForwardsHeader.NAME);            if (mf == null) {                // We don't add one here!!! We will do it on the cloned request                // that we are going to forward later.                return true;            }                         if ( mf.getMaxForwards() == 0) {                return false;            }             else {               // We don't decrement here!!! We will do it on the cloned request               // that we are going to forward later.                return true;            }           }        catch(Exception e) {             if (ProxyDebug.debug) {                   ProxyDebug.println(                   "RequestValidation: checkMaxForwards(), exception raised:");                   ProxyDebug.logException(e);             }             return false;        }    }         private boolean checkLoopDetection(Request request) {        try{            SipStack sipStack=proxy.getSipStack();            ListIterator viaList=request.getHeaders(ViaHeader.NAME);            if (viaList==null )                return false;                    String stackIPAddress=sipStack.getIPAddress();                       while (viaList.hasNext() ) {                ViaHeader viaHeader=(ViaHeader)viaList.next();                String host=viaHeader.getHost();                if (host.equals(stackIPAddress)) {                //    ProxyDebug.println("RequestValidation, checkLoopDetection(),"+                //    " the via address matches the proxy address");                    Iterator lps=sipStack.getListeningPoints();                    while (lps!=null && lps.hasNext() ) {                        ListeningPoint lp = (ListeningPoint)lps.next();                        int port = lp.getPort();                        if (viaHeader.getPort()==port) {                             ProxyDebug.println("RequestValidation, checkLoopDetection(),"+                    " the via port matches the proxy port");                                                          // We have to check the branch-ids...                             // TO DO.                                                         return false;                        }                    }                }            }            return true;                    }        catch(Exception e) {             if (ProxyDebug.debug) {                   ProxyDebug.println(                   "RequestValidation: checkLoopDetection(), exception raised:");                   ProxyDebug.logException(e);             }             return false;        }    }         private boolean checkProxyRequire(Request request) {        try{                       ProxyRequireHeader prh = (ProxyRequireHeader) request.getHeader                (ProxyRequireHeader.NAME);            if (prh == null) return true;            else {                // We don't support any option tags. So we reject the request:                return false;            }        }        catch(Exception e) {             if (ProxyDebug.debug) {                   ProxyDebug.println(                   "RequestValidation: checkProxyRequire(), exception raised:");                   ProxyDebug.logException(e);             }             return false;        }    }        private boolean checkProxyAuthorization(Request request) {        try{            Configuration configuration=proxy.getConfiguration();            Authentication authentication=proxy.getAuthentication();            if (configuration.enableAuthentication) {                 return authentication.isAuthorized(request);            }            else return true;                    }        catch(Exception e) {            if (ProxyDebug.debug) {                ProxyDebug.println(                "RequestValidation: checkProxyAuthorization(), exception raised:");                ProxyDebug.logException(e);            }            return false;        }    }          private boolean checkFromTag(Request request) {        try{            if (request.getMethod().equals("REGISTER")) return true;             FromHeader fh = (FromHeader) request.getHeader                (FromHeader.NAME);            return (fh.getTag() != null);                    }        catch(Exception e) {             if (ProxyDebug.debug) {                   ProxyDebug.println(                   "RequestValidation: checkFromTag(), exception raised:");                   ProxyDebug.logException(e);             }             return false;        }    }        private boolean checkEventHeader(Request request) {        try{            EventHeader eventHeader=(EventHeader)request.getHeader(            EventHeader.NAME);           // return eventHeader!=null;            // For Microsoft interoperability:            return true;        }        catch(Exception e) {            if (ProxyDebug.debug) {                ProxyDebug.println(                "RequestValidation: checkEventHeader(), exception raised:");                ProxyDebug.logException(e);            }            return false;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -