📄 libslp_parse.c
字号:
current_outBuf++; /* Do the last digit. */ hex_digit = *current_inbuf & 0x0F; if((hex_digit >= 0) && (hex_digit <= 9)) *current_outBuf = hex_digit + '0'; else *current_outBuf = hex_digit + 'A' - 0x0A; } else { *current_outBuf = *current_inbuf; } /* End If, Else. */ current_outBuf += sizeof(char); current_inbuf += sizeof(char); } /* End While. */ /* Make sure that the string is properly terminated. */ *current_outBuf = '\0'; return(SLP_OK);}/*=========================================================================*/SLPError SLPAPI SLPUnescape(const char* pcInbuf, char** ppcOutBuf, SLPBoolean isTag)/* *//* Process the input string in pcInbuf and unescape any SLP reserved *//* characters. If the isTag parameter is SLPTrue, then look for bad tag *//* characters and signal an error if any are found with the *//* SLP_PARSE_ERROR code. No transformation is performed if the input *//* string is an opaque. The results are put into a buffer allocated by *//* the API library and returned in the ppcOutBuf parameter. This buffer *//* should be deallocated using SLPFree() when the memory is no longer *//* needed. *//* *//* pcInbuf Pointer to he input buffer to process for escape *//* characters. *//* *//* ppcOutBuf Pointer to a pointer for the output buffer with the SLP *//* reserved characters escaped. Must be freed using *//* SLPFree() when the memory is no longer needed. *//* *//* isTag When true, the input buffer is checked for bad tag *//* characters. *//* *//* Returns: Return SLP_PARSE_ERROR if any characters are bad tag *//* characters and the isTag flag is true, otherwise SLP_OK, *//* or the appropriate error code if another error occurs. *//*=========================================================================*/{ int output_buffer_size; char *current_Inbuf, *current_OutBuf; char escaped_digit[2]; /* Ensure that the parameters are good. */ if((pcInbuf == NULL) || ((isTag != SLP_TRUE) && (isTag != SLP_FALSE))) return(SLP_PARAMETER_BAD); /* * Loop thru the string, counting the number of escape characters * and checking for bad tags when required. This is also used to * calculate the size of the new string to create. * ASSUME: that pcInbuf is a NULL terminated string. */ current_Inbuf = (char *) pcInbuf; output_buffer_size = strlen(pcInbuf); while(*current_Inbuf != '\0') { /* Ensure that there are no bad tags when it is a tag. */ if((isTag) && strchr(ATTRIBUTE_BAD_TAG, *current_Inbuf)) return(SLP_PARSE_ERROR); if(strchr(ESCAPE_CHARACTER_STRING, *current_Inbuf)) output_buffer_size-=2; current_Inbuf++; } /* End While. */ /* Allocate the string. */ *ppcOutBuf = (char *) xmalloc((sizeof(char) * output_buffer_size) + 1); if(ppcOutBuf == NULL) return(SLP_MEMORY_ALLOC_FAILED); current_Inbuf = (char *) pcInbuf; current_OutBuf = *ppcOutBuf; while(*current_Inbuf != '\0') { /* Check to see if it is an escape character. */ if(strchr(ESCAPE_CHARACTER_STRING, *current_Inbuf)) { /* Insert the real character based on the escaped character. */ escaped_digit[0] = *(current_Inbuf + sizeof(char)); escaped_digit[1] = *(current_Inbuf + (sizeof(char) * 2)); if((escaped_digit[0] >= 'A') && (escaped_digit[0] <= 'F')) escaped_digit[0] = escaped_digit[0] - 'A' + 0x0A; else if((escaped_digit[0] >= '0') && (escaped_digit[0] <= '9')) escaped_digit[0] = escaped_digit[0] - '0'; else return(SLP_PARSE_ERROR); if((escaped_digit[1] >= 'A') && (escaped_digit[1] <= 'F')) escaped_digit[1] = escaped_digit[1] - 'A' + 0x0A; else if((escaped_digit[1] >= '0') && (escaped_digit[1] <= '9')) escaped_digit[1] = escaped_digit[1] - '0'; else return(SLP_PARSE_ERROR); *current_OutBuf = escaped_digit[1] + (escaped_digit[0] * 0x10); current_Inbuf = (char *) current_Inbuf + (sizeof(char) * 2); } else { *current_OutBuf = *current_Inbuf; } /* End If, Else. */ /* Move to the next character. */ current_OutBuf++; current_Inbuf++; } /* End While. */ /* Make sure we terminate the string properly. */ *current_OutBuf = '\0'; return(SLP_OK);}/*=========================================================================*/SLPError SLPAPI SLPParseAttrs(const char* pcAttrList, const char *pcAttrId, char** ppcAttrVal)/* *//* Used to get individual attribute values from an attribute string that *//* is passed to the SLPAttrCallback *//* *//* pcAttrList (IN) A character buffer containing a comma separated, null *//* terminated list of attribute id/value assignments, in *//* SLP wire format; i.e. "(attr-id=attr-value-list)" *//* *//* pcAttrId (IN) The string indicating which attribute value to return. *//* MUST not be null. MUST not be the empty string (""). *//* *//* ppcAttrVal (IN) A pointer to a pointer to the buffer to receive *//* attribute value. The memory should be freed by a call *//* to SLPFree() when no longer needed. *//* *//* Returns: Returns SLP_PARSE_ERROR if an attribute of the specified id *//* was not found otherwise SLP_OK *//*=========================================================================*/{ const char* slider1; const char* slider2; int attridlen; /* Check for bad parameters */ if(pcAttrList == 0 || pcAttrId == 0 || ppcAttrVal == 0) { return SLP_PARAMETER_BAD; } attridlen = strlen(pcAttrId); slider1 = pcAttrList; while(1) { while(*slider1 != '(') { if(*slider1 == 0) { return SLP_PARSE_ERROR; } slider1++; } slider1++; slider2=slider1; while(*slider2 && *slider2 != '=' && *slider2 !=')') slider2++; if(attridlen == slider2-slider1 && strncasecmp(slider1, pcAttrId, slider2 - slider1) == 0) { /* found the attribute id */ slider1 = slider2; if(*slider1 == '=') slider1++; while(*slider2 && *slider2 !=')') slider2++; *ppcAttrVal = (char*)xmalloc((slider2 - slider1) + 1); if(*ppcAttrVal == 0) { return SLP_MEMORY_ALLOC_FAILED; } memcpy(*ppcAttrVal,slider1,slider2-slider1); (*ppcAttrVal)[slider2-slider1] = 0; return SLP_OK; } } /* attrid does not exist */ return SLP_PARSE_ERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -