Exemple #1
0
        // 解析出init请求中的 鉴别信息
        // parameters:
        //      nAuthentType 0: open(simple) 1:idPass(group)
        static int DecodeAuthentication(
            BerNode root,
            out string strGroupId,
            out string strUserId,
            out string strPassword,
            out int nAuthentType,
            out string strError)
        {
            strGroupId   = "";
            strUserId    = "";
            strPassword  = "";
            nAuthentType = 0;
            strError     = "";

            if (root == null)
            {
                strError = "root == null";
                return(-1);
            }

            string strOpen = ""; // open mode authentication


            for (int i = 0; i < root.ChildrenCollection.Count; i++)
            {
                BerNode node = root.ChildrenCollection[i];
                switch (node.m_uTag)
                {
                case BerNode.ASN1_SEQUENCE:

                    nAuthentType = 1;       //  "GROUP";
                    for (int k = 0; k < node.ChildrenCollection.Count; k++)
                    {
                        BerNode nodek = node.ChildrenCollection[k];
                        switch (nodek.m_uTag)
                        {
                        case 0:         // groupId
                            strGroupId = nodek.GetCharNodeData();
                            break;

                        case 1:         // userId
                            strUserId = nodek.GetCharNodeData();
                            break;

                        case 2:         // password
                            strPassword = nodek.GetCharNodeData();
                            break;
                        }
                    }

                    break;

                case BerNode.ASN1_VISIBLESTRING:
                case BerNode.ASN1_GENERALSTRING:
                    nAuthentType = 0;     //  "SIMPLE";
                    strOpen      = node.GetCharNodeData();
                    break;
                }
            }

            if (nAuthentType == 0)
            {
                int nRet = strOpen.IndexOf("/");
                if (nRet != -1)
                {
                    strUserId   = strOpen.Substring(0, nRet);
                    strPassword = strOpen.Substring(nRet + 1);
                }
                else
                {
                    strUserId = strOpen;
                }
            }

            return(0);
        }
Exemple #2
0
        // 解码RPN结构中的Attribute + Term结构
        static int DecodeAttributeAndTerm(
            Encoding term_encoding,
            BerNode pNode,
            out long lAttributeType,
            out long lAttributeValue,
            out string strTerm,
            out string strError)
        {
            lAttributeType  = 0;
            lAttributeValue = 0;
            strTerm         = "";
            strError        = "";

            if (pNode == null)
            {
                strError = "node == null";
                return(-1);
            }

            if (pNode.ChildrenCollection.Count < 2) //attriblist + term
            {
                strError = "bad RPN query";
                return(-1);
            }

            BerNode pAttrib = pNode.ChildrenCollection[0]; // attriblist
            BerNode pTerm   = pNode.ChildrenCollection[1]; // term

            if (44 != pAttrib.m_uTag)                      // Attributes
            {
                strError = "only support Attributes";
                return(-1);
            }

            if (45 != pTerm.m_uTag) // Term
            {
                strError = "only support general Term";
                return(-1);
            }

            // get attribute type and value
            if (pAttrib.ChildrenCollection.Count < 1) //attribelement
            {
                strError = "bad RPN query";
                return(-1);
            }

            pAttrib = pAttrib.ChildrenCollection[0];
            if (16 != pAttrib.m_uTag) //attribelement (SEQUENCE)
            {
                strError = "only support Attributes";
                return(-1);
            }

            for (int i = 0; i < pAttrib.ChildrenCollection.Count; i++)
            {
                BerNode pTemp = pAttrib.ChildrenCollection[i];
                switch (pTemp.m_uTag)
                {
                case 120:     // attributeType
                    lAttributeType = pTemp.GetIntegerNodeData();
                    break;

                case 121:     // attributeValue
                    lAttributeValue = pTemp.GetIntegerNodeData();
                    break;
                }
            }

            // get term
            strTerm = pTerm.GetCharNodeData(term_encoding);

            if (-1 == lAttributeType ||
                -1 == lAttributeValue ||
                String.IsNullOrEmpty(strTerm) == true)
            {
                strError = "bad RPN query";
                return(-1);
            }

            return(0);
        }
