Mercurial > hg > quicktun
annotate src/run.combined.c @ 27:5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sat, 09 Apr 2011 17:36:48 +0200 |
parents | 65c01f57bdce |
children | 6f0e6b7dc088 |
rev | line source |
---|---|
0 | 1 /* Copyright 2010 Ivo Smits <Ivo@UCIS.nl>. All rights reserved. |
2 Redistribution and use in source and binary forms, with or without modification, are | |
3 permitted provided that the following conditions are met: | |
4 | |
5 1. Redistributions of source code must retain the above copyright notice, this list of | |
6 conditions and the following disclaimer. | |
7 | |
8 2. Redistributions in binary form must reproduce the above copyright notice, this list | |
9 of conditions and the following disclaimer in the documentation and/or other materials | |
10 provided with the distribution. | |
11 | |
12 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
13 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
14 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR | |
15 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
16 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
17 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
18 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
19 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
20 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
21 | |
22 The views and conclusions contained in the software and documentation are those of the | |
23 authors and should not be interpreted as representing official policies, either expressed | |
24 or implied, of Ivo Smits.*/ | |
25 | |
26 #include "common.c" | |
27 | |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
28 struct qtproto qtproto_raw; |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
29 struct qtproto qtproto_nacl0; |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
30 struct qtproto qtproto_nacltai; |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
31 |
0 | 32 #ifdef DEBIAN_BINARY |
33 char* getenvdeb(const char* name) { | |
34 char tmp[1024] = "IF_QT_"; | |
35 if (strcmp(name, "INTERFACE") == 0) return getenv("IFACE"); | |
36 if (strlen(tmp) + strlen(name) >= 1024) { | |
37 fprintf(stderr, "Error: prefixed environment variable name is too long"); | |
38 return NULL; | |
39 } | |
40 strcat(tmp, name); | |
41 return getenv(tmp); | |
42 } | |
43 #endif | |
44 | |
45 int main() { | |
46 print_header(); | |
47 #ifdef DEBIAN_BINARY | |
48 getconf = getenvdeb; | |
49 #else | |
50 getconf = getenv; | |
51 #endif | |
52 char* envval; | |
53 if (envval = getconf("PROTOCOL")) { | |
54 if (strcmp(envval, "raw") == 0) { | |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
55 return qtrun(&qtproto_raw); |
0 | 56 } else if (strcmp(envval, "nacl0") == 0) { |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
57 return qtrun(&qtproto_nacl0); |
0 | 58 } else if (strcmp(envval, "nacltai") == 0) { |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
59 return qtrun(&qtproto_nacltai); |
0 | 60 } else { |
61 fprintf(stderr, "Unknown protocol specified: %s\n", envval); | |
62 return -1; | |
63 } | |
64 } else if (getconf("PRIVATE_KEY")) { | |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
65 return qtrun(&qtproto_nacl0); |
0 | 66 } else { |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
67 return qtrun(&qtproto_raw); |
0 | 68 } |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
69 } |