main.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "PsiphonTunnel.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. char *read_file(char *filename) {
  6. char *buffer = NULL;
  7. size_t size = 0;
  8. FILE *fp = fopen(filename, "r");
  9. if (!fp) {
  10. return NULL;
  11. }
  12. fseek(fp, 0, SEEK_END);
  13. size = ftell(fp);
  14. rewind(fp);
  15. buffer = malloc((size + 1) * sizeof(*buffer));
  16. fread(buffer, size, 1, fp);
  17. buffer[size] = '\0';
  18. return buffer;
  19. }
  20. int main(int argc, char *argv[]) {
  21. // load config
  22. char * const default_config = "psiphon_config";
  23. char * config = argv[1];
  24. if (!config) {
  25. config = default_config;
  26. printf("Using default config file: %s\n", default_config);
  27. }
  28. char *file_contents = read_file(config);
  29. if (!file_contents) {
  30. printf("Could not find config file: %s\n", config);
  31. return 1;
  32. }
  33. GoString psiphon_config = {file_contents, strlen(file_contents)};
  34. // set server list
  35. GoString serverList = {};
  36. // set timout
  37. long long timeout = 10;
  38. // set network ID
  39. char * const test_network_id = "TEST";
  40. GoString network_id = {test_network_id, strlen(test_network_id)};
  41. // start will return once Psiphon connects or does not connect for timeout seconds
  42. char *result = Start(psiphon_config, serverList, network_id, timeout);
  43. Stop();
  44. // print results
  45. printf("Result: %s\n", result);
  46. // cleanup
  47. free(result);
  48. }