| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#include <iostream> |
|---|
| 20 |
#include <unistd.h> |
|---|
| 21 |
#include <string> |
|---|
| 22 |
|
|---|
| 23 |
#include <FL/Fl_Preferences.H> |
|---|
| 24 |
|
|---|
| 25 |
#include "load_canal.hh" |
|---|
| 26 |
#include "load_sister.hh" |
|---|
| 27 |
|
|---|
| 28 |
int main(int argc, char * argv[]) |
|---|
| 29 |
{ |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
int ch; |
|---|
| 33 |
char * server = "woodward.caltech.edu"; |
|---|
| 34 |
int port = 80; |
|---|
| 35 |
char * location = "/canal/services/canal_svc/"; |
|---|
| 36 |
char * username = "admin"; |
|---|
| 37 |
char * password = "admin"; |
|---|
| 38 |
bool password_was_set = false; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
while(1) { |
|---|
| 45 |
ch = getopt(argc, argv, "?hs:i:u:p:"); |
|---|
| 46 |
|
|---|
| 47 |
if (ch == -1) { |
|---|
| 48 |
break; |
|---|
| 49 |
} |
|---|
| 50 |
switch(ch) { |
|---|
| 51 |
case 's': |
|---|
| 52 |
server = optarg; |
|---|
| 53 |
break; |
|---|
| 54 |
case 'i': |
|---|
| 55 |
port = atoi(optarg); |
|---|
| 56 |
break; |
|---|
| 57 |
case 'u': |
|---|
| 58 |
username = optarg; |
|---|
| 59 |
break; |
|---|
| 60 |
case 'p': |
|---|
| 61 |
password = optarg; |
|---|
| 62 |
password_was_set = true; |
|---|
| 63 |
break; |
|---|
| 64 |
case '?': |
|---|
| 65 |
case 'h': |
|---|
| 66 |
default: |
|---|
| 67 |
printf("\nUsage:\n\t%s [ -s server ] [ -i port ] [ -u user ] [ -p password ]\n\n", argv[0]); |
|---|
| 68 |
exit(-1); |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
Fl_Preferences p(Fl_Preferences::USER, "family.caltech.edu", "FRII"); |
|---|
| 78 |
|
|---|
| 79 |
char path[500], * value = NULL; |
|---|
| 80 |
sprintf(path, "%s@%s,%d", username, server, port); |
|---|
| 81 |
|
|---|
| 82 |
if (password_was_set) { |
|---|
| 83 |
p.set(path, password); |
|---|
| 84 |
p.flush(); |
|---|
| 85 |
} else { |
|---|
| 86 |
printf("(Using stored or default password for user '%s'.)\n", username); |
|---|
| 87 |
} |
|---|
| 88 |
p.get(path, value, password); |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
sister::init(); |
|---|
| 95 |
canal::init(); |
|---|
| 96 |
init_chooser(); |
|---|
| 97 |
|
|---|
| 98 |
printf("Connecting to remote Cartwheel server\n\n"); |
|---|
| 99 |
printf("\thttp://%s:%d%s\n\n", server, port, location); |
|---|
| 100 |
printf("as user '%s'...\n\n", username); |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
try { |
|---|
| 104 |
canal::xmlrpcAPI * api = new canal::xmlrpcAPI(server, port, location); |
|---|
| 105 |
|
|---|
| 106 |
api->authenticate(username, value); |
|---|
| 107 |
|
|---|
| 108 |
if (api->is_authenticated()) { |
|---|
| 109 |
printf("Successful! Starting chooser.\n"); |
|---|
| 110 |
} else { |
|---|
| 111 |
printf("ERROR! Cannot log in with given username; exiting.\n"); |
|---|
| 112 |
exit(-1); |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
canal_chooser(api); |
|---|
| 117 |
|
|---|
| 118 |
} catch (canal::exception& e) { |
|---|
| 119 |
std::cerr << "canal API error: " << e.msg << std::endl; |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
free(value); |
|---|
| 123 |
|
|---|
| 124 |
exit(0); |
|---|
| 125 |
} |
|---|