parse.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <stdlib.h>
  2. char filtered_query[2000];
  3. char rdata[500];
  4. char param_n[500];
  5. char param_d[500];
  6. char *get_query(char *inquery)
  7. {
  8. memset(filtered_query, 0x0, 2000);
  9. sscanf(inquery, "GET %s %[$]", filtered_query);
  10. return(filtered_query);
  11. }
  12. void web_send(int sockin, char *in_data)
  13. {
  14. send(sockin, in_data, strlen(in_data), 0);
  15. }
  16. //THIS IS BAD CODE BE CAREFULL WITH IT!
  17. //Watch out for buffer overflow...
  18. //When using please make sure to check the string size.
  19. //Also note:
  20. //I take no pride in this code, it is a really bad way of doing this...
  21. char *get_param(char in_string[500], char swhat[500])
  22. {
  23. int i = 0;
  24. int marker, iswitch, pint, dint;
  25. char flux[500];
  26. memset(flux, 0x0, 500);
  27. //Get the path of out "page"
  28. if (swhat == 0)
  29. {
  30. //while i is not equal to array size
  31. while (i != 500)
  32. {
  33. //if there is a question mark, halt!
  34. if (in_string[i] == '?')
  35. {
  36. i = 499;
  37. }
  38. else
  39. rdata[i] = in_string[i];
  40. i++;
  41. }
  42. return rdata;
  43. }
  44. else //so, we want a param...
  45. {
  46. //calculate where param begins
  47. while (i != 500)
  48. {
  49. if (in_string[i] == '?')
  50. {
  51. marker = i + 1;
  52. i = 499;
  53. }
  54. i++;
  55. }
  56. i = 0;
  57. //keep morons from trying to crash this
  58. if ((marker > 500)||(marker < 1))
  59. marker = 500;
  60. while(marker != 500)
  61. {
  62. if ((in_string[marker] != '&') && (in_string[marker] != '\0'))
  63. {
  64. flux[i] = in_string[marker];
  65. i++;
  66. }
  67. else
  68. {
  69. //we have a param, now we must dig through it
  70. //clear temp vars
  71. memset(param_n, 0x0, 500);
  72. memset(param_d, 0x0, 500);
  73. iswitch = 0;
  74. pint = 0;
  75. dint = 0;
  76. i = 0;
  77. //split result into param_n and param_d
  78. while(i != 500)
  79. {
  80. if ( (flux[i] != '=') && (flux[i] != '\0') )
  81. {
  82. if (iswitch == 0)
  83. {
  84. param_n[pint] = flux[i];
  85. pint++;
  86. }
  87. else
  88. {
  89. param_d[dint] = flux[i];
  90. dint++;
  91. }
  92. }
  93. else
  94. {
  95. iswitch = 1;
  96. }
  97. if (flux[i] == '\0')
  98. i = 499;
  99. i++;
  100. }
  101. if ( strcmp(param_n, swhat) == 0 )
  102. {
  103. return param_d;
  104. }
  105. i = 0;
  106. }
  107. if (in_string[marker] == '\0')
  108. {
  109. marker = 499;
  110. }
  111. marker++;
  112. }
  113. return 0;
  114. }
  115. }