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

📄 newproto.c

📁 安全开发库。含客户端建立ssl连接、签名、证书验证、证书发布和撤销等。编译用到nss
💻 C
📖 第 1 页 / 共 2 页
字号:
            } else {                foundChoice = CM_TRUE;            }        }        if (inList) {            srcptr = &list[listCount * listItemSize];            listCount++;        } else if (inStructList) {			srcptr = tmpl->offset + list;		} else {            srcptr = tmpl->offset + (unsigned char *)src;        }        switch(tmpl->type) {          case CMT_DT_RID:          case CMT_DT_INT:          case CMT_DT_BOOL:            len += sizeof(CMInt32);            break;          case CMT_DT_STRING:            len += sizeof(CMInt32);            /* Non NULL string */            if (*(char**)srcptr) {                len += (strlen(*(char**)srcptr) + 4) & ~3;            }            break;          case CMT_DT_ITEM:            len += sizeof(CMInt32);            len += (((CMTItem *)srcptr)->len + 3) & ~3;            break;          case CMT_DT_LIST:            len += sizeof(CMInt32);            listSize = *(CMInt32 *)srcptr;            tmpl++;            if (tmpl->type == CMT_DT_STRING) {                listItemSize = sizeof(unsigned char *);            } else if (tmpl->type == CMT_DT_ITEM) {                listItemSize = sizeof(CMTItem);            } else {                listItemSize = sizeof(CMInt32);            }            list = *(unsigned char **)(tmpl->offset + (unsigned char *)src);            listCount = 0;            inList = CM_TRUE;            break;		  case CMT_DT_STRUCT_LIST:			len += sizeof(CMInt32);			listSize = *(CMInt32 *)srcptr;			tmpl++;			if (tmpl->type != CMT_DT_STRUCT_PTR) {				goto loser;			}			list = *(unsigned char**)(tmpl->offset + (unsigned char*)src);			startOfList = tmpl;			p = tmpl;			listItemSize = 0;			while (p->type != CMT_DT_END_STRUCT_LIST) {				if (p->type == CMT_DT_STRING) {					listItemSize += sizeof(unsigned char *);				} else if (p->type == CMT_DT_ITEM) {					listItemSize += sizeof(CMTItem);				} else if (p->type == CMT_DT_INT) {					listItemSize += sizeof(CMInt32);				}				p++;			}			listCount = 0;			inStructList = CM_TRUE;			break;		  case CMT_DT_END_STRUCT_LIST:			listCount++;			if (listCount == listSize) {				inStructList = CM_FALSE;			} else {				list += listItemSize;				tmpl = startOfList;			}			break;          case CMT_DT_CHOICE:            len += sizeof(CMInt32);            choiceID = *(CMInt32 *)srcptr;            inChoice = CM_TRUE;            foundChoice = CM_FALSE;            break;          case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */          case CMT_DT_END:          default:            ASSERT(0);            break;        }        if (inList) {            if (listCount == listSize) {                inList = CM_FALSE;                tmpl++;            }        } else {            tmpl++;        }    }    *len_out = len;    return CMTSuccess;loser:    return CMTFailure;}static CMTStatusencode_int(unsigned char **curptr, void *src, CMInt32 *remaining){    CMInt32 datalen = sizeof(CMInt32);    if (*remaining < datalen)        return CMTFailure;    **(CMInt32 **)curptr = CM_htonl(*(CMInt32 *)src);    *remaining -= datalen;    *curptr += datalen;    return CMTSuccess;}static CMTStatusencode_string(unsigned char **curptr, CMInt32 len,              unsigned char *data, CMInt32 *remaining){    CMTStatus rv;    CMInt32 datalen;    rv = encode_int(curptr, &len, remaining);    if (rv != CMTSuccess)        return CMTFailure;    /* NULL string */    if (len == 0) {        goto done;    }    datalen = (len + 3) & ~3;    if (*remaining < datalen)        return CMTFailure;    memcpy(*curptr, data, len);    *remaining -= datalen;    *curptr += datalen;done:    return CMTSuccess;}/************************************************************* * CMT_EncodeMessage * * Encode src into msg as specified by tmpl. * ************************************************************/CMTStatusCMT_EncodeMessage(CMTMessageTemplate *tmpl, CMTItem *msg, void *src){    CMInt32 choiceID = 0, listSize, listItemSize, listCount, remaining;    unsigned char *srcptr, *curptr, *list;    CMBool inChoice = CM_FALSE, inList = CM_FALSE, foundChoice = CM_FALSE;    CMTStatus rv = CMTSuccess;	CMTMessageTemplate *startOfList, *p;	CMBool inStructList = CM_FALSE;    rv = calc_msg_len(tmpl, src, (long *) &msg->len);    if (rv != CMTSuccess)        goto loser;    curptr = msg->data = (unsigned char *) cmt_alloc(msg->len);    if(msg->data == NULL)        goto loser;    remaining = msg->len;    while(tmpl->type != CMT_DT_END) {        if (inChoice) {            if (tmpl->type == CMT_DT_END_CHOICE) {                if (!foundChoice)                    goto loser;                inChoice = CM_FALSE;                foundChoice = CM_FALSE;                tmpl++;                continue;            }            if (choiceID != tmpl->choiceID) {                tmpl++;                continue;  /* Not this option */            } else {                foundChoice = CM_TRUE;            }        }        if (inList) {            srcptr = &list[listCount * listItemSize];            listCount++;        } else {			if (inStructList) {				srcptr = tmpl->offset + list;			} else {				srcptr = tmpl->offset + (unsigned char *)src;			}        }        switch(tmpl->type) {          case CMT_DT_RID:          case CMT_DT_INT:          case CMT_DT_BOOL:            rv = encode_int(&curptr, srcptr, &remaining);            if (rv != CMTSuccess)                goto loser;            break;          case CMT_DT_STRING:             if (*(char**)srcptr) {                 /* Non NULL string */                 rv = encode_string(&curptr, (long) strlen(*(char**)srcptr),                  	                *(unsigned char**)srcptr, &remaining);             } else {                 /* NULL string */                 rv = encode_string(&curptr, 0L, *(unsigned char**)srcptr, &remaining);             }             if (rv != CMTSuccess)                goto loser;             break;          case CMT_DT_ITEM:            rv = encode_string(&curptr, ((CMTItem *)srcptr)->len,                               ((CMTItem *)srcptr)->data, &remaining);            if (rv != CMTSuccess)                goto loser;            break;          case CMT_DT_LIST:            rv = encode_int(&curptr, srcptr, &remaining);            if (rv != CMTSuccess)                goto loser;            listSize = *(CMInt32 *)srcptr;            tmpl++;            if (tmpl->type == CMT_DT_STRING) {                listItemSize = sizeof(unsigned char *);            } else if (tmpl->type == CMT_DT_ITEM) {                listItemSize = sizeof(CMTItem);            } else {                listItemSize = sizeof(CMInt32);            }            list = *(unsigned char **)(tmpl->offset + (unsigned char *)src);            listCount = 0;            inList = CM_TRUE;            break;		  case CMT_DT_STRUCT_LIST:            rv = encode_int(&curptr, srcptr, &remaining);            if (rv != CMTSuccess)                goto loser;            listSize = *(CMInt32 *)srcptr;			tmpl++;			if (tmpl->type != CMT_DT_STRUCT_PTR) {				goto loser;			}			list = *(unsigned char**)(tmpl->offset + (unsigned char*)src);			startOfList = tmpl;			p = tmpl;			listItemSize = 0;			while (p->type != CMT_DT_END_STRUCT_LIST) {				if (p->type == CMT_DT_STRING) {					listItemSize += sizeof(unsigned char *);				} else if (p->type == CMT_DT_ITEM) {					listItemSize += sizeof(CMTItem);				} else if (p->type == CMT_DT_INT) {					listItemSize += sizeof(CMInt32);				}				p++;			}			listCount = 0;			inStructList = CM_TRUE;			break;		  case CMT_DT_END_STRUCT_LIST:			listCount++;			if (listCount == listSize) {				inStructList = CM_FALSE;			} else {				list += listItemSize;				tmpl = startOfList;			}			break;          case CMT_DT_CHOICE:            rv = encode_int(&curptr, srcptr, &remaining);            if (rv != CMTSuccess)                goto loser;            choiceID = *(CMInt32 *)srcptr;            inChoice = CM_TRUE;            foundChoice = CM_FALSE;            break;          case CMT_DT_END_CHOICE: /* Loop should exit before we see these. */          case CMT_DT_END:          default:            ASSERT(0);            break;        }        if (inList) {            if (listCount == listSize) {                inList = CM_FALSE;                tmpl++;            }        } else {            tmpl++;        }    }    return CMTSuccess;loser:    return CMTFailure;}

⌨️ 快捷键说明

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