Esempio n. 1
0
void setTimeValue( char *searchDir )
{
	void setFileTime( char *, time_t * ) ;
	
	time_t *newOldTime, *newOlderTime, *newOldestTime, *newExactTime ;
		
	char olderTime[]  = "01:00:00 2002/01/01" ;
	char oldestTime[] = "01:00:00 2001/01/01" ;
	char exactTime[] = "01:00:01 2002/01/01" ;
	char testFile[BUFFER_SIZE] = { '\0' } ;  
  	  	
	newOldTime = ( time_t * ) malloc( sizeof( time_t ) ) ;	
	newOlderTime = ( time_t * ) malloc( sizeof( time_t ) ) ; 
	newOldestTime = ( time_t * ) malloc( sizeof( time_t ) ) ;
	newExactTime = ( time_t * ) malloc( sizeof( time_t ) ) ;
	
  	*newOldTime = time( NULL ) ;
	*newOlderTime = parsedate( olderTime, NULL ) ;
	*newOldestTime = parsedate( oldestTime, NULL ) ;
	*newExactTime = parsedate( exactTime, NULL ) ;

	_debug( __FILE__, __LINE__, 5, "newOldTime is %s", ctime( newOldTime ) ) ;
	_debug( __FILE__, __LINE__, 5, "newOlderTime is %s", ctime( newOlderTime ) ) ;
	_debug( __FILE__, __LINE__, 5, "newOldestTime is %s", ctime( newOldestTime ) ) ;
	_debug( __FILE__, __LINE__, 5, "newExactTime is %s", ctime( newExactTime ) ) ;

	sprintf( testFile, "%s/%s", searchDir, "testTIME.txt" ) ;
	setFileTime( testFile, newExactTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testID1.c" ) ;
	setFileTime( testFile, newOldestTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testDATE1.c" ) ;
	setFileTime( testFile, newOldestTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testNAME1.c" ) ;
	setFileTime( testFile, newOldestTime ) ;	
	
	sprintf( testFile, "%s/%s", searchDir, "testID2.c" ) ;
	setFileTime( testFile, newOlderTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testDATE2.c" ) ;
	setFileTime( testFile, newOlderTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testNAME2.c" ) ;
	setFileTime( testFile, newOlderTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testID3.c" ) ;
	setFileTime( testFile, newOldTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testDATE3.c" ) ;
	setFileTime( testFile, newOldTime ) ;
	
	sprintf( testFile, "%s/%s", searchDir, "testNAME3.c" ) ;
	setFileTime( testFile, newOldTime ) ;
}
Esempio n. 2
0
/*
 * Return date of message in UNIX format (secs after the epoch)
 *
 * Understood formats: see FTS-0001 (actually using getdate.y parser)
 */
time_t pkt_get_date(FILE *fp)
{
    /*
     * Allow some characters more in the date string.
     */
    char buf[MSG_MAXDATE + 10];
    int len;

    /*
     * Treat FTN date as a 0-terminated string. Actually it's a fixed
     * string with exactly 19 chars + 0-char.
     */
    buf[0] = 0;
    if((len = pkt_get_string(fp, buf, sizeof(buf))) == ERROR)
	return ERROR;
    if( len != MSG_MAXDATE)
    {
	fglog("ERROR: wrong date size in message header (%d bytes instead %d)", len,
	      MSG_MAXDATE);
	return ERROR;
    }
    // first date format - FTS         `20 Dec 02  14:26:03'
    // second date dormat - nostandart `Thu 12 Dec 02 18:19'
    if( !( (buf[2]==' ' && buf[6]==' ' && buf[9]== ' ' && buf[10]==' ' &&
	    buf[13] == ':' && buf[16] == ':') ||
	   (buf[3]==' ' && buf[6]==' ' && buf[10]==' ' && buf[13]==' ' &&
	    buf[16] == ':') ) )
    {
	fglog("WARNING: wrong or corrupted format message date header \'%s\'", buf);
    }
    
    return parsedate(buf, NULL);

}
Esempio n. 3
0
/*
 * set_tstamp()
 *	Use a specific timestamp for all individual files created in the
 *	archive
 */
static int
set_tstamp(const char *b, struct stat *st)
{
	time_t when;
	char *eb;
	long long l;

	if (stat(b, st) != -1)
		return 0;

#ifndef HAVE_NBTOOL_CONFIG_H
	errno = 0;
	if ((when = parsedate(b, NULL, NULL)) == -1 && errno != 0)
#endif
	{
		errno = 0;
		l = strtoll(b, &eb, 0);
		if (b == eb || *eb || errno)
			return -1;
		when = (time_t)l;
	}

	st->st_ino = 1;
#if HAVE_STRUCT_STAT_BIRTHTIME 
	st->st_birthtime =
#endif
	st->st_mtime = st->st_ctime = st->st_atime = when;
	return 0;
}
Esempio n. 4
0
static void
stime_arg0(char *arg, struct timeval *tvp)
{
	tvp[1].tv_sec = tvp[0].tv_sec = parsedate(arg, NULL, NULL);
	if (tvp[0].tv_sec == -1)
		errx(EXIT_FAILURE, "Could not parse `%s'", arg);
	tvp[0].tv_usec = tvp[1].tv_usec = 0;
}
Esempio n. 5
0
int calcdaysago(const char *olddate) {
	time_t ago;
	double secs;
	int days;

	ago = parsedate(olddate, -1);
	secs = difftime(time(NULL), ago);
	days = int(secs/(60*60*24));
	return days;
}
Esempio n. 6
0
int cmd_date(char *rest)
{
  char s[40];

  if (!rest || !*rest)
  {
    struct dosdate_t d;

    _dos_getdate(&d);

    displayString(TEXT_MSG_CURRENT_DATE,
                   day_strings[d.dayofweek], d.month, d.day, d.year);

    rest = NULL;
  }

  while (1)                     /*forever loop */

  {
    if (!rest)
    {
      if ((rest = getMessage(TEXT_MSG_ENTER_DATE)) == NULL)
        return 1;               /* failed, error message on screan already */

      fputs(rest, stdout);      /* put onto screen */
      free(rest);
      fgets(s, sizeof(s), stdin);
      if (cbreak)
        return 1;
      if (parsedate(s))
        return 0;
    }
    else
    {
      if (parsedate(rest))
        return 0;
    }
    displayString(TEXT_ERROR_INVALID_DATE);
    // force input the next time around.
    rest = NULL;
  }
}
Esempio n. 7
0
main()
{
	char ptr1[256],*ptr=ptr1;
	time_t ti;

	fgets(ptr,255,stdin);
	if (!strncmp("Date: ",ptr,6))
		ptr+=6;
	ti = parsedate(ptr,0);
	printf("%s\n",ctime(&ti));
}
Esempio n. 8
0
Face*
nextface(void)
{
	int i;
	Face *f;
	Plumbmsg *m;
	char *t, *senderp, *showmailp, *digestp;
	ulong xtime;

	f = emalloc(sizeof(Face));
	for(;;){
		if(seefd >= 0){
			m = plumbrecv(seefd);
			if(m == nil)
				killall("error on seemail plumb port");
			t = value(m->attr, "mailtype", "");
			if(strcmp(t, "delete") == 0)
				delete(m->data, value(m->attr, "digest", nil));
			else if(strcmp(t, "new") != 0)
				fprint(2, "faces: unknown plumb message type %s\n", t);
			else for(i=0; i<nmaildirs; i++)
				if(strncmp(m->data, maildirs[i], strlen(maildirs[i])) == 0)
					goto Found;
			plumbfree(m);
			continue;

		Found:
			xtime = parsedate(value(m->attr, "date", date));
			digestp = value(m->attr, "digest", nil);
			if(alreadyseen(digestp)){
				/* duplicate upas/fs can send duplicate messages */
				plumbfree(m);
				continue;
			}
			senderp = estrdup(value(m->attr, "sender", "???"));
			showmailp = estrdup(m->data);
			if(digestp)
				digestp = estrdup(digestp);
			plumbfree(m);
		}else{
			if(logrecv(&senderp, &xtime) <= 0)
				killall("error reading log file");
			showmailp = estrdup("");
			digestp = nil;
		}
		setname(f, senderp);
		f->time = xtime;
		f->tm = *localtime(xtime);
		f->str[Sshow] = showmailp;
		f->str[Sdigest] = digestp;
		return f;
	}
}
Esempio n. 9
0
Face*
dirface(char *dir, char *num)
{
	Face *f;
	char *from, *date;
	char buf[1024], pwd[1024], *info, *p, *digest;
	int n, fd;
	ulong len;

	/*
	 * loadmbox leaves us in maildir, so we needn't
	 * walk /mail/fs/mbox for each face; this makes startup
	 * a fair bit quicker.
	 */
	if(getwd(pwd, sizeof pwd) != nil && strcmp(pwd, dir) == 0)
		sprint(buf, "%s/info", num);
	else
		sprint(buf, "%s/%s/info", dir, num);
	len = dirlen(buf);
	if(len <= 0)
		return nil;
	fd = open(buf, OREAD);
	if(fd < 0)
		return nil;
	info = emalloc(len+1);
	n = readn(fd, info, len);
	close(fd);
	if(n < 0){
		free(info);
		return nil;
	}
	info[n] = '\0';
	f = emalloc(sizeof(Face));
	from = iline(info, &p);	/* from */
	iline(p, &p);	/* to */
	iline(p, &p);	/* cc */
	iline(p, &p);	/* replyto */
	date = iline(p, &p);	/* date */
	setname(f, estrdup(from));
	f->time = parsedate(date);
	f->tm = *localtime(f->time);
	sprint(buf, "%s/%s", dir, num);
	f->str[Sshow] = estrdup(buf);
	iline(p, &p);	/* subject */
	iline(p, &p);	/* mime content type */
	iline(p, &p);	/* mime disposition */
	iline(p, &p);	/* filename */
	digest = iline(p, &p);	/* digest */
	f->str[Sdigest] = estrdup(digest);
	free(info);
	return f;
}
Esempio n. 10
0
time_t parse_date(const char *p)
{
  time_t parsed;
  int rc = parsedate(p, &parsed);

  switch(rc) {
  case PARSEDATE_OK:
  case PARSEDATE_LATER:
  case PARSEDATE_SOONER:
    return parsed;
  }
  /* everything else is fail */
  return -1;
}
Esempio n. 11
0
daterange::daterange(const std::string& fmt)
{
  int ptr;
  std::string startstr,endstr;

  ptr=fmt.find(' ');
  
  if (ptr)
    {
      startstr=fmt.substr(0,ptr);
      endstr=fmt.substr(ptr+1);

      this->start=parsedate(startstr);
      this->end=parsedate(endstr,1);
      this->seconds=(end-start)+1;
    }
  else
    {
      this->start=parsedate(fmt);
      this->end=parsedate(fmt,1);
      this->seconds=(end-start)+1;
    }
}
Esempio n. 12
0
time_t curl_getdate(const char *p, const time_t *now)
{
  time_t parsed = -1;
  int rc = parsedate(p, &parsed);
  (void)now; /* legacy argument from the past that we ignore */

  if(rc == PARSEDATE_OK) {
    if(parsed == -1)
      /* avoid returning -1 for a working scenario */
      parsed++;
    return parsed;
  }
  /* everything else is fail */
  return -1;
}
time_t curl_getdate(const char *p, const time_t *now)
{
  time_t parsed;
  int rc = parsedate(p, &parsed);
  (void)now; /* legacy argument from the past that we ignore */

  switch(rc) {
  case PARSEDATE_OK:
  case PARSEDATE_LATER:
  case PARSEDATE_SOONER:
    return parsed;
  }
  /* everything else is fail */
  return -1;
}
Esempio n. 14
0
/*
** getpdate() get a date for reading from
*/
static int getpdate()
{
    label adate;
    long parsedate();

    if (dPass) 
    {
        mPrintf("%s when? ", (dPass==dAFTER)?"After":"Before");
        getNormStr("", adate, NAMESIZE, YES);
        if ((dDate = parsedate(adate)) == ERROR) 
        {
            mPrintf("bad date\n ");
            return NO;
        }
    }
    return TRUE;
}
Esempio n. 15
0
int
main(int ac, char **av)
{
    time_t t;
    int i = 1;

    LoadDiabloConfig(ac, av);

    while (i < ac) {
	char *p = av[i];
	if (*p == '-') {
	    p++;
	    i++;
	    switch (*p++) {
		case 'c':
			t = strtol(*p ? p : av[i++], NULL, 0);
			if (t != 0)
			    printf("%s", ctime(&t));
			else
			    printf("Bad time specification\n");
			exit(0);
		case 'g':
			t = strtol(*p ? p : av[i++], NULL, 0) * 60;
			if (t != 0)
			    printf("%s", ctime(&t));
			else
			    printf("Bad time specification\n");
			exit(0);
		default:
			Usage(av[0]);
	    }
	} else {
	    break;
	}
    }
    if (ac == 1)
	Usage(av[0]);
    t = parsedate(av[ac - 1]);
    if (t == (time_t)-1)
	printf("Illegal format\n");
    else
	printf("%s", ctime(&t));
    return(0);
}
Esempio n. 16
0
int
getlog(FILE * f, struct log_entry *log)
{
	char   *p, *p2;
	char    buf[64 * 1024];
	time_t  timestamp;
	static time_t basetime = 0;

	if (fgets(buf, (64 * 1024) - 1, f) == NULL) {
		return (-1);
	}
	p = strchr(buf, ' ');
	assert(p);

	*p = 0x00;
	log->IP = strdup(buf);
	p++;

	p = strchr(p, '[');
	assert(p);
	p++;
	p2 = strchr(p, ']');
	assert(p2);
	*p2 = NULL;

	timestamp = parsedate(p);
	assert(timestamp > 0);
	if (basetime == 0)
		basetime = timestamp;

	log->timeoffset = (timestamp - basetime);

	p = strchr(p2 + 1, '"');
	assert(p);
	p++;
	p2 = strchr(p, '"');
	assert(p2);
	*p2 = NULL;

	log->request = strdup(p);

	return (0);
}
Esempio n. 17
0
bool updater_impl::parser_http_last_modified(const std::string& str, struct tm* time)
{
   std::string date;
   time_t t;

   std::size_t pos = str.find(':');
   if (pos != std::string::npos)
      date = str.substr(pos + 1, str.length() - pos);
   else
      date = str;
   if (parsedate(date.c_str(), &t) != PARSEDATE_OK)
      return false;
   struct tm* tm = localtime(&t);
   if (!tm)
      return false;
   *time = *tm;

   return true;
}
Esempio n. 18
0
// -1 Kill
//  0 Ignore
//  1 Ok.
signed char FastTraxWindow :: GetTime( const char * str, time_t now, time_t *t  )
{
	*t = parsedate( str, now ) ;
	if( *t != -1 )
		return 1;
	
	char buffer[512] ;
	sprintf( buffer, "Cannot parse date \"%s\"", str ) ;
	BAlert * alert = new BAlert(
		"Error" , buffer, "Ignore Error" , "Cancel Find",
		NULL, B_WIDTH_FROM_WIDEST, B_STOP_ALERT ) ;
	int32 button = alert->Go() ;
	if( button != 0 )
	{
		FindLibThread::UninitFind() ;
		return -1 ;
	}
	return 0 ;	
}
Esempio n. 19
0
static void
ee_hwupdate(const struct keytabent *ktent, char *arg)
{
    uint32_t hwtime;
    time_t t;
    char *cp, *cp2;

    if (arg) {
        if ((strcmp(arg, "now") == 0) ||
                (strcmp(arg, "today") == 0)) {
            if ((t = time(NULL)) == (time_t)(-1)) {
                warnx("can't get current time");
                ++eval;
                return;
            }
        } else if ((t = parsedate(arg, NULL, NULL)) == (time_t)(-1))
            BARF(ktent);
        hwtime = (uint32_t)t;	/* XXX 32 bit time_t on hardware */
        if (hwtime != t)
            warnx("time overflow");

        if (doio(ktent, (u_char *)&hwtime, sizeof(hwtime), IO_WRITE))
            FAILEDWRITE(ktent);
    } else {
        if (doio(ktent, (u_char *)&hwtime, sizeof(hwtime), IO_READ))
            FAILEDREAD(ktent);
        t = (time_t)hwtime;	/* XXX 32 bit time_t on hardware */
    }

    cp = ctime(&t);
    if (cp != NULL && (cp2 = strrchr(cp, '\n')) != NULL)
        *cp2 = '\0';

    printf("%s=%" PRId64, ktent->kt_keyword, (int64_t)t);
    if (cp != NULL)
        printf(" (%s)", cp);
    printf("\n");
}
Esempio n. 20
0
ftnmsg *mkftnhdr(rfcmsg *msg, int newsmode, faddr *recipient)
{
    char	    *freename = NULL, *rfcfrom = NULL, *p, *q, *l, *r;
    char	    *fbuf = NULL, *ftnfrom=NULL;
    static ftnmsg   *tmsg;
    int		    needreplyaddr = 1;
    faddr	    *tmp, *tmp2;

    tmsg=(ftnmsg *)malloc(sizeof(ftnmsg));
    memset(tmsg, 0, sizeof(ftnmsg));

    if (newsmode) {
	p = xstrcpy(hdr((char *)"Comment-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-Comment-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-FTN-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-Fidonet-Comment-To",msg));
	if (p == NULL) 
	    p = xstrcpy(hdr((char *)"X-Apparently-To",msg));
	if (p == NULL)
	    p = xstrcpy(hdr((char *)"To", msg));  /* 14-Aug-2001 MB */
	if (p) {
	    Syslog('m', "Getting `to' address from \"%s\"", MBSE_SS(p));

	    if ((tmsg->to = parsefaddr(p)) == NULL)
		tmsg->to = parsefaddr((char *)"[email protected]");
	    if ((l = strrchr(p,'<')) && (r = strchr(p,'>')) && (l < r)) {
		r = l;
		*r-- = '\0';
		if ((l = strchr(p,'"')) && (r = strrchr(p,'"')) && (l < r)) {
		    l++;
		    *r-- = '\0';
		}
		while (isspace(*r)) 
		    *r-- = '\0';
		if (!l) 
		    l = p;
		while (isspace(*l)) 
		    l++;
	    } else if ((l = strrchr(p,'(')) && (r = strchr(p,')')) && (l < r)) {
		*r-- = '\0';
		while (isspace(*r)) 
		    *r-- = '\0';
		l++;
		while (isspace(*l)) 
		    l++;
	    } else {
		l = p;
		while (isspace(*l)) 
		    l++;
		r = p + strlen(p) -1;
		if (*r == '\n') 
		    *r-- = '\0';
		while (isspace(*r)) 
		    *r-- = '\0';
	    }

	    if (*l) {
		if (strlen(l) > MAXNAME)
		    l[MAXNAME]='\0';
		free(tmsg->to->name);
		tmsg->to->name=xstrcpy(l);
	    }
	    free(p);
	    /*
	     *  It will become echomail, the destination FTN address must
	     *  be our address.  14-Aug-2001 MB.
	     */
	    tmsg->to->zone   = msgs.Aka.zone;
	    tmsg->to->net    = msgs.Aka.net;
	    tmsg->to->node   = msgs.Aka.node;
	    tmsg->to->point  = msgs.Aka.point;
	    tmsg->to->domain = xstrcpy(msgs.Aka.domain);
	} else {
	    /*
	     *  Filling a default To: address.
	     */
	    tmsg->to = (faddr*)malloc(sizeof(faddr));
	    tmsg->to->name   = xstrcpy((char *)"All");
	    tmsg->to->zone   = msgs.Aka.zone;
	    tmsg->to->net    = msgs.Aka.net;
	    tmsg->to->node   = msgs.Aka.node;
	    tmsg->to->point  = msgs.Aka.point;
	    tmsg->to->domain = xstrcpy(msgs.Aka.domain);
	}
    } else {
	if (recipient) {
	    /*
	     *  In mbmail mode the recipient is valid and must be used 
	     *  as the destination address. The To: field is probably
	     *  an RFC address an cannot be used to route the message.
	     */
	    tmsg->to = (faddr *)malloc(sizeof(faddr));
	    tmsg->to->point = recipient->point;
	    tmsg->to->node  = recipient->node;
	    tmsg->to->net   = recipient->net;
	    tmsg->to->zone  = recipient->zone;
	    tmsg->to->name  = xstrcpy(recipient->name);
	    if (tmsg->to->name && (strlen(tmsg->to->name) > MAXNAME))
		tmsg->to->name[MAXNAME]='\0';
	    tmsg->to->domain = xstrcpy(recipient->domain);
	    Syslog('m', "Recipient TO: %s", ascfnode(tmsg->to,0xff));
	} else {
	    p = xstrcpy(hdr((char *)"To",msg));
	    if (p == NULL)
		p = xstrcpy(hdr((char *)"X-Apparently-To",msg));
	    if (p) {
		if ((tmsg->to = parsefaddr(p)) == NULL)
		    WriteError("Unparsable destination address");
		else
		    Syslog('m', "RFC parsed TO: %s",ascfnode(tmsg->to,0xff));
	    }
	}
    } /* else (newsmode) */

    p = fbuf = xstrcpy(hdr((char *)"Reply-To", msg));
    if (fbuf == NULL) 
	p = fbuf = xstrcpy(hdr((char *)"From", msg));
    if (fbuf == NULL) 
	p = fbuf = xstrcpy(hdr((char *)"X-UUCP-From", msg));
    if (p) {
	q = p;
	while (isspace(*q)) 
	    q++;
	fbuf = parserfcaddr(q).remainder;
	if (parserfcaddr(q).target) {
	    fbuf = xstrcat(fbuf, (char *)"@");
	    fbuf = xstrcat(fbuf, parserfcaddr(q).target);
	}	
	rfcfrom = fbuf;
    }
    if (p)
	free(p);
    p = NULL;
    if (!rfcfrom) 
	rfcfrom = xstrcpy((char *)"postmaster");
    p = fbuf = xstrcpy(hdr((char *)"From", msg));
    if (fbuf == NULL) 
	p = fbuf = xstrcpy(hdr((char *)"X-UUCP-From", msg));
    if (p) {
	q = p;
	while (isspace(*q)) 
	    q++;
        if ((q) && (*q !=  '\0'))
            freename = parserfcaddr(q).comment;
        else 
	    freename = NULL;
    } else 
	freename = xstrcpy((char *)"Unidentified User");
    if (freename) {
	while (isspace(*freename)) 
	    freename++;
    }

    if (rfcfrom) {
	while (isspace(*rfcfrom)) 
	    rfcfrom++;
	p = rfcfrom + strlen(rfcfrom) -1;
	while ((isspace(*p)) || (*p == '\n')) 
	    *(p--)='\0';
    }

    if ((freename) && (*freename != '\0')) {
	while (isspace(*freename)) 
	    freename++;
	p = freename + strlen(freename) -1;
	while ((isspace(*p)) || (*p == '\n')) 
	    *(p--)='\0';
	if ((*freename == '\"') && (*(p=freename+strlen(freename)-1) == '\"')) {
	    freename++;
	    *p='\0';
	}
    }
    // if (*freename == '\0') freename=rfcfrom;
    if ((!freename) || ((freename) && (*freename == '\0')) || (strcmp(freename,".")==0)) 
	freename=rfcfrom;

    if (! newsmode)
	Syslog('+', "from: %s <%s>",freename,rfcfrom);

    needreplyaddr = 1;
    if ((tmsg->from=parsefaddr(rfcfrom)) == NULL) {
	if (freename && rfcfrom)
	    if (!strchr(freename,'@') && !strchr(freename,'%') && 
			    strncasecmp(freename,rfcfrom,MAXNAME) &&
			    strncasecmp(freename,"uucp",4) &&
			    strncasecmp(freename,"usenet",6) &&
			    strncasecmp(freename,"news",4) &&
			    strncasecmp(freename,"super",5) &&
			    strncasecmp(freename,"admin",5) &&
			    strncasecmp(freename,"postmaster",10) &&
			    strncasecmp(freename,"sys",3)) 
		needreplyaddr=registrate(freename,rfcfrom);
    } else {
	tmsg->ftnorigin = 1;
	tmsg->from->name = xstrcpy(freename);
	if (strlen(tmsg->from->name) > MAXNAME)
	    tmsg->from->name[MAXNAME]='\0';
    }
    if (replyaddr) {
	free(replyaddr);
	replyaddr=NULL;
    }
    if (needreplyaddr && (tmsg->from == NULL)) {
	replyaddr=xstrcpy(rfcfrom);
    }

    if (tmsg->from)
	Syslog('m', "From address was%s distinguished as ftn", tmsg->from ? "" : " not");

    if (newsmode) {
	tmp2 = fido2faddr(msgs.Aka);
	bestaka = bestaka_s(tmp2);
	tidy_faddr(tmp2);
    } else
	bestaka = bestaka_s(tmsg->to);

    if ((tmsg->from == NULL) && (bestaka)) {
	if (CFG.dontregate) {
	    p = xstrcpy(hdr((char *)"X-FTN-Sender",msg));
	    if (p == NULL) {
		if ((p = hdr((char *)"X-FTN-From",msg))) {
		    tmp = parsefnode(p);
		    p = xstrcpy(ascinode(tmp, 0xff));
		    tidy_faddr(tmp);
		}
	    }
	    if (p) {
	        q = p;
		while (isspace(*q)) 
		    q++;
		ftnfrom = parserfcaddr(q).remainder;
		if (parserfcaddr(q).target) {
		    ftnfrom = xstrcat(ftnfrom,(char *)"@");
		    ftnfrom = xstrcat(ftnfrom,parserfcaddr(q).target);
		}	
		Syslog('m', "Ftn gateway: \"%s\"", ftnfrom);
		Syslog('+', "Ftn sender: %s",ftnfrom);
		if (ftnfrom) 
		    tmsg->from = parsefaddr(ftnfrom);
		if ((tmsg->from) && (!tmsg->from->name))
		    tmsg->from->name = xstrcpy(rfcfrom);
	    }
	    if (p)
		free(p);
	    p = NULL;
	    if (tmsg->from == NULL) {
		tmsg->from=(faddr *)malloc(sizeof(faddr));
		tmsg->from->name=xstrcpy(freename);
		if (tmsg->from->name && (strlen(tmsg->from->name) > MAXNAME))
		    tmsg->from->name[MAXNAME]='\0';
		tmsg->from->point=bestaka->point;
		tmsg->from->node=bestaka->node;
		tmsg->from->net=bestaka->net;
		tmsg->from->zone=bestaka->zone;
		tmsg->from->domain=xstrcpy(bestaka->domain);
	    }
	} else {
	    tmsg->from=(faddr *)xmalloc(sizeof(faddr));
	    tmsg->from->name=xstrcpy(freename);
	    if (tmsg->from->name && (strlen(tmsg->from->name) > MAXNAME))
		tmsg->from->name[MAXNAME]='\0';
	    tmsg->from->point=bestaka->point;
	    tmsg->from->node=bestaka->node;
	    tmsg->from->net=bestaka->net;
	    tmsg->from->zone=bestaka->zone;
	    tmsg->from->domain=xstrcpy(bestaka->domain);
	}
    }
    if (fbuf) 
	free(fbuf); 
    fbuf = NULL;

    p = hdr((char *)"Subject", msg);
    if (p) {
	while (isspace(*p)) 
	    p++;
	tmsg->subj = xstrcpy(p);
	if (*(p=tmsg->subj+strlen(tmsg->subj)-1) == '\n') 
	    *p='\0';
	if (strlen(tmsg->subj) > MAXSUBJ) 
	    tmsg->subj[MAXSUBJ]='\0';
    } else {
	tmsg->subj = xstrcpy((char *)" ");
    }

    if ((p = hdr((char *)"X-FTN-FLAGS",msg))) 
	tmsg->flags |= flagset(p);
    if (hdr((char *)"Return-Receipt-To",msg)) 
	tmsg->flags |= M_RRQ;
    if (hdr((char *)"Notice-Requested-Upon-Delivery-To",msg)) 
	tmsg->flags |= M_RRQ;
    if (!newsmode) {
	tmsg->flags |= M_PVT;
	tmsg->flags |= M_KILLSENT;
    }

    if ((p = hdr((char *)"X-Origin-Date",msg))) 
	tmsg->date = parsedate(p, NULL) - (gmt_offset((time_t)0) * 60);
    else if ((p = hdr((char *)"Date",msg))) 
	tmsg->date = parsedate(p, NULL) - (gmt_offset((time_t)0) * 60);
    else 
	tmsg->date = time((time_t *)NULL);

    /*
     * SunMail 1.0 creates invalid date formats like: Wed, 19 Jun 2002 18:21:07 GMT-08:00
     *                                                                                ^---- not allowed.
     */
    if (tmsg->date == -1) {
	Syslog('!', "Parsing date \"%s\" failed, using current date", p);
	tmsg->date = time((time_t *)NULL);
    }
	
    if ((p = hdr((char *)"X-FTN-MSGID", msg))) {
	tmsg->ftnorigin &= 1;
	while (isspace(*p)) 
	    p++;
	tmsg->msgid_s = xstrcpy(p);
	if (*(p = tmsg->msgid_s + strlen(tmsg->msgid_s) -1) == '\n') 
	    *p='\0';
    } else if ((p = hdr((char *)".MSGID",msg))) {
	tmsg->ftnorigin &= 1;
	while (isspace(*p)) 
	    p++;
	tmsg->msgid_s = xstrcpy(p);
	if (*(p = tmsg->msgid_s + strlen(tmsg->msgid_s) -1) == '\n') 
	    *p='\0';
    } else if ((p = hdr((char *)"Message-ID",msg))) {
	tmsg->ftnorigin &= ftnmsgid(p,&(tmsg->msgid_a),&(tmsg->msgid_n),tmsg->area);
    } else
	tmsg->msgid_a = NULL;

    if ((p = hdr((char *)"X-FTN-REPLY",msg))) {
	while (isspace(*p)) 
	    p++;
	tmsg->reply_s = xstrcpy(p);
	if (*(p=tmsg->reply_s + strlen(tmsg->reply_s) -1) == '\n') 
	    *p='\0';
    } else {
	if (newsmode) {
	    p = hdr((char *)"References",msg);
	    if (p) {       
		l = xstrcpy(p);
		r = strtok(l," \t\n");
		while ((l=strtok(NULL," \t\n")) != NULL) 
		    r = l;
		p = r;
		free(l);
	    }
	} else
	    p = hdr((char *)"In-Reply-To",msg);
    }
    if (p)
	(void)ftnmsgid(p,&(tmsg->reply_a),&(tmsg->reply_n),NULL);
    else
	tmsg->reply_a=NULL;

    p = hdr((char *)"Organization",msg);
    if (p == NULL)
	p = hdr((char *)"Organisation",msg);
    if (p) {
	while (isspace(*p)) 
	    p++;
	tmsg->origin = xstrcpy(p);
	if (tmsg->origin)
	    if (*(p = tmsg->origin + strlen(tmsg->origin)-1) == '\n') 
		*p='\0';
    } else {
	/*
	 *  No Organization header, insert the default BBS origin.
	 */
	tmsg->origin = xstrcpy(CFG.origin);
    }

    return tmsg;
}
Esempio n. 21
0
bool
GenericAttributeText::CommitEditedTextFlavor(BTextView* textView)
{
	BNode node(fModel->EntryRef());

	if (node.InitCheck() != B_OK)
		return false;

	uint32 type = fColumn->AttrType();

	if (type != B_STRING_TYPE
		&& type != B_UINT64_TYPE
		&& type != B_UINT32_TYPE
		&& type != B_UINT16_TYPE
		&& type != B_UINT8_TYPE
		&& type != B_INT64_TYPE
		&& type != B_INT32_TYPE
		&& type != B_INT16_TYPE
		&& type != B_INT8_TYPE
		&& type != B_OFF_T_TYPE
		&& type != B_TIME_TYPE
		&& type != B_FLOAT_TYPE
		&& type != B_DOUBLE_TYPE
		&& type != B_CHAR_TYPE
		&& type != B_BOOL_TYPE) {
		BAlert* alert = new BAlert("",
			B_TRANSLATE("Sorry, you cannot edit that attribute."),
			B_TRANSLATE("Cancel"),
			0, 0, B_WIDTH_AS_USUAL, B_STOP_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go();
		return false;
	}

	const char* columnName = fColumn->AttrName();
	ssize_t size = 0;

	switch (type) {
		case B_STRING_TYPE:
			size = fModel->WriteAttr(columnName, type, 0, textView->Text(),
				(size_t)(textView->TextLength() + 1));
			break;

		case B_BOOL_TYPE:
		{
			bool value = strncasecmp(textView->Text(), "0", 1) != 0
				&& strncasecmp(textView->Text(), "off", 2) != 0
				&& strncasecmp(textView->Text(), "no", 3) != 0
				&& strncasecmp(textView->Text(), "false", 4) != 0
				&& strlen(textView->Text()) != 0;

			size = fModel->WriteAttr(columnName, type, 0, &value, sizeof(bool));
			break;
		}

		case B_CHAR_TYPE:
		{
			char ch;
			sscanf(textView->Text(), "%c", &ch);
			//Check if we read the start of a multi-byte glyph:
			if (!isprint(ch)) {
				BAlert* alert = new BAlert("",
					B_TRANSLATE("Sorry, the 'Character' "
					"attribute cannot store a multi-byte glyph."),
					B_TRANSLATE("Cancel"),
					0, 0, B_WIDTH_AS_USUAL, B_STOP_ALERT);
				alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
				alert->Go();
				return false;
			}

			size = fModel->WriteAttr(columnName, type, 0, &ch, sizeof(char));
			break;
		}

		case B_FLOAT_TYPE:
		{
			float floatVal;

			if (sscanf(textView->Text(), "%f", &floatVal) == 1) {
				fValueIsDefined = true;
				fValue.floatt = floatVal;
				size = fModel->WriteAttr(columnName, type, 0, &floatVal,
					sizeof(float));
			} else {
				// If the value was already defined, it's on disk.
				// Otherwise not.
				return fValueIsDefined;
			}
			break;
		}

		case B_DOUBLE_TYPE:
		{
			double doubleVal;

			if (sscanf(textView->Text(), "%lf", &doubleVal) == 1) {
				fValueIsDefined = true;
				fValue.doublet = doubleVal;
				size = fModel->WriteAttr(columnName, type, 0, &doubleVal,
					sizeof(double));
			} else {
				// If the value was already defined, it's on disk.
				// Otherwise not.
				return fValueIsDefined;
			}
			break;
		}

		case B_TIME_TYPE:
		case B_OFF_T_TYPE:
		case B_UINT64_TYPE:
		case B_UINT32_TYPE:
		case B_UINT16_TYPE:
		case B_UINT8_TYPE:
		case B_INT64_TYPE:
		case B_INT32_TYPE:
		case B_INT16_TYPE:
		case B_INT8_TYPE:
		{
			GenericValueStruct tmp;
			size_t scalarSize = 0;

			switch (type) {
				case B_TIME_TYPE:
					tmp.time_tt = parsedate(textView->Text(), time(0));
					scalarSize = sizeof(time_t);
					break;

				// do some size independent conversion on builtin types
				case B_OFF_T_TYPE:
					tmp.off_tt = StringToScalar(textView->Text());
					scalarSize = sizeof(off_t);
					break;

				case B_UINT64_TYPE:
				case B_INT64_TYPE:
					tmp.int64t = StringToScalar(textView->Text());
					scalarSize = sizeof(int64);
					break;

				case B_UINT32_TYPE:
				case B_INT32_TYPE:
					tmp.int32t = (int32)StringToScalar(textView->Text());
					scalarSize = sizeof(int32);
					break;

				case B_UINT16_TYPE:
				case B_INT16_TYPE:
					tmp.int16t = (int16)StringToScalar(textView->Text());
					scalarSize = sizeof(int16);
					break;

				case B_UINT8_TYPE:
				case B_INT8_TYPE:
					tmp.int8t = (int8)StringToScalar(textView->Text());
					scalarSize = sizeof(int8);
					break;

				default:
					TRESPASS();
			}

			size = fModel->WriteAttr(columnName, type, 0, &tmp, scalarSize);
			break;
		}
	}

	if (size < 0) {
		BAlert* alert = new BAlert("",
			B_TRANSLATE("There was an error writing the attribute."),
			B_TRANSLATE("Cancel"),
			0, 0, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go();

		fValueIsDefined = false;
		return false;
	}

	fValueIsDefined = true;
	return true;
}
Esempio n. 22
0
_EXPORT time_t ParseDateWithTimeZone (const char *DateString)
{
	time_t	currentTime;
	time_t	dateAsTime;
	char	tempDateString [80];
	char	tempZoneString [6];
	time_t	zoneDeltaTime;
	int		zoneIndex;
	char   *zonePntr;

	// See if we can remove the time zone portion.  parsedate understands time
	// zone 3 letter names, but doesn't understand the numeric +9999 time zone
	// format.  To do: see if a newer parsedate exists.

	strncpy (tempDateString, DateString, sizeof (tempDateString));
	tempDateString[sizeof (tempDateString) - 1] = 0;

	// Remove trailing spaces.
	zonePntr = tempDateString + strlen (tempDateString) - 1;
	while (zonePntr >= tempDateString && isspace (*zonePntr))
		*zonePntr-- = 0;
	if (zonePntr < tempDateString)
		return -1; // Empty string.

	// Remove the trailing time zone in round brackets, like in
	// Fri, 22 Feb 2002 15:22:42 EST (-0500)
	// Thu, 25 Apr 1996 11:44:19 -0400 (EDT)
	if (tempDateString[strlen(tempDateString)-1] == ')')
	{
		zonePntr = strrchr (tempDateString, '(');
		if (zonePntr != NULL)
		{
			*zonePntr-- = 0; // Zap the '(', then remove trailing spaces.
			while (zonePntr >= tempDateString && isspace (*zonePntr))
				*zonePntr-- = 0;
			if (zonePntr < tempDateString)
				return -1; // Empty string.
		}
	}
	
	// Look for a numeric time zone like  Tue, 30 Dec 2003 05:01:40 +0000
	for (zoneIndex = strlen (tempDateString); zoneIndex >= 0; zoneIndex--)
	{
		zonePntr = tempDateString + zoneIndex;
		if (zonePntr[0] == '+' || zonePntr[0] == '-')
		{
			if (zonePntr[1] >= '0' && zonePntr[1] <= '9' &&
				zonePntr[2] >= '0' && zonePntr[2] <= '9' &&
				zonePntr[3] >= '0' && zonePntr[3] <= '9' &&
				zonePntr[4] >= '0' && zonePntr[4] <= '9')
				break;
		}
	}
	if (zoneIndex >= 0)
	{
		// Remove the zone from the date string and any following time zone
		// letter codes.  Also put in GMT so that the date gets parsed as GMT.
		memcpy (tempZoneString, zonePntr, 5);
		tempZoneString [5] = 0;
		strcpy (zonePntr, "GMT");
	}
	else // No numeric time zone found.
		strcpy (tempZoneString, "+0000");

	time (&currentTime);
	dateAsTime = parsedate (tempDateString, currentTime);
	if (dateAsTime == (time_t) -1)
		return -1; // Failure.

	zoneDeltaTime = 60 * atol (tempZoneString + 3); // Get the last two digits - minutes.
	tempZoneString[3] = 0;
	zoneDeltaTime += atol (tempZoneString + 1) * 60 * 60; // Get the first two digits - hours.
	if (tempZoneString[0] == '+')
		zoneDeltaTime = 0 - zoneDeltaTime;
	dateAsTime += zoneDeltaTime;

	return dateAsTime;
}
Esempio n. 23
0
int getDate( const char *filename, const struct stat *statptr, int flag )
{
	void getFileTimeStamp( char * , char * ) ;

	char theFileName[BUFFER_SIZE] = { '\0' } ;
	char fileDate[20] = { '\0' } ;
	
	time_t fileDateTime ;
		
	switch ( flag )
	{
		case FTW_F : 	getFileTimeStamp( fileDate, ctime(  &statptr -> st_mtime  ) ) ;
				fileDateTime = parsedate( fileDate, NULL ) ;
				strcat( theFileName, "file://" ) ;
				
				if( strcmp( operatorType, "EQ" ) == 0 )
    				{	    											
					if( difftime( fileDateTime, fileQueryTime ) == 0 )
					{
						strcat( theFileName, filename ) ;
						dateResults = addResultItem( dateResults, theFileName ) ;
					}
				}
				else if( strcmp( operatorType, "LT" ) == 0 )
				{
					if( difftime( fileDateTime, fileQueryTime ) < 0 )
					{
						strcat( theFileName, filename ) ;
						dateResults = addResultItem( dateResults, theFileName ) ;
					}
				}
				else if( strcmp( operatorType, "LE" ) == 0 )
				{
					if( ( difftime( fileDateTime, fileQueryTime ) == 0 ) ||
					    ( difftime( fileDateTime, fileQueryTime ) < 0 ) )
					{
						strcat( theFileName, filename ) ;
						dateResults = addResultItem( dateResults, theFileName ) ;
					}
				}
				else if( strcmp( operatorType, "GT" ) == 0 )
				{
					if( difftime( fileDateTime, fileQueryTime ) > 0 )
					{
						strcat( theFileName, filename ) ;
						dateResults = addResultItem( dateResults, theFileName ) ;
					}
				}
				else if( strcmp( operatorType, "GE" ) == 0 )
				{
					if( ( difftime( fileDateTime, fileQueryTime ) == 0 ) ||
					    ( difftime( fileDateTime, fileQueryTime ) > 0 ) )
					{
						strcat( theFileName, filename ) ;
						dateResults = addResultItem( dateResults, theFileName ) ;
					}
				}
				break ;
	}
	return 0 ;
}
Esempio n. 24
0
/*
 * Check header permissions.
 * Does newsgroup checks if ReadPat is specified
 * Does Retention check if retention > 0
 */
static int check_headperm(char *msgid)
{
        char    *ng;
        time_t  msgdate;
        HLIST   *hdr = NULL, *allhdrs = NULL;
        char    header[MAX_HEADER];
        char    value[MAX_HEADER];
        char    *hval;
        CLEARBUF

        if ( cfg.LocalDreader == 1 && 
             strcmp(client->user->readpat, "all") == 0 && 
             client->profile->Retention == 0)
                return CHECK_ARTICLE_OK;

        if ( writeserver(client, "HEAD %s\r\n", msgid) == false ) 
                return CHECK_ARTICLE_FAIL;

        if ( (readserverline(client->bbuf, cfg.BufSize)) == NULL ) 
                return CHECK_ARTICLE_FAIL;

        if ( atoi(client->bbuf) > 399 )
                return CHECK_ARTICLE_FAIL;

        /* read headers from server */
        while( readserverline(client->bbuf, cfg.BufSize) != NULL ) 
        {
                if ((sscanf(client->bbuf, "%63[^\t ] %1023[^\r\n]", header, value)) == 0)
                        strncpy(value, client->bbuf, MAX_HEADER-1);

                hdr = insert_hlist(hdr, header, value);
                if ( allhdrs == NULL ) allhdrs = hdr;

                if ( header[0] == '.' )
                        break;
        }
        hdr = allhdrs;

        /* check retention time first */
        if ( client->profile->Retention > 0 )
        {
                msgdate = 0;

                if ( (hval=hlist_get_value(hdr, "NNTP-Posting-Date:")) != NULL )
                        msgdate = parsedate(hval);
                else
                if ( (hval=hlist_get_value(hdr, "Date:")) != NULL )
                        msgdate = parsedate(hval);

                if ( msgdate < (time(NULL) - (client->profile->Retention * 86400)) ) 
                {
                        free_hlist(hdr);
                        return CHECK_ARTICLE_NOPERM;
                }
        }

        /* check newsgroup permission */
        if ( (ng=hlist_get_value(hdr, "Newsgroups:")) != NULL )
        {
                free_hlist(hdr);
                /* now we've found the article and have the newsgroups header */
                if ( match_expression((unsigned char *)ng
                                        , (unsigned char *)getwildmat(client->user->readpat)
                                        , 0) ) 
                        return CHECK_ARTICLE_OK;
                else
                        return CHECK_ARTICLE_NOPERM;
        }

        /* If we reach this, the article wouldn't have a newsgroups header. */

        free_hlist(hdr);
        return CHECK_ARTICLE_FAIL;
}
Esempio n. 25
0
File: pop3.c Progetto: bbs-io/mbse
void retr_msg(int msgnum)
{
    char	    *p, *q, temp[PATH_MAX], *base;
    int		    Header;
    unsigned int    crc = -1;

    snprintf(temp, 81, "RETR %d\r\n", msgnum);
    if (pop3_cmd(temp) == 0) {
	Msg_New();
	Header = TRUE;
	snprintf(temp, PATH_MAX, "%s/%s/mailbox", CFG.bbs_usersdir, exitinfo.Name);
	base = xstrcpy(temp);
	Open_Msgbase(base, 'w');
	Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60);
	Msg.Private = TRUE;
	while (TRUE) {
	    p = pop3_receive();
	    if ((p[0] == '.') && (strlen(p) == 1)) {
		break;
	    } else {
		if (Header) {
		    /*
		     *  Check the primary message header lines.
		     */
		    if (strncmp(p, "To: ", 4) == 0) {
			if (strlen(p) > 104)
			    p[104] = '\0';
			snprintf(Msg.To, 101, "%s", p+4);
		    }
		    if (strncmp(p, "From: ", 6) == 0) {
		        if (strlen(p) > 106)
			    p[106] = '\0';
			snprintf(Msg.From, 101, "%s", p+6);
		    }
		    if (strncmp(p, "Subject: ", 9) == 0) {
			if (strlen(p) > 109)
			    p[109] = '\0';
			snprintf(Msg.Subject, 101, "%s", p+9);
			mbse_CleanSubject(Msg.Subject);
		    }
		    if (strncmp(p, "Date: ", 6) == 0)
			Msg.Written = parsedate(p+6, NULL) - (gmt_offset((time_t)0) * 60);
		    if (strncmp(p, "Message-Id: ", 12) == 0) {
			q = xstrcpy(p+12);
			Msg.MsgIdCRC = upd_crc32(q, crc, strlen(q));
			free(q);
		    }
		    Msg.ReplyCRC = 0xffffffff;
		    if (strlen(p) == 0) {
			Header = FALSE;
		    } else {
			snprintf(temp, PATH_MAX, "\001%s", p);
			MsgText_Add2(temp);
		    }
		} else {
		    MsgText_Add2(p);
		}
	    }
	}
	Msg_AddMsg();
	Msg_UnLock();
	Close_Msgbase(base);
	free(base);
	snprintf(temp, 81, "DELE %d\r\n", msgnum);
	pop3_cmd(temp);
    } else {
	WriteError("POP3: Can't retrieve message %d", msgnum);
    }
}
Esempio n. 26
0
/*
 * This function takes in the list of headers that were in the server's
 * response, it walks through the headers looking for a Retry-After response
 * header.  If one is found, the value is parsed and saved away in the EST
 * context.  This value can be in one of two formats, both are represented as
 * an ASCII string.  The first format can be a count of the number of seconds
 * the client should wait before retrying the request.  The second format is a
 * time/date stamp of the point in time at which the client should retry the
 * request.  The result of this function is the setting of the retry_after
 * values in the context.  If no retry-after header was received, or was
 * received and could not be parsed, the values will be zero, otherwise, they
 * are set to the value received.
 *
 * NOTE: The EST client currently does not support the time/date format
 * response and will not process a response in this format.
 */
static EST_ERROR est_io_parse_http_retry_after_resp (EST_CTX *ctx,
                                                     HTTP_HEADER *hdrs,
                                                     int hdr_cnt)
{
    EST_ERROR rv = EST_ERR_INVALID_RETRY_VALUE;
    int i;
    int cmp_result;
    int rc;
    long long int temp_ll;
    int found = 0;
    
    /*
     * Initialize assuming there was no retry-after header.
     */
    ctx->retry_after_delay = 0;
    ctx->retry_after_date = 0;
    
    for (i = 0; i < hdr_cnt; i++) {
        
        cmp_result = strncasecmp(hdrs[i].name, EST_HTTP_HDR_RETRY_AFTER, 
		sizeof(EST_HTTP_HDR_RETRY_AFTER));
        if (!cmp_result) {
            
            EST_LOG_INFO("Retry-After value = %s", hdrs[i].value);
            found = 1;
            /*
             * Determine whether or not the value is a date/time string
             * or is an integer representing the number of seconds
             * that the client must wait.
             */
            if (isalpha((int)*(hdrs[i].value))) {
#ifdef RETRY_AFTER_DELAY_TIME_SUPPORT
                int rc;
                /*
                 * Convert the date/time string into a time_t
                 */
                rc = parsedate(hdrs[i].value, &ctx->retry_after_date);
                if (rc != PARSEDATE_OK) {
                    EST_LOG_ERR("Retry-After value could not be parsed");
                }
#else
                /*
                 * This format is not currently supported.
                 */
                EST_LOG_ERR("Retry-After value not in the correct format");
#endif                
            } else {
                /*
                 * make sure it's all digits, make sure it's no larger than a
                 * four byte integer, and cache away the value returned for
                 * the retry delay.
                 */
                rc = strisdigit(hdrs[i].value, 10); // max of 10 decimal places
                if (rc) {
                    temp_ll = atoll(hdrs[i].value);
                    if (temp_ll <= INT_MAX) {
                        ctx->retry_after_delay = (int) temp_ll;
                        rv = EST_ERR_CA_ENROLL_RETRY;
                    } else {
                        EST_LOG_ERR("Retry-After value too large");
                    }
                    
                } else {
                    EST_LOG_ERR("Retry-After value could not be parsed");
                }
            }
        }
    }
    if (found == 0) {
        EST_LOG_ERR("Retry-After header missing");
    }    
    return rv;
}
Esempio n. 27
0
/* process cancel write */
int receive_article()
{
    char *user, *userptr;
    char *ngptr, *pathptr;
    char **splitptr;
    static char userid[32];
    static char xdate[32];
    static char xpath[180];
    time_t datevalue;
    newsfeeds_t *nf;
    char *boardhome;
    char hispaths[4096];
    char firstpath[MAXPATHLEN], *firstpathbase;
    char *lesssym, *nameptrleft, *nameptrright;
    static char sitebuf[80];

    if (FROM == NULL) {
        innbbsdlog(":Err: article without usrid %s\n", MSGID);
        return 0;
    }
    if (strchr(FROM, '<') && (FROM[strlen(FROM) - 1] == '>'))
        user = (char *) strrchr(FROM, '@');
    else
        user = (char *) strchr(FROM, '@');
    lesssym = (char *) strchr(FROM, '<');
    nameptrleft = NULL, nameptrright = NULL;
    if (lesssym == NULL || lesssym >= user) {
        lesssym = FROM;
        nameptrleft = strchr(FROM, '(');
        if (nameptrleft != NULL)
            nameptrleft++;
        nameptrright = strrchr(FROM, ')');
    } else {
        nameptrleft = FROM;
        nameptrright = strrchr(FROM, '<');
        lesssym++;
    }
    if (user != NULL) {
        *user = '******';
        userptr = (char *) strchr(FROM, '.');
        if (userptr != NULL) {
            *userptr = '\0';
            strncpy(userid, lesssym, sizeof userid);
            *userptr = '.';
        } else {
            strncpy(userid, lesssym, sizeof userid);
        }
        *user = '******';
    } else {
        strncpy(userid, lesssym, sizeof userid);
    }
    if (!isalnum(userid[0]))
        strcpy(userid, "Unknown");
    strcat(userid, ".");
    datevalue = parsedate(DATE, NULL);

    if (datevalue > 0) {
        char *p;

        strncpy(xdate, ctime(&datevalue), sizeof(xdate));
        p = (char *) strchr(xdate, '\n');
        if (p != NULL)
            *p = '\0';
        DATE = xdate;
    }
    if (SITE && strcasecmp("Computer Science & Information Engineering NCTU", SITE) == 0) {
        SITE = NCTUCSIETxt;
    } else if (SITE && strcasecmp("Dep. Computer Sci. & Information Eng., Chiao Tung Univ., Taiwan, R.O.C", SITE) == 0) {
        SITE = NCTUCSIETxt;
    } else if (SITE == NULL || *SITE == '\0') {
        if (nameptrleft != NULL && nameptrright != NULL) {
            char savech = *nameptrright;

            *nameptrright = '\0';
            strncpy(sitebuf, nameptrleft, sizeof sitebuf);
            *nameptrright = savech;
            SITE = sitebuf;
        } else
            /*
             * SITE = "(Unknown)"; 
             */
            SITE = "";
    }
    if (strlen(MYBBSID) > 70) {
        innbbsdlog(" :Err: your bbsid %s too long\n", MYBBSID);
        return 0;
    }
    sprintf(xpath, "%s!%.*s", MYBBSID, (int)(sizeof(xpath) - strlen(MYBBSID) - 2), PATH);
    PATH = xpath;
    for (pathptr = PATH; pathptr != NULL && (pathptr = strstr(pathptr, ".edu.tw")) != NULL;) {
        if (pathptr != NULL) {
            strcpy(pathptr, pathptr + 7);
        }
    }
    xpath[71] = '\0';

    echomaillog();
    *hispaths = '\0';
    splitptr = (char **) BNGsplit(GROUPS);
    firstpath[0] = '\0';
    firstpathbase = firstpath;
    /*
     * try to split newsgroups into separate group and check if any
     * duplicated
     */

    /*
     * try to use hardlink 
     */
    /*
     * for ( ngptr = GROUPS, nngptr = (char*) strchr(ngptr,','); ngptr !=
     * NULL && *ngptr != '\0'; nngptr = (char*)strchr(ngptr,',')) {
     */
    for (ngptr = *splitptr; ngptr != NULL; ngptr = *(++splitptr)) {
        char *boardptr, *nboardptr;

        /*
         * if (nngptr != NULL) { nngptr = '\0'; }
         */
        if (*ngptr == '\0')
            continue;
        nf = (newsfeeds_t *) search_group(ngptr);
        /*
         * printf("board %s\n",nf->board); 
         */
        if (nf == NULL) {
            innbbsdlog("unwanted \'%s\'\n", ngptr);
            /*
             * if( strstr( ngptr, "tw.bbs" ) != NULL ) { }
             */
            continue;
        }
        if (nf->board == NULL || !*nf->board)
            continue;
        if (nf->path == NULL || !*nf->path)
            continue;
        for (boardptr = nf->board, nboardptr = (char *) strchr(boardptr, ','); boardptr != NULL && *boardptr != '\0'; nboardptr = (char *) strchr(boardptr, ',')) {
            if (nboardptr != NULL) {
                *nboardptr = '\0';
            }
            if (*boardptr == '\t') {
                goto boardcont;
            }
            boardhome = (char *) fileglue("%s/boards/%s", BBSHOME, boardptr);
            if (!isdir(boardhome)) {
                innbbsdlog(":Err: unable to write %s\n", boardhome);
            } else {
                char *fname;

                /*
                 * if ( !isdir( boardhome )) { innbbsdlog( ":Err:
                 * unable to write %s\n",boardhome);
                 * testandmkdir(boardhome); }
                 */
                fname = (char *) post_article(boardhome, userid, boardptr, bbspost_write_post, NULL, firstpath);
                if (fname != NULL) {
                    fname = (char *) fileglue("%s/%s", boardptr, fname);
                    if (firstpath[0] == '\0') {
                        sprintf(firstpath, "%s/boards/%s", BBSHOME, fname);
                        firstpathbase = firstpath + strlen(BBSHOME) + strlen("/boards/");
                    }
                    if (strlen(fname) + strlen(hispaths) + 1 < sizeof(hispaths)) {
                        strcat(hispaths, fname);
                        strcat(hispaths, " ");
                    }
                } else {
                    innbbsdlog("fname is null %s\n", boardhome);
                    return -1;
                }
            }

          boardcont:
            if (nboardptr != NULL) {
                *nboardptr = ',';
                boardptr = nboardptr + 1;
            } else
                break;

        }                       /* for board1,board2,... */
        /*
         * if (nngptr != NULL) ngptr = nngptr + 1; else break;
         */
        if (*firstpathbase)
            feedfplog(nf, firstpathbase, 'P');
    }
    if (*hispaths)
        bbsfeedslog(hispaths, 'P');

    if (Junkhistory || *hispaths) {
        if (storeDB(HEADER[MID_H], hispaths) < 0) {
            innbbsdlog("store DB fail\n");
            /*
             * I suspect here will introduce duplicated articles 
             */
            /*
             * return -1; 
             */
        }
    }
    return 0;
}
Esempio n. 28
0
int32 Date::ParseDate(const char *date)
{
	if (date==NULL)
		return B_ERROR;
		time_t now = time(NULL);
		return parsedate(date,now);
//		printf("Date as received: %s\n",date);
	/*
		We need to handle folding whitespace as defined in RFC 2822, so lets take
		care of that first.
	*/
	int32 length=strlen(date);
	char *copy=new char[length+1];
	memset(copy,0,length+1);
	strcpy(copy,date);
	int32 fws_count=0;
	char *fws_p=NULL;
	fws_p=strstr(copy,"\r\n");
	while(fws_p!=NULL)
	{
		if (isspace(*(fws_p+2)))
		{
			fws_count++;
			memmove(fws_p,fws_p+2,strlen(fws_p+2)+1);//replace the fws with three spaces instead
		}
		fws_p=strstr(fws_p+2,"\r\n");
	}
//	printf("%ld instances of folding whitespace encountered\n",fws_count);
//	printf("modified copy of date string: %s\n",copy);
	/*
		We also need to handle comments as defined in RFC 2822.
	*/
	char *open_p=strchr(copy,'('),*close_p=NULL;
	int32 comment_count=0;
	while (open_p!=NULL)
	{
		close_p=strchr(open_p,')');
		if (close_p!=NULL)
		{
			comment_count++;
			int32 remainder=strlen(close_p+1);
			memmove(open_p,close_p+1,remainder+1);
		}
		open_p=strchr(open_p,'(');
	}
	/*
		Some date strings used in cookies have the nerve to have hyphens between
		the day, month, and year... The audacity! Convert them to space characters!
	*/
	char *hyphen=strchr(copy,'-');
	while (hyphen!=NULL)
	{
		*hyphen=0x20;
		hyphen=strchr(hyphen,'-');
	}
//	printf("%ld comments encountered\n",comment_count);
//	printf("modified copy of date string: %s\n",copy);
	/*
		Now proceed to analyze the date...
	*/
	char *start_p=copy,*comma=strchr(copy,',');
	//If we have a comma, that means there's a day of the week expression starting things off. Skip it.
	if (comma!=NULL)
		start_p=(comma+1);
	/*
		There are five key sections that will need to be isolated and analyzed:
		1	Day of the month.
		2	Month of the year.
		3	Year.
		4	Time of day.
		5	Time zone.
		So divide the string up into it's sections.
	*/
	char *sections[5]={NULL,NULL,NULL,NULL,NULL};
	int32 lengths[5]={0,0,0,0,0};
	int32 section_counter=0;
	for (;section_counter<5; )
	{
		if ((*start_p)==(char)NULL)
			break;
		if (isspace(*start_p))
		{
			start_p++;
			continue;
		}
		sections[section_counter]=start_p;
		while(!isspace(*start_p))
		{
			if ((*start_p)==(char)NULL)
				break;
			start_p++;
			lengths[section_counter]++;
		}
//		printf("section %d is %d bytes long\n",section_counter+1,lengths[section_counter]);
		section_counter++;
	}
//	char *sn[5]={"Day","Month","Year","Time","Time Zone"};
	char *value;
	/*
		Move the data into a time structure.
	*/
	struct tm tstruct;
	for (int i=0; i<5; i++)
	{
		value=new char[lengths[i]+1];
		memset(value,0,lengths[i]+1);
		strncpy(value,sections[i],lengths[i]);
//		printf("\t%s:\t%s\n",sn[i],value);
		switch(i)
		{
			case 0:
			{
				tstruct.tm_mday=atoi(value);
			}break;
			case 1:
			{
				if (strcasecmp(value,"jan")==0)
					tstruct.tm_mon=0;
				if (strcasecmp(value,"feb")==0)
					tstruct.tm_mon=1;
				if (strcasecmp(value,"mar")==0)
					tstruct.tm_mon=2;
				if (strcasecmp(value,"apr")==0)
					tstruct.tm_mon=3;
				if (strcasecmp(value,"may")==0)
					tstruct.tm_mon=4;
				if (strcasecmp(value,"jun")==0)
					tstruct.tm_mon=5;
				if (strcasecmp(value,"jul")==0)
					tstruct.tm_mon=6;
				if (strcasecmp(value,"aug")==0)
					tstruct.tm_mon=7;
				if (strcasecmp(value,"sep")==0)
					tstruct.tm_mon=8;
				if (strcasecmp(value,"oct")==0)
					tstruct.tm_mon=9;
				if (strcasecmp(value,"nov")==0)
					tstruct.tm_mon=10;
				if (strcasecmp(value,"dec")==0)
					tstruct.tm_mon=11;
			}break;
			case 2:
			{
				if (lengths[i]==4)
				{
					tstruct.tm_year=atol(value)-1900;
				} else
				{
				
					int16 year=atol(value);
					/*
						The following is more technically correct, but in truth
						it is no different than just doing tstruct.tm_year=atol(value)
						provided that the length of the year is less than 4 but greater
						than 0.
					*/
					if ((lengths[i]==2) && (year<50) && (year>=0))
						year+=2000;
					else
						if (((lengths[i]==2) && (year>=50) && (year<100)) || (lengths[i]==3))
							year+=1900;
					tstruct.tm_year=year-1900;
				}
			}break;
			case 3:
			{
				char *time_array[3];
				time_array[0]=strtok(value,":");
				time_array[1]=strtok(NULL,":");
				time_array[2]=strtok(NULL,":");
//				printf("Hour: %s\nMinute: %s\nSeconds: %s\n",time_array[0],time_array[1],time_array[2]);
				tstruct.tm_hour=atoi(time_array[0]);
				tstruct.tm_min=atoi(time_array[1]);
				if (time_array[2]!=NULL)
					tstruct.tm_sec=atoi(time_array[2]);
			}break;
			case 4:
			{
				/*
					Adjust the time in the structure based on the time zone information to
					get GMT time...
				*/
				if ((ispunct(value[0]) && (strpbrk(value,"-+")==value)) && (strlen(value)==5))
				{
//					printf("Numeric time zone!\n");
					bool positive=false;
					int32 minutes=0,hours=0, zone=0;
					if (value[0]=='+')
						positive=true;
					zone=atoi((value+1));
					hours=zone/100;
					minutes=zone%100;
					printf("This time is GMT %c %d hours %d minutes\n",value[0],hours,minutes);
					
					if (positive)
					{//if the time zone is positive, we need to subtract to get gmt
						tstruct.tm_gmtoff=-(3600*hours+60*minutes);
					} else
					{//if the time zone is negative, we need to add to get gmt
						tstruct.tm_gmtoff=(3600*hours+60*minutes);
					}
					
				} else
				{
//					printf("String time zone!\n");
					int32 offset=0,local_offset=0;
					time_t current_time=real_time_clock();
					struct tm *gmt=localtime(&current_time);
					if (gmt->tm_gmtoff<0)
						local_offset=-gmt->tm_gmtoff;
					else
						local_offset=gmt->tm_gmtoff;
					if (gmt->tm_isdst)
						local_offset+=3600;
//					printf("GMT offset of local machine: %d\n",gmt->tm_gmtoff);
					if ((strcasecmp("GMT",value)==0) || (strcasecmp("UT",value)==0))
					{//Then we need to find the GMT offset of the local machine
						printf("(GMT) local offset: %ld\toffset: %ld\n",local_offset,offset);
						local_offset-=3600;
					}
					/*
						Add more time zone strings and values as time and sanity permit.
					*/
					if (strcasecmp("edt",value)==0)//US Eastern Daylight Time
						offset=0x3840;
					if (strcasecmp("est",value)==0)//US Eastern Standard Time
						offset=0x4650;
					if (strcasecmp("cdt",value)==0)//US Central Daylight Time
						offset=0x4650;
					if (strcasecmp("cst",value)==0)//US Central Standard Time
						offset=0x5460;
					if (strcasecmp("mdt",value)==0)//US Mountain Daylight Time
						offset=0x5460;
					if (strcasecmp("mst",value)==0)//US Mountain Standard Time
						offset=0x6270;
					if (strcasecmp("pdt",value)==0)//US Pacific Daylight Time
						offset=0x6270;
					if (strcasecmp("pst",value)==0)//US Pacific Standard Time
						offset=0x7080;
//						printf("local offset: %d\nother offset: %d\n",local_offset,offset);
//					if (offset==0)
//						offset=local_offset;
					offset=local_offset-offset;
//					printf("difference: %d\n",offset);
						int32 hours=offset/3600, minutes=(offset%3600)/60;
						tstruct.tm_hour-=hours;
						tstruct.tm_min-=minutes;
					
				}
			}break;
		}
		memset(value,0,lengths[i]+1);
		delete value;	
	}
	time_t ttime=mktime(&tstruct);
	ttime=mktime(localtime(&ttime));
//	printf("ctime() (localtime): %s\n",ctime(&ttime));
	char dt[100];
	memset(dt,0,100);
	strftime(dt,99,"%a %B %d, %Y %H:%M:%S %Z",&tstruct);
	printf("strftime (localtime): %s (%s)\n",dt,asctime(&tstruct));
	memset(dt,0,100);
//	struct tm *gmt=gmtime(&ttime);
//	strftime(dt,99,"%a %B %d, %Y %H:%M:%S %Z",gmt);
//	printf("strftime (GMT): %s\n",dt);
	memset(copy,0,length+1);
	delete copy;
	return ttime;
}
Esempio n. 29
0
queryList* FSqueryTool( queryList *listpointer )
{
	void getDirectoryPath( ) ;
	void attributeDATE( ) ;
	void attributeNAME( ) ;
	resultList* attributeID( query *, int ) ;
	
   	char oneLine[BUFFER_SIZE] ;	// one line from the an opened file
   	char *word ;			// a token during string tokenization
   	int numClauses ;
   	queryList *tempQueries ;	// a pointer to the query list arguement
   	resultList *tempResults ;
   	   	
   	getDirectoryPath( ) ;
  	
	tempQueries = listpointer ;
	tempResults = NULL ;
	
	while( tempQueries != NULL )
	{
		for( numClauses = 0 ; numClauses <= tempQueries -> oneQuery -> numClauses ; numClauses++ )
		{
			if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses].attribute, "ID" ) == 0 )
			{
				if( numClauses == 0 )
					tempResults = attributeID( tempQueries -> oneQuery, numClauses ) ;
				else
				{
					if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "AND" ) == 0 )
						tempResults = andResult( tempResults, attributeID( tempQueries -> oneQuery, numClauses ) ) ;
			
					if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "OR" ) == 0 )
						tempResults = orResult(tempResults, attributeID( tempQueries -> oneQuery, numClauses ) ) ;
				}
			}
	
			if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses].attribute, "DATE" ) == 0 )
			{
				char fileTime[22] = { '\0' } ;
				dateResults = NULL;
				
				formatTimeStamp( fileTime, tempQueries -> oneQuery -> myClauses[numClauses].value ) ;
				fileQueryTime = parsedate( fileTime, NULL) ;	
				
				strcpy( operatorType, tempQueries -> oneQuery -> myClauses[numClauses].operator ) ;
				attributeDATE( ) ;
				if( numClauses == 0 )
					tempResults = dateResults ;
				else
				{
					if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "AND" ) == 0 )
						tempResults = andResult( tempResults, dateResults ) ;
	
					if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "OR" ) == 0 )
						tempResults = orResult( tempResults, dateResults ) ;
				}
			}

			if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses].attribute, "NAME" ) == 0 )
			{
				nameResults = NULL;
				strcpy( operatorType, tempQueries -> oneQuery -> myClauses[numClauses].operator ) ;
				strcpy( queryName, tempQueries -> oneQuery -> myClauses[numClauses].value ) ;
				attributeNAME( ) ;
				if( numClauses == 0 )
					tempResults = nameResults ;
				else
				{
					if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "AND" ) == 0 )
						tempResults = andResult( tempResults, nameResults ) ;
						
					if( strcmp( tempQueries -> oneQuery -> myClauses[numClauses-1].conjecture, "OR" ) == 0 )
						tempResults = orResult( tempResults, nameResults ) ;
				}
			}
			
		}
	
		while ( tempResults != NULL )
		{
			tempQueries -> oneQuery -> results = addResultItem( tempQueries -> oneQuery -> results, tempResults -> oneResult ) ;
			tempQueries -> oneQuery -> numFound++ ;
			tempResults = ( resultList* ) tempResults -> link ;
		}
		
		tempQueries = ( queryList* ) tempQueries -> link ;
	}
	return listpointer ;	
}
Esempio n. 30
0
int parseLine(char * line, int membuf, int lineno, const char * delim1, ivector & tvec, 
	       svector & delims, srivector & srv, ftvector & out, int grpsize) {
  int i, ival;
  int64 dival;
  qint qval;
  float fval;
  double dval;
  char * here, * next; 

  here = line;
  for (i = 0; i < tvec.size(); i++) {
    next = strpbrk(here, delim1);
    if (!next && i < tvec.size()-1) {
      cerr << "parseLine: format error line " << lineno << endl;
      cerr << "  contents: " << line << " ... " << here << endl;
      throw 10;
    }
    if (next && *next) *(next++) = 0;
    switch (tvec[i]) {
    case ftype_int:
      sscanf(here, "%d", &ival);
      out[i].iv.push_back(ival);
      break;
    case ftype_dint:
      sscanf(here, "%lld", &dival);
      out[i].div.push_back(dival);
      break;
    case ftype_qhex:
      sscanf(here, "%16llx%16llx", &qval.top, &qval.bottom);
      out[i].qv.push_back(qval);
      break;
    case ftype_float:
      sscanf(here, "%f", &fval);
      out[i].fv.push_back(fval);
      break;
    case ftype_double:
      sscanf(here, "%lf", &dval);
      out[i].dv.push_back(dval);
      break;
    case ftype_word:
      here += strspn(here, " ");
      out[i].iv.push_back(srv[i].checkword(here));
      break;
    case ftype_string:
      out[i].im.push_back(srv[i].checkstring(here, delims[i].c_str()));
      break;
    case ftype_dt:  
      ival = parsedt(here);
      if (ival < 0)
	printf("\nWarning: bad dt on line %d\n", lineno);
      out[i].iv.push_back(ival);
      break;
    case ftype_mdt:
      ival = parsemdt(here);
      if (ival < 0)
	printf("\nWarning: bad mdt on line %d\n", lineno);
      out[i].iv.push_back(ival);
      break;
    case ftype_date:
      ival = parsedate(here);
      if (ival < 0)
	printf("\nWarning: bad date on line %d\n", lineno);
      out[i].iv.push_back(ival);
      break;
    case ftype_mdate:
      ival = parsemdate(here);
      if (ival < 0)
	printf("\nWarning: bad mdate on line %d\n", lineno, here);
      out[i].iv.push_back(ival);
      break;
    case ftype_cmdate:
      ival = parsecmdate(here);
      if (ival < 0)
	printf("\nWarning: bad cmdate on line %d\n", lineno, here);
      out[i].iv.push_back(ival);
      break;
    case ftype_group:
      *(next-1) = *delim1;
      out[i].im.push_back(srv[i].checkstrings(&here, delim1, grpsize));
      next = here;
      break;
    case ftype_igroup:
      //      *(next-1) = *delim1;
      out[i].im.push_back(srv[i].checkgroup(&here, delims[i].c_str(), grpsize));
      next = here;
      break;
    case ftype_digroup:
      //      *(next-1) = *delim1;
      out[i].dim.push_back(srv[i].checkdgroup(&here, delims[i].c_str(), grpsize));
      next = here;
      break;
    default:
      break;
    }
    here = next;
  }
  return 0;
}