Changeset 366

Show
Ignore:
Timestamp:
04/22/03 10:44:29 (6 years ago)
Author:
jajcus
Message:

- new log translation handling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/configure.ac

    r361 r366  
    6161 
    6262MKINSTALLDIRS="${MKINSTALLDIRS} -m 755" 
     63XGETTEXT="${XGETTEXT} --keyword=L_" 
    6364 
    6465AC_CONFIG_FILES([Makefile src/Makefile intl/Makefile po/Makefile.in]) 
  • trunk/src/acl.c

    r344 r366  
    1 /* $Id: acl.c,v 1.3 2003/04/16 11:10:17 jajcus Exp $ */ 
     1/* $Id: acl.c,v 1.4 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    4747                if (!strcmp(str,"allow")) allow=1; 
    4848                else if (!strcmp(str,"deny")) allow=0; 
    49                 else g_error(N_("Invalid tag <%s/> in config section <acl/>"),str); 
     49                else g_error(L_("Invalid tag <%s/> in config section <acl/>"),str); 
    5050                what=xmlnode_get_attrib(node,"what"); 
    5151                if (!what || what[0]=='\000' || !strcmp(what,"*")) what=NULL; 
     
    9797        xmlnode_free(x); 
    9898        g_free(jid); 
    99         if (result) debug("Allowed"); 
    100         else debug("Denied"); 
     99        if (result) debug(L_("Allowed")); 
     100        else debug(L_("Denied")); 
    101101        return result; 
    102102} 
  • trunk/src/ggtrans.h

    r316 r366  
    1 /* $Id: ggtrans.h,v 1.11 2003/04/14 09:07:29 jajcus Exp $ */ 
     1/* $Id: ggtrans.h,v 1.12 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    2929#define _(String) gettext (String) 
    3030 
    31 /* dummy gettext shortcut for translating error/debug messages after log handler is set */ 
     31/* dummy gettext shortcut for translations out-of-place */ 
    3232#define N_(String) (String) 
     33 
     34/* gettext shortcut for translating error/debug messages (locale/encoding must be switched) */ 
     35#define L_(String) local_translate(String) 
     36 
     37const char *local_translate(const char *str); 
    3338 
    3439extern GMainLoop *main_loop; 
  • trunk/src/jabber.c

    r320 r366  
    1 /* $Id: jabber.c,v 1.22 2003/04/14 10:18:47 jajcus Exp $ */ 
     1/* $Id: jabber.c,v 1.23 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    6363        } 
    6464 
    65         g_message(N_("handshake OK")); 
     65        g_message(L_("handshake OK")); 
    6666        jabber_state=JS_CONNECTED; 
    6767        users_probe_all(); 
     
    7373        data=xmlnode_get_data(x); 
    7474        if (data==NULL) data="-unknown-"; 
    75         g_critical(N_("Stream error: %s"),data); 
     75        g_critical(L_("Stream error: %s"),data); 
    7676        stream_close(s); 
    7777        stop_it=1; 
     
    137137                        break; 
    138138                default: 
    139                         g_critical(N_("Unknown node type: %i"),type); 
     139                        g_critical(L_("Unknown node type: %i"),type); 
    140140                        stop_it=1; 
    141141                        stream_close(s); 
     
    217217        node=xmlnode_get_tag(config,"service"); 
    218218        if (!node) 
    219                 g_error(N_("No <service/> found in config file")); 
     219                g_error(L_("No <service/> found in config file")); 
    220220 
    221221        my_name=xmlnode_get_attrib(node,"jid"); 
    222222        if (!my_name) 
    223                 g_error(N_("<service/> without \"jid\" in config file")); 
     223                g_error(L_("<service/> without \"jid\" in config file")); 
    224224 
    225225        server=config_load_string("connect/ip"); 
    226226        if (!server) 
    227                 g_error(N_("Jabberd server not found in config file")); 
     227                g_error(L_("Jabberd server not found in config file")); 
    228228 
    229229        port=config_load_int("connect/port",0); 
    230230        if (port<=0) 
    231                 g_error(N_("Connect port not found in config file")); 
     231                g_error(L_("Connect port not found in config file")); 
    232232 
    233233        node=xmlnode_get_tag(config,"connect/secret"); 
    234234        if (node) secret=xmlnode_get_data(node); 
    235235        if (!node || !secret) 
    236                 g_error(N_("Connect secret not found in config file")); 
     236                g_error(L_("Connect secret not found in config file")); 
    237237 
    238238        register_instructions=config_load_formatted_string("register/instructions"); 
    239239        if (!register_instructions) 
    240                 g_error(N_("Registration instructions not not found in config file")); 
     240                g_error(L_("Registration instructions not not found in config file")); 
    241241 
    242242        search_instructions=config_load_formatted_string("search/instructions"); 
    243243        if (!search_instructions) 
    244                 g_error(N_("Search instructions not found in config file")); 
     244                g_error(L_("Search instructions not found in config file")); 
    245245 
    246246        gateway_desc=config_load_formatted_string("gateway/desc"); 
    247247        if (!gateway_desc) 
    248                 g_error(N_("Gateway instructions not found in config file")); 
     248                g_error(L_("Gateway instructions not found in config file")); 
    249249 
    250250        gateway_prompt=config_load_formatted_string("gateway/prompt"); 
    251251        if (!gateway_prompt) 
    252                 g_error(N_("Gateway prompt not found in config file")); 
     252                g_error(L_("Gateway prompt not found in config file")); 
    253253 
    254254        jabber_state=JS_NONE; 
  • trunk/src/jid.c

    r269 r366  
    1 /* $Id: jid.c,v 1.10 2003/04/06 15:42:42 mmazur Exp $ */ 
     1/* $Id: jid.c,v 1.11 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    3939                else if (jid[i]=='@') 
    4040                        if (!just_digits){ 
    41                                 debug(N_("Non-digits before '@' in jid: %s"),jid); 
     41                                debug(L_("Non-digits before '@' in jid: %s"),jid); 
    4242                                return 0; 
    4343                        } 
     
    5454        if (slash<0){ 
    5555                if ( g_strcasecmp(jid+at+1,my_name) ){ 
    56                         debug(N_("Bad hostname (%s) in JID: %s"),jid+at+1,jid); 
     56                        debug(L_("Bad hostname (%s) in JID: %s"),jid+at+1,jid); 
    5757                        return 0; 
    5858                } 
    5959        } else{ 
    6060                if ( slash-at-1!=strlen(my_name) ){ 
    61                         debug(N_("Bad hostname len (%i) instead of %i in JID: %s"),slash-at-1,strlen(my_name),jid); 
     61                        debug(L_("Bad hostname len (%i) instead of %i in JID: %s"),slash-at-1,strlen(my_name),jid); 
    6262                        return 0; 
    6363                } 
    6464 
    6565                if ( g_strncasecmp(jid+at+1,my_name,slash-at-1) ){ 
    66                         debug(N_("Bad hostname in JID: %s[%i:%i]"),jid,at+1,slash-at-2); 
     66                        debug(L_("Bad hostname in JID: %s[%i:%i]"),jid,at+1,slash-at-2); 
    6767                        return 0; 
    6868                } 
  • trunk/src/main.c

    r362 r366  
    1 /* $Id: main.c,v 1.47 2003/04/22 07:12:32 jajcus Exp $ */ 
     1/* $Id: main.c,v 1.48 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    3131#include <time.h> 
    3232#include <locale.h> 
     33 
     34#ifdef HAVE_LANGINFO_CODESET 
     35#  include <langinfo.h> 
     36#endif 
     37 
    3338#include "jabber.h" 
    3439#include "sessions.h" 
     
    173178        switch(log_level){ 
    174179                case G_LOG_LEVEL_ERROR: 
    175                         fprintf(f,_("Fatal error: %s\n"),_(message)); 
     180                        fprintf(f,_("Fatal error: %s\n"),message); 
    176181                        break; 
    177182                case G_LOG_LEVEL_CRITICAL: 
    178                         fprintf(f,_("Error: %s\n"),_(message)); 
     183                        fprintf(f,_("Error: %s\n"),message); 
    179184                        break; 
    180185                case G_LOG_LEVEL_WARNING: 
    181                         fprintf(f,_("Warning: %s\n"),_(message)); 
     186                        fprintf(f,_("Warning: %s\n"),message); 
    182187                        break; 
    183188                case G_LOG_LEVEL_MESSAGE: 
     
    185190                case G_LOG_LEVEL_INFO: 
    186191                        if (debug_level<0) break; 
    187                         fprintf(f,"%s\n",_(message)); 
     192                        fprintf(f,"%s\n",message); 
    188193                        break; 
    189194                case G_LOG_LEVEL_DEBUG: 
    190195                        if (debug_level>0) 
    191                                 fprintf(f,_("Debug: %s\n"),_(message)); 
     196                                fprintf(f,_("Debug: %s\n"),message); 
    192197                        break; 
    193198                default: 
    194                         fprintf(f,_("Unknown: %s\n"),_(message)); 
     199                        fprintf(f,_("Unknown: %s\n"),message); 
    195200                        break; 
    196201        } 
     
    202207        switch(log_level){ 
    203208                case G_LOG_LEVEL_ERROR: 
    204                         syslog(LOG_ERR,_("Fatal error: %s"),_(message)); 
     209                        syslog(LOG_ERR,_("Fatal error: %s"),message); 
    205210                        break; 
    206211                case G_LOG_LEVEL_CRITICAL: 
    207                         syslog(LOG_ERR,_("Error: %s"),_(message)); 
     212                        syslog(LOG_ERR,_("Error: %s"),message); 
    208213                        break; 
    209214                case G_LOG_LEVEL_WARNING: 
    210                         syslog(LOG_WARNING,_("Warning: %s"),_(message)); 
     215                        syslog(LOG_WARNING,_("Warning: %s"),message); 
    211216                        break; 
    212217                case G_LOG_LEVEL_MESSAGE: 
    213218                        if (debug_level<-1) break; 
    214                         syslog(LOG_NOTICE,"%s",_(message)); 
     219                        syslog(LOG_NOTICE,"%s",message); 
    215220                        break; 
    216221                case G_LOG_LEVEL_INFO: 
    217222                        if (debug_level<0) break; 
    218                         syslog(LOG_NOTICE,"%s",_(message)); 
     223                        syslog(LOG_NOTICE,"%s",message); 
    219224                        break; 
    220225                case G_LOG_LEVEL_DEBUG: 
    221226                        if (debug_level>0) 
    222                                 syslog(LOG_DEBUG,_("Debug: %s\n"),_(message)); 
     227                                syslog(LOG_DEBUG,_("Debug: %s\n"),message); 
    223228                        break; 
    224229                default: 
    225                         syslog(LOG_NOTICE,_("Unknown: %s\n"),_(message)); 
    226                         break; 
    227         } 
    228 
    229  
    230 void log_handler(const gchar *log_domain, GLogLevelFlags log_level, 
    231                         const gchar *message, gpointer user_data){ 
    232  
    233 char *lc_ctype,*lc_messages,*td_codeset; 
     230                        syslog(LOG_NOTICE,_("Unknown: %s\n"),message); 
     231                        break; 
     232        } 
     233
     234 
     235const char *local_translate(const char *str){ 
     236const char *lc_ctype,*lc_messages,*td_codeset,*ret; 
    234237 
    235238        td_codeset=bind_textdomain_codeset(PACKAGE,NULL); 
    236239        lc_ctype=setlocale(LC_CTYPE,NULL); 
    237240        lc_messages=setlocale(LC_MESSAGES,NULL); 
     241        setlocale(LC_MESSAGES,""); 
     242        setlocale(LC_CTYPE,""); 
     243#ifdef HAVE_LANGINFO_CODESET 
     244        bind_textdomain_codeset(PACKAGE,nl_langinfo(CODESET)); 
     245#endif 
     246/*      textdomain(PACKAGE);*/ 
     247 
     248        ret=gettext(str); 
     249 
     250        setlocale(LC_CTYPE,lc_ctype); 
     251        setlocale(LC_MESSAGES,lc_ctype); 
     252        bind_textdomain_codeset(PACKAGE,td_codeset); 
     253 
     254        return ret; 
     255} 
     256 
     257void log_handler(const gchar *log_domain, GLogLevelFlags log_level, 
     258                        const gchar *message, gpointer user_data){ 
     259 
     260char *lc_ctype,*lc_messages,*td_codeset; 
     261 
     262        td_codeset=bind_textdomain_codeset(PACKAGE,NULL); 
     263        lc_ctype=setlocale(LC_CTYPE,NULL); 
     264        lc_messages=setlocale(LC_MESSAGES,NULL); 
     265        setlocale(LC_MESSAGES,""); 
     266        setlocale(LC_CTYPE,""); 
     267#ifdef HAVE_LANGINFO_CODESET 
     268        bind_textdomain_codeset(PACKAGE,nl_langinfo(CODESET)); 
     269#endif 
     270/*      textdomain(PACKAGE);*/ 
    238271 
    239272        log_level&=G_LOG_LEVEL_MASK; 
     
    252285int fd; 
    253286 
    254         debug(N_("Daemonizing...")); 
     287        debug(L_("Daemonizing...")); 
    255288        pid=fork(); 
    256         if (pid==-1) g_error(N_("Failed to fork(): %s"),g_strerror(errno)); 
     289        if (pid==-1) g_error(L_("Failed to fork(): %s"),g_strerror(errno)); 
    257290        if (pid){ 
    258291                if (pidfile){ 
     
    260293                        fclose(pidfile); 
    261294                } 
    262                 debug(N_("Daemon born, pid %i."),pid); 
     295                debug(L_("Daemon born, pid %i."),pid); 
    263296                exit(0); 
    264297        } 
     
    282315        if (sid==-1) abort(); 
    283316        foreground=FALSE; 
    284         debug(N_("I am a daemon, I think.")); 
     317        debug(L_("I am a daemon, I think.")); 
    285318        return; 
    286319} 
     
    406439        config=xmlnode_file(config_file); 
    407440        if (!config){ 
    408                 g_error(N_("Couldn't load config!")); 
     441                g_error(L_("Couldn't load config!")); 
    409442                return 1; 
    410443        } 
    411444        str=xmlnode_get_name(config); 
    412445        if (!str || strcmp(str,"jggtrans")){ 
    413                 g_error(N_("%s doesn't look like jggtrans config file."),config_file); 
     446                g_error(L_("%s doesn't look like jggtrans config file."),config_file); 
    414447                return 1; 
    415448        } 
     
    438471                                if (!strcmp(facilitynames[log_facility].name,str)) break; 
    439472                        if (!facilitynames[log_facility].name) 
    440                                  g_error(N_("Unknown syslog facility: %s"),str); 
     473                                 g_error(L_("Unknown syslog facility: %s"),str); 
    441474                } 
    442475                else if (!strcmp(log_type,"file")){ 
     
    465498                        if (r==1 && pid>0){ 
    466499                                r=kill(pid,0); 
    467                                 if (!r || (r && errno!=ESRCH)) g_error(N_("jggtrans already running")); 
     500                                if (!r || (r && errno!=ESRCH)) g_error(L_("jggtrans already running")); 
    468501                                if (r){ 
    469502                                        g_warning(N_("Stale pid file. Removing.")); 
     
    471504                                } 
    472505                        } 
    473                         else if (r!=EOF) g_error(N_("Invalid pid file.")); 
     506                        else if (r!=EOF) g_error(L_("Invalid pid file.")); 
    474507                } 
    475508                pidfile=fopen(pid_filename,"w"); 
    476509                if (pidfile==NULL) 
    477                         g_error(N_("Couldn't open pidfile %s"),pid_filename); 
     510                        g_error(L_("Couldn't open pidfile %s"),pid_filename); 
    478511        } 
    479512        else 
     
    482515        if (group){ 
    483516                grp=getgrnam(group); 
    484                 if (!grp) g_error(N_("Couldn't find group %s"),group); 
     517                if (!grp) g_error(L_("Couldn't find group %s"),group); 
    485518                newgid=grp->gr_gid; 
    486519        } 
    487520        if (user){ 
    488521                pwd=getpwnam(user); 
    489                 if (!pwd) g_error(N_("Couldn't find user %s"),user); 
     522                if (!pwd) g_error(L_("Couldn't find user %s"),user); 
    490523                if (newgid<=0) newgid=pwd->pw_gid; 
    491524                fchown(fileno(pidfile),pwd->pw_uid,newgid); 
    492                 if (setgid(newgid)) g_error(N_("Couldn't change group: %s"),g_strerror(errno)); 
    493                 if (initgroups(user,newgid)) g_error(N_("Couldn't init groups: %s"),g_strerror(errno)); 
    494                 if (setuid(pwd->pw_uid)) g_error(N_("Couldn't change user: %s"),g_strerror(errno)); 
    495         } 
    496         else if (uid==0 && !restarting) g_error(N_("Refusing to run with uid=0")); 
     525                if (setgid(newgid)) g_error(L_("Couldn't change group: %s"),g_strerror(errno)); 
     526                if (initgroups(user,newgid)) g_error(L_("Couldn't init groups: %s"),g_strerror(errno)); 
     527                if (setuid(pwd->pw_uid)) g_error(L_("Couldn't change user: %s"),g_strerror(errno)); 
     528        } 
     529        else if (uid==0 && !restarting) g_error(L_("Refusing to run with uid=0")); 
    497530 
    498531        main_loop=g_main_new(0); 
     
    513546        if (log_filename){ 
    514547                log_file=fopen(log_filename,"a"); 
    515                 if (!log_file) g_critical(N_("Couldn't open log file '%s': %s"), 
     548                if (!log_file) g_critical(L_("Couldn't open log file '%s': %s"), 
    516549                                                log_filename,g_strerror(errno)); 
    517550                if (log_file) setvbuf(log_file,NULL,_IOLBF,0); 
     
    548581                int n; 
    549582 
    550                 g_message(N_("Restarting in %i seconds.\n"),restart_timeout); 
     583                g_message(L_("Restarting in %i seconds.\n"),restart_timeout); 
    551584                if (restart_timeout>0) sleep(restart_timeout); 
    552585                if (saved_pwd) chdir(saved_pwd); 
     
    571604        } 
    572605 
    573         g_message(N_("Exiting normally.\n")); 
     606        g_message(L_("Exiting normally.\n")); 
    574607 
    575608        g_log_remove_handler(NULL,lh); 
  • trunk/src/register.c

    r349 r366  
    1 /* $Id: register.c,v 1.37 2003/04/20 14:09:39 jajcus Exp $ */ 
     1/* $Id: register.c,v 1.38 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    391391int change_password_error(struct request_s *r){ 
    392392 
    393         g_message(N_("Password change error for user '%s'"),r->from); 
     393        g_message(L_("Password change error for user '%s'"),r->from); 
    394394        jabber_iq_send_error(r->stream,r->from,r->to,r->id,500,_("Internal Server Error")); 
    395395        return 0; 
     
    405405        } 
    406406 
    407         g_message(N_("Password changed for user '%s'"),r->from); 
     407        g_message(L_("Password changed for user '%s'"),r->from); 
    408408        if (r->data){ 
    409409                g_free(u->password); 
     
    470470char *jid; 
    471471 
    472         debug(N_("Unregistering '%s'"),from); 
     472        debug(L_("Unregistering '%s'"),from); 
    473473        ses=session_get_by_jid(from,NULL); 
    474474        if (ses) 
     
    500500        } 
    501501        presence_send_unsubscribed(s,NULL,jid); 
    502         g_message(N_("User '%s' unregistered"),from); 
     502        g_message(L_("User '%s' unregistered"),from); 
    503503        g_free(jid); 
    504504        return 0; 
     
    520520        node=xmlnode_get_firstchild(q); 
    521521        if (!node){ 
    522                 debug(N_("Set query for jabber:iq:register empty: %s"),xmlnode2str(q)); 
     522                debug(L_("Set query for jabber:iq:register empty: %s"),xmlnode2str(q)); 
    523523                unregister(s,from,to,id,0); 
    524524                return; 
     
    546546        node=xmlnode_get_tag(q,"remove"); 
    547547        if (node){ 
    548                 debug(N_("<remove/> in jabber:iq:register set: %s"),xmlnode2str(q)); 
     548                debug(L_("<remove/> in jabber:iq:register set: %s"),xmlnode2str(q)); 
    549549                unregister(s,from,to,id,0); 
    550550                return; 
     
    606606        if (!first && !last && !nick && !city && !born && !sex){ 
    607607                        if (!uin && !password){ 
    608                                 debug(N_("Set query for jabber:iq:register empty: %s"),xmlnode2str(q)); 
     608                                debug(L_("Set query for jabber:iq:register empty: %s"),xmlnode2str(q)); 
    609609                                unregister(s,from,to,id,0); 
    610610                                return; 
  • trunk/src/stream.c

    r332 r366  
    1 /* $Id: stream.c,v 1.19 2003/04/15 16:33:04 jajcus Exp $ */ 
     1/* $Id: stream.c,v 1.20 2003/04/22 08:44:29 jajcus Exp $ */ 
    22 
    33/* 
     
    7474        fd=socket(PF_INET,SOCK_STREAM,0); 
    7575        if (!fd){ 
    76                 g_error(N_("socket: %s"),g_strerror(errno)); 
     76                g_error(L_("socket: %s"),g_strerror(errno)); 
    7777                g_free(s); 
    7878                return NULL; 
     
    116116        else{ 
    117117                if (r<0){ 
    118                         g_error(N_("connect: %s"),g_strerror(errno)); 
     118                        g_error(L_("connect: %s"),g_strerror(errno)); 
    119119                        g_free(s); 
    120120                        return NULL; 
     
    150150        } 
    151151        if (errno==EALREADY) return 0; 
    152         g_critical(N_("connect: %s"),g_strerror(errno)); 
     152        g_critical(L_("connect: %s"),g_strerror(errno)); 
    153153        return -1; 
    154154} 
     
    163163        s->xs->f(XSTREAM_CLOSE,NULL,s); 
    164164        if (!s->connected) 
    165                 g_critical(N_("Couldn't connect to jabber server")); 
     165                g_critical(L_("Couldn't connect to jabber server")); 
    166166        else 
    167                 g_critical(N_("Connection to jabber server broken")); 
     167                g_critical(L_("Connection to jabber server broken")); 
    168168        do_restart=TRUE; 
    169169        return FALSE; 
     
    197197        g_assert(s); 
    198198 
    199         if (!s->connected) g_error(N_("Unconnected stream")); 
     199        if (!s->connected) g_error(L_("Unconnected stream")); 
    200200 
    201201        if (!s->read_buf){