Mercurial > ~darius > hgwebdir.cgi > wh1080
annotate db.c @ 4:f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 11 Feb 2010 11:47:11 +1030 |
parents | dc5ff2a1ed81 |
children | e0b32014ed14 |
rev | line source |
---|---|
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 * Report weather conditions to remote web sites. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 * Database access and startup functions. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 * |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 * Greg Lehey, 14 December 2009 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 * |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 * $Id: db.c,v 1.5 2010/02/04 03:50:35 grog Exp $ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 |
2
9da35e705144
Add includes so that it builds without warnings.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
10 #include <stdlib.h> |
9da35e705144
Add includes so that it builds without warnings.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
11 |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 #include "wh1080.h" |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 #define STAMPSIZE 32 /* size of time stamp to print out */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 /* Command line options */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 int debug; /* -d */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 int update = 1; /* -n turns updating off */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 int recover = 0; /* -r: recover missed archive data (wh1080 only) */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 int verbose; /* -v */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 int once; /* -1 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 struct passwd *mypasswd; /* password information for default user */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 /* MySQL stuff */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 MYSQL *mysql; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 MYSQL_RES *mysql_result; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 MYSQL_ROW mysql_row; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 char mysql_querytext [1024]; /* build up queries here */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 struct config config; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 void db_login () |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 if (! mysql_init (mysql)) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 fprintf (stderr, "Can't initialize MySQL\n"); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 mysql = mysql_init (mysql); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 if (! mysql) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 fprintf (stderr, "Can't initialize MySQL: insufficient memory\n"); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 if (! mysql_real_connect (mysql, /* DB state */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 config.db_host, /* database host */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 config.db_user, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 config.db_passwd, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 config.db, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 0, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 NULL, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 0 )) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 fprintf (stderr, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 "Can't connect to databaase: %s (%d)\n", |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 mysql_error (mysql), |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 mysql_errno (mysql) ); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 * Perform a database query, return result to myresult. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 int domyquery (char *query, MYSQL_RES **myresult) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 if (mysql_query (mysql, query)) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 fprintf (stderr, |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 "Can't query database: %s (%d)\n" |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 " query:%s\n", |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 mysql_error (mysql), |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 mysql_errno (mysql), |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 query ); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 return 1; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
76 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
77 *myresult = mysql_store_result (mysql); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 return 0; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
79 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 * Perform a database query, return result to implicit mysql_result. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 int doquery (char *query) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 return domyquery (query, &mysql_result); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
87 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 * Make a copy of a string in malloced memory and return it. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
91 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 char *mycopy (char *string) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
94 char *result = malloc (strlen (string) + 1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 strcpy (result, string); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 return result; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 * Read in config from database. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 * |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
102 * XXX We have a chicken and egg problem here: the config information includes |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
103 * the database name, but we need to know that before we start. For the time |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
104 * being we supply necessary information on the command line, with defaults. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 * FIXME. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
107 int read_config (int argc, char *argv []) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
108 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
109 int col; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
110 int arg; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 for (arg = 1; arg < argc; arg++) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 if (! strcmp (argv [arg], "-d")) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
115 debug = 1; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 else if (! strcmp (argv [arg], "-n")) /* turn off DB updates */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 update = 0; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 else if (! strcmp (argv [arg], "-v")) /* verbose */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 verbose = 1; |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
120 else if (! strcmp (argv [arg], "-vv")) /* more verbose */ |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
121 verbose = 2; |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
122 else if (! strcmp (argv [arg], "-1")) /* run once and exit */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
123 once = 1; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 else |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 if (! config.station_id) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 config.station_id = argv [arg]; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 else if (! config.db_user) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
129 config.db_user = argv [arg]; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 else if (! config.db_passwd) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 config.db_passwd = argv [arg]; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
132 else if (! config.db_host) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 config.db_host = argv [arg]; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 else if (! config.db) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 config.db = argv [arg]; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 else |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
137 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
138 fprintf (stderr, "Too many arguments: %s\n", argv [arg]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 return -1; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
140 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
141 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
142 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
143 |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
144 /* Set default values for config stuff above. */ |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
145 if (! config.station_id) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
146 config.station_id = "mystation"; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
147 if (! config.db_host) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
148 config.db_host = "localhost"; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
149 if (! config.db_user) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
150 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
151 /* Find out user name and use it */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
152 mypasswd = getpwuid (getuid ()); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
153 if (mypasswd) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
154 config.db_user = mycopy (mypasswd->pw_name); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
155 else |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
156 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
157 fprintf (stderr, "Can't get default user id\n"); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
158 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
159 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
160 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
161 if (! config.db_passwd) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 config.db_passwd = ""; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 if (! config.db) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
164 config.db = "weather"; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
165 |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
166 /* No updates required so don't bother with DB stuff */ |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
167 if (!update) { |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
168 config.poll_interval = 5; |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
169 return 0; |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
170 } |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
171 |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
172 if (! mysql_init (mysql)) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
173 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
174 fprintf (stderr, "Can't initialize MySQL\n"); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
175 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
176 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
177 mysql = mysql_init (mysql); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
178 if (! mysql) |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
179 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
180 fprintf (stderr, "Can't initialize MySQL: insufficient memory\n"); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
181 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
182 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
183 if (! mysql_real_connect (mysql, /* DB state */ |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
184 config.db_host, /* database host */ |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
185 config.db_user, |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
186 config.db_passwd, |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
187 config.db, |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
188 0, |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
189 NULL, |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
190 0 )) |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
191 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
192 fprintf (stderr, |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
193 "Can't connect to databaase: %s (%d)\n", |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
194 mysql_error (mysql), |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
195 mysql_errno (mysql) ); |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
196 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
197 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
198 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
199 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
200 * Read the rest of the config from specified database. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
201 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
202 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
203 sprintf (mysql_querytext, |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
204 "SELECT version,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
205 " latitude,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
206 " longitude,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
207 " elevation,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
208 " pressure_error,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
209 " poll_interval,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
210 " address,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
211 " wunderground_station_id,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
212 " wunderground_passwd,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
213 " wunderground_report_interval,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
214 " weatheforyou_station_id,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
215 " weatheforyou_passwd,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
216 " weatherforyou_report_interval,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
217 " website_generation_interval,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
218 " db_table,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
219 " php_header,\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
220 " comparefile\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
221 "FROM config\n" |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
222 "WHERE station_id = \"%s\";\n", |
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
223 config.station_id ); |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
224 if (doquery (mysql_querytext)) /* failure */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
225 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
226 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
227 if (! (mysql_row = mysql_fetch_row (mysql_result))) /* got something */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
228 { |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 fprintf (stderr, "No configuration file found\n"); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 exit (1); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
231 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
232 |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
233 /* |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
234 * XXX here we should perform a version check. Do it when we introduce |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
235 * version 2. |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
236 */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
237 /* And this is filthy ugly. Fix it */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
238 col = 1; |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
239 config.latitude = atof (mysql_row [col++]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
240 config.longitude = atof (mysql_row [col++]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
241 config.elevation = atof (mysql_row [col++]); /* metres */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
242 config.pressure_error = atof (mysql_row [col++]); /* difference between actual and real pressure, hPa */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
243 config.poll_interval = atoi (mysql_row [col++]); /* time, in seconds, between reading the device */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
244 config.address = mycopy (mysql_row [col++]); /* Address to display on web pages */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 config.wunderground_station_id = mycopy (mysql_row [col++]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
246 config.wunderground_passwd = mycopy (mysql_row [col++]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
247 config.wunderground_report_interval = atoi (mysql_row [col++]); /* how many seconds between reports to Wunderground */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
248 config.weatheforyou_station_id = mycopy (mysql_row [col++]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 config.weatheforyou_passwd = mycopy (mysql_row [col++]); |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 config.weatherforyou_report_interval = atoi (mysql_row [col++]); /* how many seconds between reports to Weather for you */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
251 config.website_generation_interval = atoi (mysql_row [col++]); /* how many seconds between generating PHP header file */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 config.db_table = mycopy (mysql_row [col++]); /* table */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
253 config.php_header = mycopy (mysql_row [col++]); /* php header file with weather data */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
254 config.comparefile = mycopy (mysql_row [col++]); /* file to compare local weather stations */ |
4
f561c7f130a0
Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
255 |
0
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
256 return 0; /* success */ |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 } |
9dab44dcb331
Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 |