A tool for adding anime to your anidb list.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.3KB

  1. #ifndef _API_H
  2. #define _API_H
  3. #include <stdint.h>
  4. #include <time.h>
  5. #include "error.h"
  6. #define API_VERSION "3"
  7. /* Maximum length of one response/request */
  8. #define API_BUFSIZE 1400
  9. /* Session key maximum size, including '\0' */
  10. #define API_SMAXSIZE 16
  11. /* Encryption salt maximum size, including '\0' */
  12. #define API_SALTMAXSIZE 16
  13. /* The session timeout in miliseconds */
  14. #define API_TIMEOUT 30 * 60 * 1000
  15. /* How many miliseconds to wait between sends */
  16. #define API_SENDWAIT 2 * 1000
  17. /* The number of packets that are exccempt from the ratelimit */
  18. #define API_FREESEND 5
  19. /* Long term wait between sends */
  20. #define API_SENDWAIT_LONG 4 * 1000
  21. /* After this many packets has been sent, use the longterm ratelimit */
  22. #define API_LONGTERM_PACKETS 100
  23. enum mylist_state {
  24. MYLIST_STATE_UNKNOWN = 0,
  25. MYLIST_STATE_INTERNAL,
  26. MYLIST_STATE_EXTERNAL,
  27. MYLIST_STATE_DELETED,
  28. MYLIST_STATE_REMOTE,
  29. };
  30. enum file_state {
  31. FILE_STATE_NORMAL = 0,
  32. FILE_STATE_CORRUPT,
  33. FILE_STATE_SELF_EDIT,
  34. FILE_STATE_SELF_RIP = 10,
  35. FILE_STATE_ON_DVD,
  36. FILE_STATE_ON_VHS,
  37. FILE_STATE_ON_TV,
  38. FILE_STATE_IN_THEATERS,
  39. FILE_STATE_STREAMED,
  40. FILE_STATE_OTHER = 100,
  41. };
  42. struct api_version_result {
  43. char version_str[40];
  44. };
  45. struct api_auth_result {
  46. union {
  47. char session_key[API_SMAXSIZE];
  48. /* free() */
  49. char *banned_reason;
  50. };
  51. };
  52. struct api_encrypt_result {
  53. char salt[API_SALTMAXSIZE];
  54. };
  55. struct api_uptime_result {
  56. int32_t ms;
  57. };
  58. struct api_mylistadd_result {
  59. union {
  60. uint64_t new_id;
  61. struct {
  62. uint64_t lid, fid, eid, aid, gid, date, viewdate;
  63. /* free() if != NULL ofc */
  64. char *storage, *source, *other;
  65. enum mylist_state state;
  66. enum file_state filestate;
  67. };
  68. };
  69. };
  70. #define e(n) struct api_##n##_result n
  71. struct api_result {
  72. uint16_t code;
  73. union {
  74. struct api_version_result version;
  75. struct api_auth_result auth;
  76. struct api_uptime_result uptime;
  77. e(mylistadd);
  78. e(encrypt);
  79. };
  80. };
  81. #undef e
  82. enum error api_init(bool auth);
  83. void api_free();
  84. enum error api_cmd_version(struct api_result *res);
  85. enum error api_cmd_uptime(struct api_result *res);
  86. enum error api_cmd_mylistadd(int64_t size, const uint8_t *hash,
  87. enum mylist_state fstate, bool watched, struct api_result *res);
  88. #endif /* _API_H */