annotate db.c @ 0:9dab44dcb331

Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
author Daniel O'Connor <darius@dons.net.au>
date Tue, 09 Feb 2010 13:44:25 +1030
parents
children 9da35e705144
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
10 #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
11
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 #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
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 /* 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
15 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
16 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
17 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
18 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
19 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
20
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 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
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 /* 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
24 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
25 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
26 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
27 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
28 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
29
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 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
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 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
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 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
35 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
36 }
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 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
38 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
39 {
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 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
41 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
42 }
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 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
44 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
45 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
46 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
47 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
48 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
49 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
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 {
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 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
53 "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
54 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
55 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
56 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
57 }
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 }
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 * 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
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 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
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 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
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 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
68 "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
69 " 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
70 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
71 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
72 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
73 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
74 }
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 *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
76 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
77 }
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
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 * 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
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 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
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 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
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
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 * 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
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 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
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 *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
93 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
94 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
95 }
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
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 * 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
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 * 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
101 * 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
102 * 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
103 * 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
104 */
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 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
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 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
108 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
109
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 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
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 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
113 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
114 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
115 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
116 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
117 verbose = 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
118 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
119 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
120 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
121 {
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 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 {
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 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
135 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
136 }
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 }
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
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 /* Set default values for config stuff above. */
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 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
142 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
143 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
144 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
145 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
146 {
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 /* 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
148 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
149 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
150 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
151 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
152 {
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 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
154 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
155 }
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 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
158 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
159 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
160 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
161
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 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
163 {
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 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
165 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
166 }
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
167 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
168 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
169 {
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
170 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
171 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
172 }
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 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 {
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 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
183 "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
184 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
185 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
186 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
187 }
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
188
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
189 /*
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
190 * 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
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
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
193 sprintf (mysql_querytext,
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
194 "SELECT version,\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
195 " latitude,\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
196 " longitude,\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
197 " elevation,\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
198 " pressure_error,\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
199 " poll_interval,\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
200 " address,\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
201 " wunderground_station_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
202 " wunderground_passwd,\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
203 " wunderground_report_interval,\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
204 " weatheforyou_station_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
205 " weatheforyou_passwd,\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
206 " weatherforyou_report_interval,\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
207 " website_generation_interval,\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
208 " db_table,\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
209 " php_header,\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
210 " comparefile\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
211 "FROM config\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
212 "WHERE station_id = \"%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
213 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
214 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
215 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
216
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
217 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
218 {
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
219 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
220 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
221 }
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
222
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
223 /*
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 * 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
225 * 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
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 /* 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
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243 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
244 config.comparefile = mycopy (mysql_row [col++]); /* file to compare local weather stations */
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 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
246 }
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