📄 slp_compare.c
字号:
} return 0;}/*=========================================================================*/int SLPIntersectStringList(int list1len, const char* list1, int list2len, const char* list2)/* Calculates the number of common entries between two string-lists *//* *//* list1 - pointer to the string-list to be checked *//* *//* list1len - length in bytes of the list to be checked *//* *//* list2 - pointer to the string-list to be checked *//* *//* list2len - length in bytes of the list to be checked *//* *//* Returns - The number of common entries. *//*=========================================================================*/{ int result = 0; char* listend = (char*)list1 + list1len; char* itembegin = (char*)list1; char* itemend = itembegin; while(itemend < listend) { itembegin = itemend; /* seek to the end of the next list item */ while(1) { if(itemend == listend || *itemend == ',') { if(*(itemend - 1) != '\\') { break; } } itemend ++; } if(SLPContainsStringList(list2len, list2, itemend - itembegin, itembegin)) { result ++; } itemend ++; } return result;}/*=========================================================================*/int SLPUnionStringList(int list1len, const char* list1, int list2len, const char* list2, int* unionlistlen, char * unionlist)/* Generate a string list that is a union of two string lists *//* *//* list1len - length in bytes of list1 *//* *//* list1 - pointer to a string-list *//* *//* list2len - length in bytes of list2 *//* *//* list2 - pointer to a string-list *//* *//* unionlistlen - pointer to the size in bytes of the unionlist buffer. *//* also receives the size in bytes of the unionlist buffer *//* on successful return. *//* *//* unionlist - pointer to the buffer that will receive the union list. */ /* *//* *//* Returns - Length of the resulting union list or negative if *//* unionlist is not big enough. If negative is returned *//* *unionlist will be changed indicate the size of unionlist *//* buffer needed *//* *//* Important: In order ensure that unionlist does not contain any *//* duplicates, at least list1 must not have any duplicates. *//* Also, for speed optimization if list1 and list2 are both *//* with out duplicates, the larger list should be passed in *//* as list1. *//* *//* Note: A good size for unionlist (so that non-zero will never be *//* returned) is list1len + list2len + 1 *//*=========================================================================*/{ char* listend = (char*)list2 + list2len; char* itembegin = (char*)list2; char* itemend = itembegin; int itemlen; int copiedlen; if(unionlist == 0 || *unionlistlen == 0 || *unionlistlen < list1len) { *unionlistlen = list1len + list2len + 1; return -1; } /* Copy list1 into the unionlist since it should not have any duplicates */ memcpy(unionlist,list1,list1len); copiedlen = list1len; while(itemend < listend) { itembegin = itemend; /* seek to the end of the next list item */ while(1) { if(itemend == listend || *itemend == ',') { if(*(itemend - 1) != '\\') { break; } } itemend ++; } itemlen = itemend - itembegin; if(SLPContainsStringList(list1len, list1, itemlen, itembegin) == 0) { if(copiedlen + itemlen + 1 > *unionlistlen) { *unionlistlen = list1len + list2len + 1; return -1; } /* append a comma if not the first entry*/ if(copiedlen) { unionlist[copiedlen] = ','; copiedlen++; } memcpy(unionlist + copiedlen, itembegin, itemlen); copiedlen += itemlen; } itemend ++; } *unionlistlen = copiedlen; return copiedlen;}/*=========================================================================*/int SLPSubsetStringList(int listlen, const char* list, int sublistlen, const char* sublist)/* Test if sublist is a set of list *//* *//* list - pointer to the string-list to be checked *//* *//* listlen - length in bytes of the list to be checked *//* *//* sublistlistlen - pointer to the string-list to be checked *//* *//* sublist - length in bytes of the list to be checked *//* *//* Returns - non-zero is sublist is a subset of list. Zero otherwise *//*=========================================================================*/{ /* count the items in sublist */ int curpos; int sublistcount; if(sublistlen ==0 || listlen == 0) { return 0; } curpos = 0; sublistcount = 1; while(curpos < sublistlen) { if(sublist[curpos] == ',') { sublistcount ++; } curpos ++; } if(SLPIntersectStringList(listlen, list, sublistlen, sublist) == sublistcount) { return sublistcount; } return 0;}/*=========================================================================*/int SLPCheckServiceUrlSyntax(const char* srvurl, int srvurllen)/* Test if a service url conforms to accepted syntax * * srvurl - (IN) service url string to check * * srvurllen - (IN) length of srvurl in bytes * * Returns - zero if srvurl has acceptable syntax, non-zero on failure * *=========================================================================*/{ /* TODO: Do we actually need to do something here to ensure correct * service-url syntax, or should we expect that it will be used * by smart developers who know that ambiguities could be encountered * if they don't? if(srvurllen < 8) { return 1; } if(strncasecmp(srvurl,"service:",8)) { return 1; } return 0; */ return 0;} /*=========================================================================*/int SLPCheckAttributeListSyntax(const char* attrlist, int attrlistlen)/* Test if a service url conforms to accepted syntax * * attrlist - (IN) attribute list string to check * * attrlistlen - (IN) length of attrlist in bytes * * Returns - zero if srvurl has acceptable syntax, non-zero on failure * *=========================================================================*/{ const char* slider; const char* end; if(attrlistlen) { slider = attrlist; end = attrlist + attrlistlen; while(slider != end) { if(*slider == '(') { while(slider != end) { if(*slider == '=') { return 0; } slider++; } return 1; } slider++; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -