getparam.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef GETPARAM_H
  2. #define GETPARAM_H
  3. #pragma once
  4. #include "config.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /*
  9. * protocol msg parsing utility
  10. * each call parse a line
  11. * line = <fullname>:<whitespace+><value>\r\n
  12. * the msg ends with \r\n\r\n
  13. */
  14. #define PROTOPARSE_IGNOREWHITESPACE 1
  15. #define PROTOPARSE_CASESENSITIVE 2
  16. struct proto_param
  17. {
  18. const char *fname; /* fullname */
  19. int mode; /* see PROTOPARSE_xxx */
  20. int sname; /* short name */
  21. };
  22. /**
  23. * parsing funtion
  24. * @param buf original protocol msg buffer, must be ends with CRLFCRLF
  25. * @param params pointers to proto_param array, end element must be fill with zero members
  26. * @param pval pointer to value
  27. * @param plen pval length
  28. * @param ctx context store current parsing position in the buf,
  29. * init value is null, user don't access
  30. * @return -1 indicate finished
  31. */
  32. TOOLKIT_API int getparam(const char *buf,
  33. const struct proto_param *params,
  34. const char **pval,
  35. int *plen,
  36. const char **ctx);
  37. #ifdef __cplusplus
  38. } // extern "C" {
  39. #endif
  40. #endif // GETPARAM_H