Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.8 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1996 **
  4. //*********************************************************************
  5. #include "project.h"
  6. CSampleObtainRating::CSampleObtainRating()
  7. {
  8. m_cRef = 1;
  9. DllAddRef();
  10. }
  11. CSampleObtainRating::~CSampleObtainRating()
  12. {
  13. DllRelease();
  14. }
  15. STDMETHODIMP CSampleObtainRating::QueryInterface(REFIID riid, void **ppvObject)
  16. {
  17. if (IsEqualIID(riid, IID_IUnknown) ||
  18. IsEqualIID(riid, IID_IObtainRating)) {
  19. *ppvObject = (void *)this;
  20. AddRef();
  21. return NOERROR;
  22. }
  23. *ppvObject = NULL;
  24. return E_NOINTERFACE;
  25. }
  26. STDMETHODIMP_(ULONG) CSampleObtainRating::AddRef(void)
  27. {
  28. return ++m_cRef;
  29. }
  30. STDMETHODIMP_(ULONG) CSampleObtainRating::Release(void)
  31. {
  32. if (!--m_cRef) {
  33. delete this;
  34. return 0;
  35. }
  36. else
  37. return m_cRef;
  38. }
  39. /* The sample rating obtainer reads the rating for the site from
  40. * a .INI file (ratings.ini) which looks like this:
  41. *
  42. * [Ratings]
  43. * http://www.msn.com=l 0 s 0 n 0 v 0
  44. * http://www.playboy.com=l 3 s 4 n 4 v 0
  45. *
  46. * For this sample implementation, the URL must match exactly with
  47. * an entry in the file.
  48. */
  49. const TCHAR szRatingTemplate[] =
  50. "(PICS-1.0 \"http://www.rsac.org/ratingsv01.html\" l by \"Sample Rating Obtainer\" for \"%s\" on \"1996.04.16T08:15-0500\" exp \"1997.03.04T08:15-0500\" r (%s))";
  51. STDMETHODIMP CSampleObtainRating::ObtainRating(THIS_ LPCTSTR pszTargetUrl, HANDLE hAbortEvent,
  52. IMalloc *pAllocator, LPSTR *ppRatingOut)
  53. {
  54. TCHAR szRating[18]; /* big enough for "l 0 s 0 n 0 v 0" */
  55. UINT cchCopied;
  56. cchCopied = GetPrivateProfileString("Allow", pszTargetUrl, "", szRating, sizeof(szRating), "ratings.ini");
  57. if (cchCopied > 0) {
  58. return S_RATING_ALLOW; /* explicitly allow access */
  59. }
  60. cchCopied = GetPrivateProfileString("Deny", pszTargetUrl, "", szRating, sizeof(szRating), "ratings.ini");
  61. if (cchCopied > 0) {
  62. return S_RATING_DENY; /* explicitly deny access */
  63. }
  64. cchCopied = GetPrivateProfileString("Ratings", pszTargetUrl, "", szRating, sizeof(szRating), "ratings.ini");
  65. if (cchCopied == 0) {
  66. return E_RATING_NOT_FOUND; /* rating not found */
  67. }
  68. LPSTR pBuffer = (LPSTR)pAllocator->Alloc(sizeof(szRatingTemplate) + lstrlen(pszTargetUrl) + lstrlen(szRating));
  69. if (pBuffer == NULL)
  70. return E_OUTOFMEMORY;
  71. ::wsprintf(pBuffer, szRatingTemplate, pszTargetUrl, szRating);
  72. *ppRatingOut = pBuffer;
  73. return S_RATING_FOUND;
  74. }
  75. /* We want the sample provider to override any HTTP rating bureau
  76. * which might be installed, so we return a sort order value which
  77. * is less than the one used by that provider (0x80000000).
  78. */
  79. STDMETHODIMP_(ULONG) CSampleObtainRating::GetSortOrder(THIS)
  80. {
  81. return 0x40000000; /* before rating bureau */
  82. }