query.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <httpd.h>
  12. /*
  13. * parse a search string of the form
  14. * tag=val&tag1=val1...
  15. */
  16. HSPairs*
  17. hparsequery(HConnect *c, char *search)
  18. {
  19. HSPairs *q;
  20. char *tag, *val, *s;
  21. while((s = strchr(search, '?')) != nil)
  22. search = s + 1;
  23. s = search;
  24. while((s = strchr(s, '+')) != nil)
  25. *s++ = ' ';
  26. q = nil;
  27. while(*search){
  28. tag = search;
  29. while(*search != '='){
  30. if(*search == '\0')
  31. return q;
  32. search++;
  33. }
  34. *search++ = 0;
  35. val = search;
  36. while(*search != '&'){
  37. if(*search == '\0')
  38. return hmkspairs(c, hurlunesc(c, tag), hurlunesc(c, val), q);
  39. search++;
  40. }
  41. *search++ = '\0';
  42. q = hmkspairs(c, hurlunesc(c, tag), hurlunesc(c, val), q);
  43. }
  44. return q;
  45. }