Advertisement
Guest User

Untitled

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