Annotation of sbbs/src/sbbs3/msg_id.c, revision 1.1.1.2

1.1       root        1: /* msg_id.c */
                      2: 
                      3: /* Synchronet Message-ID generation routines */
                      4: 
1.1.1.2 ! root        5: /* $Id: msg_id.c,v 1.4 2008/02/25 08:25:29 rswindell Exp $ */
1.1       root        6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       12:  *                                                                                                                                                     *
                     13:  * This program is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU General Public License                         *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU General Public License for more details: gpl.txt or                     *
                     18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #include "sbbs.h"
                     39: 
                     40: static msg_number(smbmsg_t* msg)
                     41: {
                     42:        if(msg->idx.number)
                     43:                return(msg->idx.number);
                     44:        return(msg->hdr.number);
                     45: }
                     46: 
                     47: static msg_time(smbmsg_t* msg)
                     48: {
                     49:        if(msg->idx.time)
                     50:                return(msg->idx.time);
                     51:        return(msg->hdr.when_imported.time);
                     52: }
                     53: 
                     54: static ulong msgid_serialno(smbmsg_t* msg)
                     55: {
                     56:        return (msg_time(msg)-1000000000) + msg_number(msg);
                     57: }
                     58: 
                     59: /****************************************************************************/
                     60: /* Returns a FidoNet (FTS-9) message-ID                                                                                */
                     61: /****************************************************************************/
1.1.1.2 ! root       62: char* DLLCALL ftn_msgid(sub_t *sub, smbmsg_t* msg, char* msgid, size_t maxlen)
1.1       root       63: {
1.1.1.2 ! root       64:        if(msg->ftn_msgid!=NULL && *msg->ftn_msgid!=0) {
        !            65:                strncpy(msgid,msg->ftn_msgid,maxlen);
1.1       root       66:                return(msg->ftn_msgid);
1.1.1.2 ! root       67:        }
1.1       root       68: 
1.1.1.2 ! root       69:        safe_snprintf(msgid,maxlen
1.1       root       70:                ,"%lu.%s@%s %08lx"
                     71:                ,msg_number(msg)
                     72:                ,sub->code
                     73:                ,smb_faddrtoa(&sub->faddr,NULL)
                     74:                ,msgid_serialno(msg)
                     75:                );
                     76: 
                     77:        return(msgid);
                     78: }
                     79: 
                     80: /****************************************************************************/
                     81: /* Return a general purpose (RFC-822) message-ID                                                       */
                     82: /****************************************************************************/
1.1.1.2 ! root       83: char* DLLCALL get_msgid(scfg_t* cfg, uint subnum, smbmsg_t* msg, char* msgid, size_t maxlen)
1.1       root       84: {
1.1.1.2 ! root       85:        char*   host;
1.1       root       86: 
1.1.1.2 ! root       87:        if(msg->id!=NULL && *msg->id!=0) {
        !            88:                strncpy(msgid,msg->id,maxlen);
1.1       root       89:                return(msg->id);
1.1.1.2 ! root       90:        }
        !            91: 
        !            92:        /* Try *really* hard to get a hostname from the configuration data */
        !            93:        host=cfg->sys_inetaddr;
        !            94:        if(!host[0]) {
        !            95:                host=cfg->sys_id;
        !            96:                if(!host[0]) {
        !            97:                        host=cfg->sys_name;
        !            98:                        if(!host[0]) {
        !            99:                                host=cfg->sys_op;
        !           100:                        }
        !           101:                }
        !           102:        }
1.1       root      103: 
                    104:        if(subnum>=cfg->total_subs)
1.1.1.2 ! root      105:                safe_snprintf(msgid,maxlen
1.1       root      106:                        ,"<%08lX.%lu@%s>"
                    107:                        ,msg_time(msg)
                    108:                        ,msg_number(msg)
1.1.1.2 ! root      109:                        ,host);
1.1       root      110:        else
1.1.1.2 ! root      111:                safe_snprintf(msgid,maxlen
1.1       root      112:                        ,"<%08lX.%lu.%s@%s>"
                    113:                        ,msg_time(msg)
                    114:                        ,msg_number(msg)
                    115:                        ,cfg->sub[subnum]->code
1.1.1.2 ! root      116:                        ,host);
1.1       root      117: 
                    118:        return(msgid);
                    119: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.