/*********************************************************** **函数名 encodevalue **输入: ** method 请求方法 "get" or "post" url_path openapi名称 params 请求参数 secret 密钥 **输出: ** **返回: 签名 **描述: 回调发货URL专用的编码算法 ** 编码规则为:除了 0~9 a~z A~Z !*()之外其他字符按其ASCII码的十六进制加%进行表示,例如"-"编码为"%2D" ** http://wiki.open.qq.com/wiki/%E5%9B%9E%E8%B0%83%E5%8F%91%E8%B4%A7URL%E7%9A%84%E5%8D%8F%E8%AE%AE%E8%AF%B4%E6%98%8E_V3 **************************************************************/ string CSnsSigCheck::encodevalue(string& value) { string encodedata; char c; char tmp[4]={'\0'}; for (unsigned int i = 0; i < value.size(); i++) { c = value[i]; if (!isalpha(c) && !isdigit(c)&& !IsSpecialChar(c)) { snprintf(tmp,sizeof(tmp),"%%%02X",c); encodedata.append(tmp); } else { encodedata.append(1,c); } } return encodedata; }
/*--------------------------------------------------------------------------------------*/ int p3parseline(char *line, char **argv) { char *bptr; /* Pointer into the buffer buf */ char *tptr; /* Temp pointer */ int intoken; /* Are we in the middle of reading a token in? */ int argc; /* Number of args */ int bg; /* Background job? */ if ((strlen(line)*2) > MAXLINE) { HandleError("Line too long for p3parseline\n"); } argc = 0; intoken = 0; /* Copy line into buf character-by-character to create the argv strings */ bptr = buf; tptr = line; while (*tptr != '\n') { if (IsWhiteSpace(*tptr)) { *bptr++ = '\0'; /* insert \0 to terminate current token */ intoken = 0; } else if (IsSpecialChar(*tptr)) { /* stand-alone token -- add room for \0 */ if (intoken) { *bptr++ = '\0'; intoken = 0; } argv[argc++] = bptr; *bptr++ = *tptr; *bptr++ = '\0'; } else if (*tptr == '"') { /* starting a string -- copy until matching \" */ if (intoken) { *bptr++ = '\0'; intoken = 0; } argv[argc++] = bptr; tptr++; while ((*tptr != '\"') && (*tptr != '\0')) *bptr++ = *tptr++; if (*tptr == '\0') { HandleError("String not terminated -- missing double quote\n"); } else { *bptr++ = '\0'; } } else { /* non-special character */ if (intoken) *bptr++ = *tptr; else { intoken = 1; argv[argc++] = bptr; *bptr++ = *tptr; } } tptr++; /* move to the next character */ } *bptr = '\0'; /* terminate the last token */ argv[argc] = NULL; if (argc == 0) /* Ignore blank line */ return 1; /* Should the job run in the background? */ if ((bg = (*argv[argc-1] == '&')) != 0) argv[--argc] = NULL; #ifdef P3PARSELINE_DEBUG int i; for (i = 0; i < argc; i++) printf("argv[%d] = '%s'\n", i, argv[i]); #endif return bg; }