logout.c 984 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <json-c/json.h>
  4. #include <json-c/json_util.h>
  5. #include <json-c/json_object.h>
  6. #include <mosquitto.h>
  7. #include "common.h"
  8. #include "command.h"
  9. int main(int argc, char *argv[])
  10. {
  11. struct json_object *proot=NULL, *resp_obj = NULL;
  12. const char *resp_string=NULL;
  13. #if ENABLE_HTTP_COOKIE
  14. if (auth_user() ==false)
  15. return 0;
  16. #endif
  17. proot = json_object_from_file("./cookie/cookied.json");
  18. if(proot == NULL)
  19. {
  20. printf("Location:/index.html\n\n");
  21. }
  22. json_object_object_add(proot,"cookied", json_object_new_string(""));
  23. json_object_to_file_ext("./cookie/cookied.json", proot,JSON_C_TO_STRING_PRETTY);
  24. json_object_put(proot);
  25. printf("%s\n\n","Content-Type:application/json;charset=UTF-8");
  26. resp_obj = json_object_new_object();
  27. json_object_object_add(resp_obj, "state", json_object_new_string("success"));
  28. resp_string = json_object_to_json_string(resp_obj);
  29. printf("%s",resp_string);
  30. json_object_put(resp_obj);
  31. return 0;
  32. }