Clean out meego/tizen specific things and quiet compile warnings
[platform/upstream/corewatcher.git] / src / configfile.c
1 #define _GNU_SOURCE
2 /*
3  * Copyright 2007, Intel Corporation
4  *
5  * This file is part of corewatcher.org
6  *
7  * This program file is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program in a file named COPYING; if not, write to the
18  * Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301 USA
21  *
22  * Authors:
23  *      Arjan van de Ven <arjan@linux.intel.com>
24  *      William Douglas <william.douglas@intel.com>
25  */
26
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <glib.h>
32
33 #include "corewatcher.h"
34
35 char *submit_url[MAX_URLS];
36 char *build_release = NULL;
37 char *core_folder = NULL;
38 int url_count = 0;
39 int do_unlink = 0;
40
41 void read_config_file(char *filename)
42 {
43         FILE *file = NULL;
44         char *line = NULL, *line_len = NULL;
45         size_t dummy = 0;
46
47         file = fopen(filename, "r");
48         if (!file)
49                 return;
50         while (!feof(file)) {
51                 char *c = NULL;
52                 char *n = NULL;
53
54                 if (getline(&line, &dummy, file) == -1)
55                         break;
56
57                 if (line[0] == '#')
58                         continue;
59
60                 /* we don't care about any lines that are too short to have config options */
61                 if (dummy < 5)
62                         continue;
63
64                 /* remove trailing\n */
65                 n = strchr(line, '\n');
66                 if (n) *n = 0;
67
68                 line_len = line + dummy;
69                 c = strstr(line, "unlink");
70                 if (c)
71                         if (strstr(c, "yes"))
72                                 do_unlink = 1;
73
74                 c = strstr(line, "submit-url");
75                 if (c && url_count <= MAX_URLS) {
76                         c += 11;
77                         if (c < line_len) {
78                                 c = strstr(c, "http:");
79                                 if (c) {
80                                         submit_url[url_count] = strdup(c);
81                                         if (!submit_url[url_count])
82                                                 submit_url[url_count] = NULL;
83                                         else
84                                                 url_count++;
85                                 }
86                         }
87                 }
88                 c = strstr(line, "release-info");
89                 if (c) {
90                         c += 11;
91                         if (c < line_len) {
92                                 c = strstr(c, "/");
93                                 if (c)
94                                         build_release = strdup(c);
95                         }
96                 }
97                 c = strstr(line, "core-folder");
98                 if (c) {
99                         c += 11;
100                         if (c < line_len) {
101                                 c = strstr(c, "/");
102                                 if (c)
103                                         core_folder = strdup(c);
104                         }
105                 }
106         }
107
108         fclose(file);
109         free(line);
110
111         if (!build_release)
112                 build_release = strdup("/etc/meego-release");
113         if (!url_count) {
114                 submit_url[url_count] = strdup("http://crashdb.meego.com/submitbug.php");
115                 if (!submit_url[url_count])
116                         submit_url[url_count] = NULL;
117                 else
118                         url_count++;
119         }
120         if (!core_folder)
121                 core_folder = strdup("/tmp/corewatcher/");
122 }