shared_utils.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_
  17. #define DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_
  18. #include "native_interface.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define FMT_ATTR_CONTAINER 99
  23. #define FMT_APP_RAW_BINARY 98
  24. typedef struct request {
  25. // message id
  26. uint32 mid;
  27. // url of the request
  28. char *url;
  29. // action of the request, can be PUT/GET/POST/DELETE
  30. int action;
  31. // payload format, currently only support attr_container_t type
  32. int fmt;
  33. // payload of the request, currently only support attr_container_t type
  34. void *payload;
  35. int payload_len;
  36. unsigned long sender;
  37. } request_t;
  38. typedef struct response {
  39. // message id
  40. uint32 mid;
  41. // status of the response
  42. int status;
  43. // payload format
  44. int fmt;
  45. // payload of the response,
  46. void *payload;
  47. int payload_len;
  48. unsigned long reciever;
  49. } response_t;
  50. int check_url_start(const char* url, int url_len, const char * leading_str);
  51. bool match_url(char * pattern, char * matched);
  52. char * find_key_value(char * buffer, int buffer_len, char * key, char * value,
  53. int value_len, char delimiter);
  54. request_t *clone_request(request_t *request);
  55. void request_cleaner(request_t *request);
  56. response_t * clone_response(response_t * response);
  57. void response_cleaner(response_t * response);
  58. response_t * set_response(response_t * response, int status, int fmt,
  59. const char *payload, int payload_len);
  60. response_t * make_response_for_request(request_t * request,
  61. response_t * response);
  62. request_t * init_request(request_t * request, char *url, int action, int fmt,
  63. void *payload, int payload_len);
  64. char * pack_request(request_t *request, int * size);
  65. request_t * unpack_request(char * packet, int size, request_t * request);
  66. char * pack_response(response_t *response, int * size);
  67. response_t * unpack_response(char * packet, int size, response_t * response);
  68. void free_req_resp_packet(char * packet);
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif /* DEPS_SSG_MICRO_RUNTIME_WASM_POC_APP_LIBS_NATIVE_INTERFACE_SHARED_UTILS_H_ */