Leaked source code of windows server 2003
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.

142 lines
3.0 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include "resource.h"
  5. void StartHTML(char * title, int fNoCache)
  6. {
  7. char szExpireMsg[_MAX_PATH];
  8. char szReturnMsg[_MAX_PATH];
  9. char szReturnHtmlMsg[_MAX_PATH*4];
  10. HINSTANCE hInst = GetModuleHandle(NULL);
  11. LoadString(hInst, IDS_EXPIREMSG, szExpireMsg, sizeof(szExpireMsg));
  12. LoadString(hInst, IDS_RETURNMSG, szReturnMsg, sizeof(szReturnMsg));
  13. LoadString(hInst, IDS_RETURNHTMLMSG, szReturnHtmlMsg, sizeof(szReturnHtmlMsg));
  14. if (fNoCache)
  15. printf("%s\r\n", szExpireMsg);
  16. printf( szReturnHtmlMsg, title, szReturnMsg);
  17. }
  18. void EndHTML()
  19. {
  20. char szEndHtml[_MAX_PATH];
  21. HINSTANCE hInst = GetModuleHandle(NULL);
  22. LoadString(hInst, IDS_ENDHTML, szEndHtml, sizeof(szEndHtml));
  23. printf( szEndHtml );
  24. }
  25. // translates HTTP escapes to ASCII equivalents
  26. // assumes HTTP escapes are of the form %dd, where the first digit is 0-9 and
  27. // the second is 0-F
  28. void TranslateEscapes(char * p, long l)
  29. {
  30. char * p2;
  31. int c1;
  32. int c2;
  33. for(p2=p; l; l--) {
  34. if (*p == '+' )
  35. *p = ' ';
  36. if (*p == '%' && *(p+1) != '%') {
  37. p++;
  38. c1=toupper(*p);
  39. c2=toupper(*(p+1));
  40. //*p2++ = (*p-'0')*16 + ((*(p+1))>= 'A' ? *(p+1)-'A'+10 : *(p+1)-'0');
  41. *p2++ = (c1>='A' ? c1-'A'+10 : c1-'0')*16 +
  42. (c2>='A' ? c2-'A'+10 : c2-'0');
  43. p += 2;
  44. l -= 2;
  45. }
  46. else
  47. *p2++=*p++;
  48. }
  49. }
  50. //
  51. // This is like TranslateEscapes but fixes a problem where the description
  52. // string gets broken
  53. //
  54. void
  55. TranslateEscapes2(
  56. char * p,
  57. long len
  58. )
  59. {
  60. char * p2;
  61. int c1;
  62. int c2;
  63. for(p2=p; len > 0; len--) {
  64. if (*p == '+' ) {
  65. *p = ' ';
  66. }
  67. if (*p == '%' && *(p+1) != '%') {
  68. p++;
  69. c1=toupper(*p);
  70. c2=toupper(*(p+1));
  71. //*p2++ = (*p-'0')*16 + ((*(p+1))>= 'A' ? *(p+1)-'A'+10 : *(p+1)-'0');
  72. *p2 = (c1>='A' ? c1-'A'+10 : c1-'0')*16 +
  73. (c2>='A' ? c2-'A'+10 : c2-'0');
  74. if (*p2 == '+' ) {
  75. *p2 = ' ';
  76. }
  77. ++p2;
  78. p += 2;
  79. len -= 2;
  80. } else {
  81. *p2++=*p++;
  82. }
  83. }
  84. *p2 = '\0';
  85. } // TranslateEscapes2
  86. void
  87. ConvertSP2Plus(
  88. char * String1,
  89. char * String2
  90. )
  91. {
  92. char *p = String1;
  93. char *q = String2;
  94. char ch;
  95. do {
  96. ch = *p;
  97. *q = (ch == ' ') ? '+' : ch;
  98. ++p;
  99. ++q;
  100. } while (ch != '\0');
  101. return;
  102. } // ConvertSP2Plus