2 * Copyright (C) 2008-2011 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2009 Bart Trojanowski <bart@jukie.net>
4 * Copyright (C) 2009-2010 Amir Mohammad Saied <amirsaied@gmail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
33 #include <sys/types.h>
35 #include <curl/curl.h>
36 #include <libxml/xmlmemory.h>
37 #include <libxml/parser.h>
38 #include <libxml/tree.h>
45 void bti_parse_configfile(struct session *session)
51 char *password = NULL;
52 char *consumer_key = NULL;
53 char *consumer_secret = NULL;
54 char *access_token_key = NULL;
55 char *access_token_secret = NULL;
65 config_file = fopen(session->configfile, "r");
67 /* No error if file does not exist or is unreadable. */
68 if (config_file == NULL)
72 ssize_t n = getline(&line, &len, config_file);
75 if (line[n - 1] == '\n')
77 /* Parse file. Format is the usual value pairs:
80 # is a comment character
82 *strchrnul(line, '#') = '\0';
86 /* Ignore blank lines. */
90 if (!strncasecmp(c, "account", 7) && (c[7] == '=')) {
94 } else if (!strncasecmp(c, "password", 8) &&
99 } else if (!strncasecmp(c, "consumer_key", 12) &&
103 consumer_key = strdup(c);
104 } else if (!strncasecmp(c, "consumer_secret", 15) &&
108 consumer_secret = strdup(c);
109 } else if (!strncasecmp(c, "access_token_key", 16) &&
113 access_token_key = strdup(c);
114 } else if (!strncasecmp(c, "access_token_secret", 19) &&
118 access_token_secret = strdup(c);
119 } else if (!strncasecmp(c, "host", 4) &&
124 } else if (!strncasecmp(c, "proxy", 5) &&
129 } else if (!strncasecmp(c, "logfile", 7) &&
134 } else if (!strncasecmp(c, "replyto", 7) &&
139 } else if (!strncasecmp(c, "action", 6) &&
144 } else if (!strncasecmp(c, "user", 4) &&
149 } else if (!strncasecmp(c, "shrink-urls", 11) &&
152 if (!strncasecmp(c, "true", 4) ||
153 !strncasecmp(c, "yes", 3))
155 } else if (!strncasecmp(c, "verbose", 7) &&
158 if (!strncasecmp(c, "true", 4) ||
159 !strncasecmp(c, "yes", 3))
160 session->verbose = 1;
161 } else if (!strncasecmp(c,"retweet", 7) &&
167 } while (!feof(config_file));
170 session->password = password;
172 session->account = account;
174 session->consumer_key = consumer_key;
176 session->consumer_secret = consumer_secret;
177 if (access_token_key)
178 session->access_token_key = access_token_key;
179 if (access_token_secret)
180 session->access_token_secret = access_token_secret;
182 if (strcasecmp(host, "twitter") == 0) {
183 session->host = HOST_TWITTER;
184 session->hosturl = strdup(twitter_host);
185 session->hostname = strdup(twitter_name);
186 } else if (strcasecmp(host, "identica") == 0) {
187 session->host = HOST_IDENTICA;
188 session->hosturl = strdup(identica_host);
189 session->hostname = strdup(identica_name);
191 session->host = HOST_CUSTOM;
192 session->hosturl = strdup(host);
193 session->hostname = strdup(host);
199 free(session->proxy);
200 session->proxy = proxy;
203 session->logfile = logfile;
205 session->replyto = replyto;
207 session->retweet = retweet;
209 if (strcasecmp(action, "update") == 0)
210 session->action = ACTION_UPDATE;
211 else if (strcasecmp(action, "friends") == 0)
212 session->action = ACTION_FRIENDS;
213 else if (strcasecmp(action, "user") == 0)
214 session->action = ACTION_USER;
215 else if (strcasecmp(action, "replies") == 0)
216 session->action = ACTION_REPLIES;
217 else if (strcasecmp(action, "public") == 0)
218 session->action = ACTION_PUBLIC;
219 else if (strcasecmp(action, "group") == 0)
220 session->action = ACTION_GROUP;
222 session->action = ACTION_UNKNOWN;
226 session->user = user;
227 session->shrink_urls = shrink_urls;
229 /* Free buffer and close file. */