|
|
1.1 ! root 1: /* msgdate.c */ ! 2: ! 3: /* Synchronet RFC822 message date/time string conversion routines */ ! 4: ! 5: /* $Id: msgdate.c,v 1.2 2006/04/05 09:11:31 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 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: /****************************************************************************/ ! 41: /* Convert when_t structure to RFC822 date header field (string) */ ! 42: /****************************************************************************/ ! 43: char* DLLCALL msgdate(when_t when, char* buf) ! 44: { ! 45: struct tm tm; ! 46: char plus='+'; ! 47: short tz; ! 48: ! 49: tz=smb_tzutc(when.zone); ! 50: if(tz<0) { ! 51: plus='-'; ! 52: tz=-tz; ! 53: } ! 54: ! 55: if(localtime_r((const time_t*)&when.time,&tm)==NULL) ! 56: memset(&tm,0,sizeof(tm)); ! 57: sprintf(buf,"%s, %d %s %d %02d:%02d:%02d %c%02u%02u" ! 58: ,wday[tm.tm_wday] ! 59: ,tm.tm_mday ! 60: ,mon[tm.tm_mon] ! 61: ,1900+tm.tm_year ! 62: ,tm.tm_hour ! 63: ,tm.tm_min ! 64: ,tm.tm_sec ! 65: /* RFC1123: implementations SHOULD use numeric timezones instead of timezone names */ ! 66: ,plus, tz/60, tz%60 ! 67: ); ! 68: return(buf); ! 69: } ! 70: ! 71: /****************************************************************************/ ! 72: /* Convert RFC822 date header field to when_t structure */ ! 73: /* dd mon yyyy hh:mm:ss [zone] */ ! 74: /****************************************************************************/ ! 75: when_t DLLCALL rfc822date(char* date) ! 76: { ! 77: char* p=date; ! 78: char str[32]; ! 79: char month[32]; ! 80: when_t when; ! 81: struct tm tm; ! 82: ! 83: memset(&tm,0,sizeof(tm)); ! 84: memset(&when,0,sizeof(when)); ! 85: ! 86: while(*p && *p<=' ') p++; ! 87: while(*p && !isdigit(*p)) p++; ! 88: /* DAY */ ! 89: tm.tm_mday=atoi(p); ! 90: while(*p && isdigit(*p)) p++; ! 91: /* MONTH */ ! 92: while(*p && *p<=' ') p++; ! 93: sprintf(month,"%3.3s",p); ! 94: if(!stricmp(month,"jan")) ! 95: tm.tm_mon=0; ! 96: else if(!stricmp(month,"feb")) ! 97: tm.tm_mon=1; ! 98: else if(!stricmp(month,"mar")) ! 99: tm.tm_mon=2; ! 100: else if(!stricmp(month,"apr")) ! 101: tm.tm_mon=3; ! 102: else if(!stricmp(month,"may")) ! 103: tm.tm_mon=4; ! 104: else if(!stricmp(month,"jun")) ! 105: tm.tm_mon=5; ! 106: else if(!stricmp(month,"jul")) ! 107: tm.tm_mon=6; ! 108: else if(!stricmp(month,"aug")) ! 109: tm.tm_mon=7; ! 110: else if(!stricmp(month,"sep")) ! 111: tm.tm_mon=8; ! 112: else if(!stricmp(month,"oct")) ! 113: tm.tm_mon=9; ! 114: else if(!stricmp(month,"nov")) ! 115: tm.tm_mon=10; ! 116: else ! 117: tm.tm_mon=11; ! 118: p+=4; ! 119: /* YEAR */ ! 120: tm.tm_year=atoi(p); ! 121: if(tm.tm_year<Y2K_2DIGIT_WINDOW) ! 122: tm.tm_year+=100; ! 123: else if(tm.tm_year>1900) ! 124: tm.tm_year-=1900; ! 125: ! 126: while(*p && isdigit(*p)) p++; ! 127: /* HOUR */ ! 128: while(*p && *p<=' ') p++; ! 129: tm.tm_hour=atoi(p); ! 130: while(*p && isdigit(*p)) p++; ! 131: /* MINUTE */ ! 132: if(*p) p++; ! 133: tm.tm_min=atoi(p); ! 134: while(*p && isdigit(*p)) p++; ! 135: /* SECONDS */ ! 136: if(*p) p++; ! 137: tm.tm_sec=atoi(p); ! 138: while(*p && isdigit(*p)) p++; ! 139: /* TIME ZONE */ ! 140: while(*p && *p<=' ') p++; ! 141: if(*p) { ! 142: if(isdigit(*p) || *p=='-' || *p=='+') { /* [+|-]HHMM format */ ! 143: if(*p=='+') p++; ! 144: sprintf(str,"%.*s",*p=='-'? 3:2,p); ! 145: when.zone=atoi(str)*60; ! 146: p+=(*p=='-') ? 3:2; ! 147: if(when.zone<0) ! 148: when.zone-=atoi(p); ! 149: else ! 150: when.zone+=atoi(p); ! 151: } ! 152: else if(!strnicmp(p,"PDT",3)) ! 153: when.zone=(short)PDT; ! 154: else if(!strnicmp(p,"MDT",3)) ! 155: when.zone=(short)MDT; ! 156: else if(!strnicmp(p,"CDT",3)) ! 157: when.zone=(short)CDT; ! 158: else if(!strnicmp(p,"EDT",3)) ! 159: when.zone=(short)EDT; ! 160: else if(!strnicmp(p,"PST",3)) ! 161: when.zone=(short)PST; ! 162: else if(!strnicmp(p,"MST",3)) ! 163: when.zone=(short)MST; ! 164: else if(!strnicmp(p,"CST",3)) ! 165: when.zone=(short)CST; ! 166: else if(!strnicmp(p,"EST",3)) ! 167: when.zone=(short)EST; ! 168: } ! 169: ! 170: tm.tm_isdst=-1; /* Don't adjust for daylight-savings-time */ ! 171: when.time=mktime(&tm); ! 172: ! 173: return(when); ! 174: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.