Exemple #3
0
        // 根据RPN创建XML检索式
        // 本函数要递归调用,检索数据库并返回结果集
        // parameters:
        //		node    RPN 结构的根结点
        //		strXml[out] 返回局部XML检索式
        // return:
        //      -1  出错
        //      0   数据库没有找到
        //      1   成功
        public static int BuildQueryXml(
            ZHostInfo zhost,
            List <string> dbnames,
            BerNode node,
            Encoding searchTermEncoding,
            out string strQueryXml,
            out string strError)
        {
            strQueryXml = "";
            strError    = "";
            int nRet = 0;

            if (node == null)
            {
                strError = "node == null";
                return(-1);
            }

            if (0 == node.m_uTag)
            {
                // operand node

                // 检索得到 saRecordID
                if (node.ChildrenCollection.Count < 1)
                {
                    strError = "bad RPN structure";
                    return(-1);
                }

                BerNode pChild = node.ChildrenCollection[0];

                if (102 == pChild.m_uTag)
                {
                    // AttributesPlusTerm
                    long nAttributeType  = -1;
                    long nAttributeValue = -1;

                    nRet = DecodeAttributeAndTerm(
                        searchTermEncoding,
                        pChild,
                        out nAttributeType,
                        out nAttributeValue,
                        out string strTerm,
                        out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }

                    // return:
                    //      -1  出错
                    //      0   数据库没有找到
                    //      1   成功
                    nRet = BuildOneXml(
                        zhost,
                        dbnames,
                        strTerm,
                        nAttributeValue,
                        out strQueryXml,
                        out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }
                    if (nRet == 0)
                    {
                        return(0);
                    }

                    return(1);
                }
                else if (31 == pChild.m_uTag)
                {
                    // 是结果集参预了检索
                    string strResultSetID = pChild.GetCharNodeData();

                    strQueryXml = "<item><resultSetName>" + strResultSetID + "</resultSetName></item>";

                    /*
                     * //
                     * // 为了避免在递归运算时删除了以前保留的结果集,copy 一份
                     * if (!FindAndCopyExistResultSet(strResultSetID, pResult)) {
                     *  throw_exception(0, _T("referred resultset not exist"));
                     * }
                     * //
                     * */
                }
                else
                {
                    //
                    strError = "Unsurported RPN structure";
                }
            }
            else if (1 == node.m_uTag)
            {
                // rpnRpnOp
                //
                if (3 != node.ChildrenCollection.Count)
                {
                    strError = "bad RPN structure";
                    return(-1);
                }
                //
                int nOperator = -1;

                nRet = BuildQueryXml(
                    zhost,
                    dbnames,
                    node.ChildrenCollection[0],
                    searchTermEncoding,
                    out string strXmlLeft,
                    out strError);
                if (nRet == -1 || nRet == 0)
                {
                    return(nRet);
                }

                nRet = BuildQueryXml(
                    zhost,
                    dbnames,
                    node.ChildrenCollection[1],
                    searchTermEncoding,
                    out string strXmlRight,
                    out strError);
                if (nRet == -1 || nRet == 0)
                {
                    return(nRet);
                }

                //	and     [0]
                //	or      [1]
                //	and-not [2]
                nOperator = DecodeRPNOperator(node.ChildrenCollection[2]);
                if (nOperator == -1)
                {
                    strError = "DecodeRPNOperator() return -1";
                    return(-1);
                }

                switch (nOperator)
                {
                case 0:     // and
                    strQueryXml = "<group>" + strXmlLeft + "<operator value='AND' />" + strXmlRight + "</group>";
                    break;

                case 1:     // or
                    strQueryXml = "<group>" + strXmlLeft + "<operator value='OR' />" + strXmlRight + "</group>";
                    break;

                case 2:     // and-not
                    strQueryXml = "<group>" + strXmlLeft + "<operator value='SUB' />" + strXmlRight + "</group>";
                    break;

                default:
                    // 不支持的操作符
                    strError = "unsurported operator";
                    return(-1);
                }
            }
            else
            {
                strError = "bad RPN structure";
            }

            return(1);
        }