Changeset 13551 in vbox for trunk/src/VBox/HostServices
- Timestamp:
- Oct 24, 2008 12:10:08 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/GuestProperties/service.cpp
r13376 r13551 203 203 AssertLogRelReturn(VALID_PTR(pvService), VERR_INVALID_PARAMETER); 204 204 SELF *pSelf = reinterpret_cast<SELF *>(pvService); 205 //pSelf->mpfnHostCallback = pfnExtension;205 pSelf->mpfnHostCallback = pfnExtension; 206 206 pSelf->mpvHostData = pvExtension; 207 207 return VINF_SUCCESS; … … 614 614 615 615 /** 616 * Matches a sample name against a pattern.617 *618 * @returns True if matches, false if not.619 * @param pszPat Pattern.620 * @param pszName Name to match against the pattern.621 * @todo move this into IPRT622 */623 static bool matchesSinglePattern(const char *pszPat, const char *pszName)624 {625 /* ASSUMES ASCII */626 for (;;)627 {628 char chPat = *pszPat;629 switch (chPat)630 {631 default:632 if (*pszName != chPat)633 return false;634 break;635 636 case '*':637 {638 while ((chPat = *++pszPat) == '*' || chPat == '?')639 /* nothing */;640 641 for (;;)642 {643 char ch = *pszName++;644 if ( ch == chPat645 && ( !chPat646 || matchesSinglePattern(pszPat + 1, pszName)))647 return true;648 if (!ch)649 return false;650 }651 /* won't ever get here */652 break;653 }654 655 case '?':656 if (!*pszName)657 return false;658 break;659 660 case '\0':661 return !*pszName;662 }663 pszName++;664 pszPat++;665 }666 return true;667 }668 669 670 /* Checks to see if the given string matches against one of the patterns in671 * the list. */672 static bool matchesPattern(const char *paszPatterns, size_t cchPatterns,673 const char *pszString)674 {675 size_t iOffs = 0;676 /* If the first pattern in the list is empty, treat it as "match all". */677 bool matched = (cchPatterns > 0) && (0 == *paszPatterns) ? true : false;678 while ((iOffs < cchPatterns) && !matched)679 {680 size_t cchCurrent;681 if ( RT_SUCCESS(RTStrNLenEx(paszPatterns + iOffs,682 cchPatterns - iOffs, &cchCurrent))683 && (cchCurrent > 0)684 )685 {686 matched = matchesSinglePattern(paszPatterns + iOffs, pszString);687 iOffs += cchCurrent + 1;688 }689 else690 iOffs = cchPatterns;691 }692 return matched;693 }694 695 696 /**697 616 * Enumerate guest properties by mask, checking the validity 698 617 * of the arguments passed. … … 730 649 if (RT_SUCCESS(rc)) 731 650 rc = VBoxHGCMParmPtrGet(&paParms[0], (void **) &paszPatterns, &cchPatterns); 651 if (RT_SUCCESS(rc) && cchPatterns > MAX_PATTERN_LEN + 1) 652 rc = VERR_TOO_MUCH_DATA; 732 653 if (RT_SUCCESS(rc)) 733 654 rc = VBoxHGCMParmPtrGet(&paParms[1], (void **) &pchBuf, &cchBuf); 734 655 735 656 /* 736 * Start by enumerating all values in the current node into a temporary buffer. 657 * First repack the patterns into the format expected by RTStrSimplePatternMatch() 658 */ 659 bool matchAll = false; 660 char pszPatterns[MAX_PATTERN_LEN + 1]; 661 if ( (NULL == paszPatterns) 662 || (cchPatterns < 2) /* An empty pattern string means match all */ 663 ) 664 matchAll = true; 665 else 666 { 667 for (unsigned i = 0; i < cchPatterns - 1; ++i) 668 if (paszPatterns[i] != '\0') 669 pszPatterns[i] = paszPatterns[i]; 670 else 671 pszPatterns[i] = '|'; 672 pszPatterns[cchPatterns - 1] = '\0'; 673 } 674 675 /* 676 * Next enumerate all values in the current node into a temporary buffer. 737 677 */ 738 678 RTMemAutoPtr<char> TmpBuf; … … 756 696 * overwrite it next iteration. */ 757 697 if ( RT_SUCCESS(rc) 758 && matchesPattern(paszPatterns, cchPatterns, &TmpBuf[iTmpBuf]) 698 && ( matchAll 699 || RTStrSimplePatternMultiMatch(pszPatterns, RTSTR_MAX, 700 &TmpBuf[iTmpBuf], RTSTR_MAX, 701 NULL) 702 ) 759 703 ) 760 704 {
Note:
See TracChangeset
for help on using the changeset viewer.