Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <curl/curl.h>
  5.  
  6. #define API_DEV_KEY "85775ec7499f74ab87344ca7ba61c95a"
  7.  
  8. int main() {
  9. int buffer_size = 16;
  10. char *data = (char*) malloc(buffer_size);
  11. int string_size = 0;
  12. for(char c; c != EOF; c = getchar()) {
  13. data[string_size] = c;
  14. if (string_size == buffer_size - 1) {
  15. buffer_size += buffer_size;
  16. data = (char*) realloc(data, buffer_size);
  17. if (data == 0) {
  18. fprintf(stderr, "\033[1m\033[31merror:\033[0m Out of memory\n");
  19. return 1;
  20. }
  21. }
  22. string_size++;
  23. }
  24.  
  25. CURL *curl = curl_easy_init();
  26. if (curl) {
  27. char *url_encoded_data = curl_easy_escape(curl, data, string_size);
  28. char *post_data = (char*) malloc(77 + strlen(url_encoded_data));
  29. sprintf(post_data, "api_dev_key=" API_DEV_KEY "&api_option=paste&api_paste_code=%s", url_encoded_data);
  30.  
  31. curl_easy_setopt(curl, CURLOPT_URL, "https://pastebin.com/api/api_post.php");
  32. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data);
  33.  
  34. // printf("%s\n", post_data);
  35. CURLcode res = curl_easy_perform(curl);
  36. if (res != CURLE_OK) {
  37. fprintf(stderr, "\033[1m\033[31merror:\033[0m Request to Pastebin's servers failed. %s\n", curl_easy_strerror(res));
  38. }
  39.  
  40. curl_easy_cleanup(curl);
  41. }
  42. curl_global_cleanup();
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement