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.

135 lines
4.3 KiB

  1. // PPUrl.h: interface for the CPPUrl class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_PPURL_H__7AF434BC_E9A3_4288_9B3F_F7BA9FD68B4E__INCLUDED_)
  5. #define AFX_PPURL_H__7AF434BC_E9A3_4288_9B3F_F7BA9FD68B4E__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. class CPPQueryString: protected CStringA
  10. {
  11. public:
  12. CPPQueryString()
  13. {
  14. Preallocate(ATL_URL_MAX_URL_LENGTH);
  15. m_psz=NULL;
  16. m_pszBegin=NULL;
  17. m_bLockedCString = false;
  18. };
  19. virtual ~CPPQueryString() { Uninit(true); };
  20. void AddQueryParam(LPCSTR pszParamName, LPCSTR pszParamValue, bool fEncoding=false);
  21. void AddQueryParam(LPCSTR pszParamName, LPCWSTR pwszParamValue, bool bTrueUnicode, bool fEncoding=false);
  22. void Set(LPCSTR lpsz);
  23. void Set(LPCWSTR lpwsz);
  24. bool StripQueryParam(LPCSTR pszParamName);
  25. operator CStringA * () { Uninit(false); return (CStringA *) this; }
  26. operator LPCSTR () { return m_pszBegin; }
  27. inline bool IsEmpty()
  28. {
  29. return (m_psz - m_pszBegin) > 0 ? false : true;
  30. }
  31. protected:
  32. //char m_szUrl[ATL_URL_MAX_URL_LENGTH];
  33. char *m_psz;
  34. char *m_pszBegin;
  35. void DoParamAdd(LPCSTR pszParamValue, bool fEncoding);
  36. void DoParamAdd(LPCWSTR pwszParamValue, bool fEncoding);
  37. void Reinit();
  38. void Uninit(bool bUnlock);
  39. char *LockData()
  40. {
  41. if (m_bLockedCString)
  42. {
  43. UnlockBuffer(); // balanced the last LockBuffer;
  44. return LockBuffer();
  45. }
  46. m_bLockedCString = true;
  47. return LockBuffer();
  48. };
  49. void UnlockData()
  50. {
  51. if (m_bLockedCString)
  52. {
  53. m_bLockedCString = false;
  54. UnlockBuffer(); // balanced the last LockBuffer;
  55. }
  56. }
  57. bool m_bLockedCString;
  58. private:
  59. CPPQueryString & operator= (const CPPQueryString cp) { return *this; };
  60. };
  61. class CPPUrl : protected CPPQueryString
  62. {
  63. public:
  64. CPPUrl(CPPUrl &cp) { Set((LPCSTR)cp); } ; // prevent copy operations, as in = assignment.
  65. CPPUrl(LPCSTR pszUrl=NULL);
  66. virtual ~CPPUrl() {};
  67. static BOOL GetQParamQuick(LPCSTR qsStart, LPCSTR name, UINT nameStrLen, LPCSTR& qpStart, LPCSTR& qpEnd);
  68. inline BOOL GetQParamQuick(LPCSTR name, UINT nameStrLen, LPCSTR& qpStart, LPCSTR& qpEnd) const
  69. {
  70. return GetQParamQuick(GetQString(), name, nameStrLen, qpStart, qpEnd);
  71. };
  72. static BOOL GetQParamQuick(LPCSTR qsStart, LPCSTR name, UINT nameStrLen, INT& value);
  73. inline BOOL GetQParamQuick(LPCSTR name, UINT nameStrLen, INT& value) const
  74. {
  75. return GetQParamQuick(GetQString(), name, nameStrLen, value);
  76. };
  77. LPCSTR GetQString() const { return m_pszQuestion ? m_pszQuestion + 1 : NULL;};
  78. ULONG GetLength()
  79. {
  80. Reinit();
  81. return (ULONG)(m_psz - m_pszBegin);
  82. };
  83. void Set(LPCSTR lpsz);
  84. void Set(LPCWSTR lpwsz);
  85. void AddQueryParam(LPCSTR pszParamName, long lValue);
  86. void AddQueryParam(LPCSTR pszParamName, LPCSTR pszParamValue, bool fEncoding=false);
  87. void AddQueryParam(LPCSTR pszParamName, LPCWSTR pwszParamValue, bool bTrueUnicode, bool fEncoding=false);
  88. void ReplaceQueryParam(LPCSTR pszParamName, LPCSTR pszParamValue);
  89. inline bool StripQueryParam(LPCSTR pszParamName)
  90. {
  91. return CPPQueryString::StripQueryParam(pszParamName);
  92. }
  93. void InsertBQueryString(LPCSTR pszQueryString);
  94. void AppendQueryString(LPCSTR pszQueryString);
  95. void MakeSecure();
  96. void MakeNonSecure();
  97. operator CStringA * () { Uninit(false); return ((CStringA *) this); }
  98. operator LPCSTR () { Reinit(); return m_pszBegin; }
  99. bool IsSecure()
  100. {
  101. return (0 == _strnicmp((LPCSTR) *this, "https:", 6));
  102. }
  103. inline bool IsEmpty()
  104. {
  105. return CPPQueryString::IsEmpty();
  106. }
  107. inline BOOL UrlEncode(LPSTR szBuf, PULONG pulBufLen)
  108. {
  109. return AtlEscapeUrlA((LPCSTR) *this,
  110. szBuf,
  111. pulBufLen,
  112. *pulBufLen,
  113. ATL_URL_ESCAPE);
  114. }
  115. void MakeFullUrl(LPCSTR pszUrlPath, bool bSecure);
  116. void ReplacePath(LPCSTR pszUrlPath);
  117. CPPUrl & operator += (LPCSTR pcszAppend);
  118. private:
  119. CPPUrl & operator= (const CPPUrl cp) { return *this; };
  120. char *m_pszQuestion;
  121. void Reinit();
  122. };
  123. #endif // !defined(AFX_PPURL_H__7AF434BC_E9A3_4288_9B3F_F7BA9FD68B4E__INCLUDED_)