1 /* Copyright 2013,2014 Akira Ohta (akohta001@gmail.com)
2 This file is part of ntch.
4 The ntch is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 The ntch is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with ntch. If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/types.h>
32 #include "utils/nt_std_t.h"
33 #include "utils/file.h"
34 #include "utils/text.h"
38 char USR_COOKIE_PATH[1024];
39 char USR_LOG_DB_PATH[1024];
40 char USR_FAVORITE_BOARD_FILE_PATH[1024];
41 char USR_FAVORITE_GRP_FILE_PATH[1024];
42 char USR_FAVORITE_THREAD_FILE_PATH[1024];
43 char USR_NG_WORD_FILE_PATH[1024];
44 char USR_NG_NAME_FILE_PATH[1024];
45 char USR_NG_ID_FILE_PATH[1024];
46 char EDITOR_CMD[1024];
47 int FORCE_REFRESH = 0;
48 int THREAD_SORT_TYPE = NT_THREAD_SORT_BY_READ;
49 int INIT_DISP_STATE = NT_INTI_DISP_BOARDMENU;
50 int NT_MAINLOOP_POLLING_INTERVAL;
51 int NT_PTHREAD_POOL_SIZE;
52 int NT_PTHREAD_POOL_QUEUE_SIZE;
53 int NT_AUTO_SCROLL_INTERVAL;
54 int NT_AUTO_UPDATE_INTERVAL;
58 int RFC2898_ITERATION;
64 char CA_FILE_PATH[1024];
66 static char *app_name = PACKAGE_NAME;
67 static char *version_name = PACKAGE_VERSION;
68 static char *def_editor_cmd = "vi";
73 struct option longopts[] = {
74 {"refresh-screen", 0, NULL, 'r'},
75 {"version", 0, NULL, 'v'},
76 {"help", 0, NULL, 'h'},
77 {"editor", 1, NULL, 'e'},
78 {"out-path", 1, NULL, 'o'},
79 {"pem", 1, NULL, 'p'},
80 {"server", 2, NULL, 's'},
84 extern void print_help();
85 extern BOOL read_resource(const char *path);
89 if(MARU_ID != NULL) free(MARU_ID);
90 if(MARU_PW != NULL) free(MARU_PW);
91 if(RFC2898_SALT != NULL) free(RFC2898_SALT);
92 if(AES256_PASS != NULL) free(AES256_PASS);
93 if(NCE_AUTH_URL != NULL) free(NCE_AUTH_URL);
94 if(NCE_ID != NULL) free(NCE_ID);
95 if(NCE_PASS != NULL) free(NCE_PASS);
98 int set_option(int argc, char* argv[])
105 APP_MODE = NT_APP_MODE_CLIENT;
110 RFC2898_ITERATION = 0;
115 CA_FILE_PATH[0] = '\0';
117 NT_MAINLOOP_POLLING_INTERVAL = 100;
118 NT_PTHREAD_POOL_SIZE = 5;
119 NT_PTHREAD_POOL_QUEUE_SIZE = 20;
121 NT_AUTO_SCROLL_INTERVAL = 500;
122 NT_AUTO_UPDATE_INTERVAL = 60000;
127 perror("Could not find user info.(home dir)\n");
130 sprintf(USR_PATH, "%s/.ntch", pw->pw_dir);
131 sprintf(USR_COOKIE_PATH, "%s/cookie", USR_PATH);
132 sprintf(USR_LOG_DB_PATH, "%s/usr_log.sqlite3", USR_PATH);
133 sprintf(USR_FAVORITE_BOARD_FILE_PATH, "%s/fb.txt", USR_PATH);
134 sprintf(USR_FAVORITE_GRP_FILE_PATH, "%s/ftab.txt", USR_PATH);
135 sprintf(USR_FAVORITE_THREAD_FILE_PATH, "%s/ft.txt", USR_PATH);
136 sprintf(USR_NG_WORD_FILE_PATH, "%s/ngwd.txt", USR_PATH);
137 sprintf(USR_NG_NAME_FILE_PATH, "%s/ngnm.txt", USR_PATH);
138 sprintf(USR_NG_ID_FILE_PATH, "%s/ngid.txt", USR_PATH);
140 sprintf(buf, "%s/.ntchrc", pw->pw_dir);
141 if(!read_resource(buf)){
143 "Could not read user's resource file. \n\tuse default.\n",
147 strcpy(LOG_PATH, "./log");
148 strcpy(EDITOR_CMD, def_editor_cmd);
150 if(!nt_mkdir(USR_PATH)){
154 while((opt = getopt_long(
155 argc, argv, "hvro:p:s::", longopts, NULL)) != -1){
159 printf("screen refresh: on\n");
163 printf("%s (NTCH) 2channel browser version - %s\n",
164 app_name , version_name);
170 printf("output path: %s\n", optarg);
171 len = strlen(optarg);
172 if(len == 0 || len > sizeof(LOG_PATH)-5)
174 strcpy(LOG_PATH, optarg);
175 if(LOG_PATH[len-1] != '/'){
176 LOG_PATH[len++] = '/';
178 strcpy(LOG_PATH+len, "log");
181 printf("ca file path: %s\n", optarg);
182 len = strlen(optarg);
183 if(len == 0 || len > sizeof(CA_FILE_PATH)-1)
185 strcpy(CA_FILE_PATH, optarg);
188 APP_MODE = NT_APP_MODE_SERVER;
195 if(CA_FILE_PATH[0] == '\0'){
196 strcpy(CA_FILE_PATH, "cacert.pem");
198 /*for(; optind < argc; optind++){
199 fprintf(stderr, "Unrecognized argument %s\n",
206 extern BOOL read_resource(const char *path)
209 char *cptr, *key, *val;
210 char *sort_type, *init_disp;
214 fp = fopen(path, "r");
218 while(fgets(buf, sizeof(buf), fp)){
221 cptr = strchr(buf, '=');
226 key = strstr(buf, "maru-id");
229 MARU_ID = nt_trim(val);
232 key = strstr(buf, "maru-pw");
235 MARU_PW = nt_trim(val);
238 key = strstr(buf, "sort");
241 sort_type = nt_trim(val);
244 if(0 == strcmp(sort_type, "number")){
245 THREAD_SORT_TYPE = NT_THREAD_SORT_BY_NUMBER;
246 }else if(0 == strcmp(sort_type, "read")){
247 THREAD_SORT_TYPE = NT_THREAD_SORT_BY_READ;
248 }else if(0 == strcmp(sort_type, "unread")){
249 THREAD_SORT_TYPE = NT_THREAD_SORT_BY_UNREAD;
254 key = strstr(buf, "show");
257 init_disp = nt_trim(val);
260 if(0 == strcmp(init_disp, "favorite")){
261 INIT_DISP_STATE = NT_INTI_DISP_FAVORITE;
262 }else if(0 == strcmp(init_disp, "history")){
263 INIT_DISP_STATE = NT_INTI_DISP_HISTORY;
268 key = strstr(buf, "auto-scroll-interval");
271 li = strtol(val, NULL, 10);
272 if(li > 0 && li < LONG_MAX )
273 NT_AUTO_SCROLL_INTERVAL = li;
276 key = strstr(buf, "auto-update-interval");
279 li = strtol(val, NULL, 10);
280 if(li > 0 && li < LONG_MAX )
281 NT_AUTO_UPDATE_INTERVAL = li;
284 key = strstr(buf, "rfc2898-salt");
287 RFC2898_SALT = nt_trim(val);
290 key = strstr(buf, "rfc2898-iteration");
293 li = strtol(val, NULL, 10);
294 if(li > 0 && li < LONG_MAX )
295 RFC2898_ITERATION = li;
298 key = strstr(buf, "aes256-pass");
301 AES256_PASS = nt_trim(val);
304 key = strstr(buf, "nce-auth-url");
307 NCE_AUTH_URL = nt_trim(val);
310 key = strstr(buf, "nce-id");
313 NCE_ID = nt_trim(val);
316 key = strstr(buf, "nce-pass");
319 NCE_PASS = nt_trim(val);