Discord library in plain C
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.

discord.c 908B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Created by Memer on 24.08.18.
  3. //
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <discord.h>
  7. #include <log.h>
  8. struct ld_context *ld_create_context(struct ld_context_info *info)
  9. {
  10. struct ld_context *ctx;
  11. // Initializing context
  12. ctx = malloc(sizeof(struct ld_context));
  13. // Initializing CURL handle
  14. if ((ctx->curl_handle = curl_easy_init()) == NULL)
  15. {
  16. log_fatal("Failed to initialize curl handle");
  17. return NULL;
  18. }
  19. if (!info->bot_token)
  20. {
  21. log_fatal("info->bot_token = NULL");
  22. return NULL;
  23. }
  24. ctx->bot_token = malloc(strlen(info->bot_token) + 1);
  25. strcpy(ctx->bot_token, info->bot_token);
  26. log_trace("ctx->bot_token = %s", ctx->bot_token);
  27. log_set_level(info->log_level);
  28. ctx->hello_triggered = false;
  29. ctx->heartbeat_interval = 0;
  30. ctx->heartbeat_acks = 0;
  31. ctx->sequence = 0;
  32. return ctx;
  33. }