OSDN Git Service

fix web_charset handling (ticket: #18509)
[keitairc/keitairc.git] / lib / Keitairc / Config.pm
1 # -*- mode: perl; coding: utf-8 -*-
2 # Keitairc::Config
3 # $Id: Config.pm,v 1.34 2009-09-24 14:48:21 ishikawa Exp $
4 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/Keitairc/Config.pm,v $
5 #
6 # Copyright (c) 2008 Jun Morimoto <morimoto@mrmt.net>
7 # This program is covered by the GNU General Public License 2
8
9 package Keitairc::Config;
10 use AppConfig qw(:argcount);
11 use Cwd;
12 use Encode::MIME::Name;
13 use strict;
14 use warnings;
15 our @ISA = qw(AppConfig);
16
17 ################################################################
18 sub new{
19         my $class = shift;
20         my $arg = shift;
21         my @argv = @{$arg->{argv}};
22         my $me = $class->SUPER::new(
23                 {
24                         CASE => 1,
25                         GLOBAL => {
26                                 ARGCOUNT => ARGCOUNT_ONE,
27                         }
28                 },
29                 qw(irc_nick irc_username irc_desc
30                    irc_server irc_port irc_password
31                    irc_keyword irc_charset
32                    au_subscriber_id au_pcsv
33                    docomo_foma_icc docomo_imodeid
34                    softbank_serial_key emobile_userid
35                    use_cookie cookie_ttl session_ttl
36                    web_listen_port
37                    web_port web_title web_lines web_root web_schema
38                    web_username web_password web_host web_charset
39                    common_header extra_header
40                    fontsize mobile_fontsize silent_config
41                    show_newmsgonly show_joinleave show_console
42                    ping_delay reconnect_delay follow_nick
43                    smtp_server smtp_from smtp_to debug
44                    version daemonize pid_dir pid_file
45                    template_dir plugin_dir public_dir
46                    url_target url_redirect
47                    rgeocode_server
48                    reverse_message reverse_recent reverse_unread)
49                 );
50
51         # set default values
52         $me->version($arg->{version});
53         $me->silent_config($arg->{silent});
54         $me->irc_desc('keitairc');
55         $me->irc_port(6667);
56         $me->irc_charset('iso-2022-jp-1');
57         $me->web_port(8080);
58         $me->web_title('keitairc');
59         $me->web_lines(100);
60         $me->web_root('/');
61         $me->web_charset('shiftjis');
62         $me->web_schema('http');
63         $me->ping_delay(30);
64         $me->reconnect_delay(10);
65         $me->cookie_ttl(86400 * 3);  # 3 days
66         $me->session_ttl(60 * 30);  # 30 min
67         $me->au_subscriber_id('');
68         $me->docomo_foma_icc('');
69         $me->docomo_imodeid('');
70         $me->softbank_serial_key('');
71         $me->emobile_userid('');
72         $me->pid_dir('/var/run');
73         $me->pid_file('keitairc.pid');
74         $me->plugin_dir(getcwd() . '/lib/plugins:/usr/share/keitairc/lib/plugins');
75         $me->template_dir(getcwd() . '/lib/templates:/usr/share/keitairc/lib/templates');
76         $me->public_dir(getcwd() . '/lib/public:/usr/share/keitairc/lib/public');
77         $me->reverse_message(1);
78         $me->reverse_recent(1);
79         $me->reverse_unread(1);
80         $me->show_joinleave(1);
81         $me->show_console(0);
82         $me->fontsize('+0');
83         $me->mobile_fontsize(-1);
84         $me->url_target('_self');
85         $me->follow_nick(1);
86         $me->rgeocode_server('refits');
87         $me->common_header('
88 <meta name="Robots" content="noindex,nofollow" />
89 <meta name="Keywords" content="norobot" />
90 <meta http-equiv="pragma" content="no-cache" />
91 <meta http-equiv="cache-control" content="no-cache" />
92 <meta http-equiv="expires" content="-1" />');
93         $me->debug(0);
94         $me->daemonize(0);
95
96         if(-r '/etc/keitairc'){
97                 $me->file('/etc/keitairc');
98         }
99         if(-r $ENV{HOME} . '/.keitairc'){
100                 $me->file($ENV{HOME} . '/.keitairc');
101         }
102
103         if(defined $argv[0]){
104                 if(-r $argv[0]){
105                         $me->file($argv[0]);
106                         shift(@argv);
107                 }
108         }
109
110         $me->args(\@argv);
111
112         if(defined $me->show_newmsgonly()){
113                 Keitairc::Log::log('show_newmsgonly has obsoleted from keitairc 2.0');
114         }
115
116         if(defined $me->web_username()){
117                 Keitairc::Log::log('web_username has obsoleted from keitairc 2.0');
118         }
119
120         if(defined $me->use_cookie()){
121                 Keitairc::Log::log('use_cookie has obsoleted from keitairc 2.0');
122         }
123
124         if(defined $me->au_pcsv()){
125                 Keitairc::Log::log('au_pcsv has obsoleted from keitairc 2.0');
126         }
127
128         if(!defined($me->irc_nick()) || !length($me->irc_nick())){
129                 Keitairc::Log::log_die('irc_nick does not specified');
130         }
131
132         if(!defined($me->irc_username()) || !length($me->irc_username())){
133                 Keitairc::Log::log_die('irc_username does not specified');
134         }
135
136         if(!defined($me->irc_server()) || !length($me->irc_server())){
137                 Keitairc::Log::log_die('irc_server does not specified');
138         }
139
140         if(!defined($me->web_listen_port()) || !length($me->web_listen_port())){
141                 $me->web_listen_port($me->web_port());
142         }
143
144         if(!defined($me->web_host()) || !length($me->web_host())){
145                 Keitairc::Log::log_die('web_host does not specified');
146         }
147
148         if(!defined($me->web_password()) || !length($me->web_password())){
149                 Keitairc::Log::log_die('web_password does not specified');
150         }
151
152         $me;
153 }
154
155 ################################################################
156 sub file{
157         my $me = shift;
158         my $file = shift;
159         if(-r $file){
160                 $me->SUPER::file($file);
161                 Keitairc::Log::log("Loaded configuration file: $file")
162                         unless $me->silent_config();
163                 return;
164         }
165         Keitairc::Log::log("$file does not exist");
166 }
167
168 ################################################################
169 sub content_charset{
170         my $me = shift;
171         Encode::MIME::Name::get_mime_name(Encode::resolve_alias($me->web_charset()));
172 }
173
174 1;