Annotation of sbbs/src/smblib/smbstr.c, revision 1.1.1.1

1.1       root        1: /* smbstr.c */
                      2: 
                      3: /* Synchronet message base (SMB) library routines returning strings */
                      4: 
                      5: /* $Id: smbstr.c,v 1.11 2006/04/25 02:26:06 rswindell Exp $ */
                      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:  *                                                                                                                                                     *
                     11:  * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html         *
                     12:  *                                                                                                                                                     *
                     13:  * This library is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details: lgpl.txt or     *
                     18:  * http://www.fsf.org/copyleft/lesser.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 <ctype.h>             /* is*() */
                     39: #include <string.h>            /* strcpy, strcat, memset, strchr */
                     40: #include <genwrap.h>           /* stricmp */
                     41: #include "smblib.h"
                     42: 
                     43: char* SMBCALL smb_hfieldtype(ushort type)
                     44: {
                     45:        static char str[8];
                     46: 
                     47:        switch(type) {
                     48:                case SENDER:                    return("Sender");
                     49:                case SENDERAGENT:               return("SenderAgent");
                     50:                case SENDERNETTYPE:             return("SenderNetType");
                     51:                case SENDERNETADDR:             return("SenderNetAddr");
                     52:                case SENDEREXT:                 return("SenderExt");
                     53:                case SENDERORG:                 return("SenderOrg");
                     54:                case SENDERIPADDR:              return("SenderIpAddr");
                     55:                case SENDERHOSTNAME:    return("SenderHostName");
                     56:                case SENDERPROTOCOL:    return("SenderProtocol");
                     57:                case SENDERPORT:                return("SenderPort");
                     58: 
                     59:                case REPLYTO:                   return("ReplyTo");
                     60:                case REPLYTOAGENT:              return("ReplyToAgent");
                     61:                case REPLYTONETTYPE:    return("ReplyToNetType");
                     62:                case REPLYTONETADDR:    return("ReplyToNetAddr");
                     63:                case REPLYTOEXT:                return("ReplyToExt");
                     64:                                                                
                     65:                case RECIPIENT:                 return("Recipient");
                     66:                case RECIPIENTAGENT:    return("RecipientAgent");
                     67:                case RECIPIENTNETTYPE:  return("RecipientNetType");
                     68:                case RECIPIENTNETADDR:  return("RecipientNetAddr");
                     69:                case RECIPIENTEXT:              return("RecipientExt");
                     70: 
                     71:                case SUBJECT:                   return("Subject");
                     72:                case SMB_SUMMARY:               return("Summary");
                     73:                case SMB_COMMENT:               return("Comment");
                     74:                case SMB_CARBONCOPY:    return("CarbonCopy");
                     75:                case SMB_GROUP:                 return("Group");
                     76:                case SMB_EXPIRATION:    return("Expiration");
                     77:                case SMB_PRIORITY:              return("Priority");
                     78:                case SMB_COST:                  return("Cost");
                     79: 
                     80:                case FIDOCTRL:                  return("FidoCtrl");
                     81:                case FIDOAREA:                  return("FidoArea");
                     82:                case FIDOSEENBY:                return("FidoSeenBy");
                     83:                case FIDOPATH:                  return("FidoPath");
                     84:                case FIDOMSGID:                 return("FidoMsgID");
                     85:                case FIDOREPLYID:               return("FidoReplyID");
                     86:                case FIDOPID:                   return("FidoPID");
                     87:                case FIDOFLAGS:                 return("FidoFlags");
                     88:                case FIDOTID:                   return("FidoTID");
                     89: 
                     90:                case RFC822HEADER:              return("RFC822Header");
                     91:                case RFC822MSGID:               return("RFC822MsgID");
                     92:                case RFC822REPLYID:             return("RFC822ReplyID");
                     93:                case RFC822TO:                  return("RFC822To");
                     94:                case RFC822FROM:                return("RFC822From");
                     95:                case RFC822REPLYTO:             return("RFC822ReplyTo");
                     96: 
                     97:                case USENETPATH:                return("UsenetPath");
                     98:                case USENETNEWSGROUPS:  return("UsenetNewsgroups");
                     99: 
                    100:                case SMTPCOMMAND:               return("SMTPCommand");
                    101:                case SMTPREVERSEPATH:   return("SMTPReversePath");
                    102:                case SMTPFORWARDPATH:   return("SMTPForwardPath");
                    103: 
                    104:                case SMTPSYSMSG:                return("SMTPSysMsg");
                    105: 
                    106:                case UNKNOWN:                   return("UNKNOWN");
                    107:                case UNKNOWNASCII:              return("UNKNOWNASCII");
                    108:                case UNUSED:                    return("UNUSED");
                    109:        }
                    110:        sprintf(str,"%02Xh",type);
                    111:        return(str);
                    112: }
                    113: 
                    114: ushort SMBCALL smb_hfieldtypelookup(const char* str)
                    115: {
                    116:        ushort type;
                    117: 
                    118:        if(isdigit(*str))
                    119:                return((ushort)strtol(str,NULL,0));
                    120: 
                    121:        for(type=0;type<=UNUSED;type++)
                    122:                if(stricmp(str,smb_hfieldtype(type))==0)
                    123:                        return(type);
                    124: 
                    125:        return(UNKNOWN);
                    126: }
                    127: 
                    128: char* SMBCALL smb_dfieldtype(ushort type)
                    129: {
                    130:        static char str[8];
                    131: 
                    132:        switch(type) {
                    133:                case TEXT_BODY: return("TEXT_BODY");
                    134:                case TEXT_TAIL: return("TEXT_TAIL");
                    135:                case UNUSED:    return("UNUSED");
                    136:        }
                    137:        sprintf(str,"%02Xh",type);
                    138:        return(str);
                    139: }
                    140: 
                    141: char* SMBCALL smb_hashsourcetype(uchar type)
                    142: {
                    143:        static char str[8];
                    144: 
                    145:        switch(type) {
                    146:                case SMB_HASH_SOURCE_BODY:              return(smb_dfieldtype(TEXT_BODY));
                    147:                case SMB_HASH_SOURCE_MSG_ID:    return(smb_hfieldtype(RFC822MSGID));
                    148:                case SMB_HASH_SOURCE_FTN_ID:    return(smb_hfieldtype(FIDOMSGID));
                    149:        }
                    150:        sprintf(str,"%02Xh",type);
                    151:        return(str);
                    152: }
                    153: 
                    154: char* SMBCALL smb_hashsource(smbmsg_t* msg, int source)
                    155: {
                    156:        switch(source) {
                    157:                case SMB_HASH_SOURCE_MSG_ID:
                    158:                        return(msg->id);
                    159:                case SMB_HASH_SOURCE_FTN_ID:
                    160:                        return(msg->ftn_msgid);
                    161:        }
                    162:        return("hash");
                    163: }
                    164: 
                    165: /****************************************************************************/
                    166: /* Converts when_t.zone into ASCII format                                   */
                    167: /****************************************************************************/
                    168: char* SMBCALL smb_zonestr(short zone, char* outstr)
                    169: {
                    170:        char*           plus;
                    171:     static char str[32];
                    172: 
                    173:        switch((ushort)zone) {
                    174:                case 0:     return("UTC");
                    175:                case AST:   return("AST");
                    176:                case EST:   return("EST");
                    177:                case CST:   return("CST");
                    178:                case MST:   return("MST");
                    179:                case PST:   return("PST");
                    180:                case YST:   return("YST");
                    181:                case HST:   return("HST");
                    182:                case BST:   return("BST");
                    183:                case ADT:   return("ADT");
                    184:                case EDT:   return("EDT");
                    185:                case CDT:   return("CDT");
                    186:                case MDT:   return("MDT");
                    187:                case PDT:   return("PDT");
                    188:                case YDT:   return("YDT");
                    189:                case HDT:   return("HDT");
                    190:                case BDT:   return("BDT");
                    191:                case MID:   return("MID");
                    192:                case VAN:   return("VAN");
                    193:                case EDM:   return("EDM");
                    194:                case WIN:   return("WIN");
                    195:                case BOG:   return("BOG");
                    196:                case CAR:   return("CAR");
                    197:                case RIO:   return("RIO");
                    198:                case FER:   return("FER");
                    199:                case AZO:   return("AZO");
                    200:                case LON:   return("LON");
                    201:                case BER:   return("BER");
                    202:                case ATH:   return("ATH");
                    203:                case MOS:   return("MOS");
                    204:                case DUB:   return("DUB");
                    205:                case KAB:   return("KAB");
                    206:                case KAR:   return("KAR");
                    207:                case BOM:   return("BOM");
                    208:                case KAT:   return("KAT");
                    209:                case DHA:   return("DHA");
                    210:                case BAN:   return("BAN");
                    211:                case HON:   return("HON");
                    212:                case TOK:   return("TOK");
                    213:                case SYD:   return("SYD");
                    214:                case NOU:   return("NOU");
                    215:                case WEL:   return("WEL");
                    216:                }
                    217: 
                    218:        if(!OTHER_ZONE(zone)) {
                    219:                if(zone&(WESTERN_ZONE|US_ZONE)) /* West of UTC? */
                    220:                        zone=-(zone&0xfff);
                    221:                else
                    222:                        zone&=0xfff;
                    223:        }
                    224: 
                    225:        if(zone>0)
                    226:                plus="+";
                    227:        else
                    228:                plus="";
                    229:        sprintf(str,"UTC%s%d:%02u", plus, zone/60, zone<0 ? (-zone)%60 : zone%60);
                    230: 
                    231:        if(outstr==NULL)
                    232:                return(str);
                    233:        strcpy(outstr,str);
                    234:        return(outstr);
                    235: }
                    236: 
                    237: /****************************************************************************/
                    238: /* Returns an ASCII string for FidoNet address 'addr'                       */
                    239: /****************************************************************************/
                    240: char* SMBCALL smb_faddrtoa(fidoaddr_t* addr, char* outstr)
                    241: {
                    242:        static char str[64];
                    243:     char point[25];
                    244: 
                    245:        if(addr==NULL)
                    246:                return("0:0/0");
                    247:        sprintf(str,"%hu:%hu/%hu",addr->zone,addr->net,addr->node);
                    248:        if(addr->point) {
                    249:                sprintf(point,".%hu",addr->point);
                    250:                strcat(str,point); 
                    251:        }
                    252:        if(outstr==NULL)
                    253:                return(str);
                    254:        strcpy(outstr,str);
                    255:        return(outstr);
                    256: }
                    257: 
                    258: /****************************************************************************/
                    259: /* Returns the FidoNet address parsed from str.                                                                */
                    260: /****************************************************************************/
                    261: fidoaddr_t SMBCALL smb_atofaddr(const fidoaddr_t* sys_addr, const char *str)
                    262: {
                    263:        char *p;
                    264:        fidoaddr_t addr;
                    265:        fidoaddr_t tmp_addr={1,1,1,0};  /* Default system address: 1:1/1.0 */
                    266: 
                    267:        if(sys_addr==NULL)
                    268:                sys_addr=&tmp_addr;
                    269: 
                    270:        ZERO_VAR(addr);
                    271:        if((p=strchr(str,':'))!=NULL) {
                    272:                addr.zone=atoi(str);
                    273:                addr.net=atoi(p+1); 
                    274:        } else {
                    275:                addr.zone=sys_addr->zone;
                    276:                addr.net=atoi(str);
                    277:        }
                    278:        if(addr.zone==0)              /* no such thing as zone 0 */
                    279:                addr.zone=1;
                    280:        if((p=strchr(str,'/'))!=NULL)
                    281:                addr.node=atoi(p+1);
                    282:        else {
                    283:                if(addr.zone==sys_addr->zone)
                    284:                        addr.net=sys_addr->net;
                    285:                addr.node=atoi(str); 
                    286:        }
                    287:        if((p=strchr(str,'.'))!=NULL)
                    288:                addr.point=atoi(p+1);
                    289:        return(addr);
                    290: }
                    291: 
                    292: /****************************************************************************/
                    293: /* Returns ASCIIZ representation of network address (net_t)                                    */
                    294: /****************************************************************************/
                    295: char* SMBCALL smb_netaddr(net_t* net)
                    296: {
                    297:        if(net->type==NET_FIDO)
                    298:                return(smb_faddrtoa((fidoaddr_t*)net->addr,NULL));
                    299:        return(net->addr);
                    300: }
                    301: 
                    302: /****************************************************************************/
                    303: /* Returns net_type for passed e-mail address (i.e. "user@addr")                       */
                    304: /****************************************************************************/
                    305: ushort SMBCALL smb_netaddr_type(const char* str)
                    306: {
                    307:        char*   p;
                    308:        char*   tp;
                    309: 
                    310:        if((p=strchr(str,'@'))==NULL)
                    311:                return(NET_NONE);
                    312: 
                    313:        p++;
                    314:        SKIP_WHITESPACE(p);
                    315:        if(*p==0)
                    316:                return(NET_UNKNOWN);
                    317: 
                    318:        if(isalpha(*p) && strchr(p,'.')==NULL)
                    319:                return(NET_QWK);
                    320: 
                    321:        for(tp=p;*tp;tp++) {
                    322:                if(!isdigit(*tp) && *tp!=':' && *tp!='/' && *tp!='.')
                    323:                        break;
                    324:        }
                    325:        if(isdigit(*p) && *tp)
                    326:                return(NET_FIDO);
                    327:        if(isalnum(*p))
                    328:                return(NET_INTERNET);
                    329: 
                    330:        return(NET_UNKNOWN);
                    331: }

unix.superglobalmegacorp.com

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