File: taspoolid.c

package info (click to toggle)
zmailer 2.99.55-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,516 kB
  • ctags: 9,694
  • sloc: ansic: 120,953; sh: 3,862; makefile: 3,166; perl: 2,695; python: 115; awk: 22
file content (56 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* taspoolid() -- build a spoolid into provided buffer
 *
 * Minimum spoolid space is about 17 chars!  Have at least 32 !
 * (8 for a timestamp, 8+1 for the i-node number and terminating null..)
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* These ARE NOT MIME BASE64 characters, but something by which it is
   fairly easily to MANUALLY decode the following result.. */
char taspid_encodechars[] =
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123abcdefghijklmnopqrstuvwxyz4567890-=";

void taspoolid(buf,mtime,inodenum)
char *buf;
time_t mtime;
long inodenum;
{
  char *s = buf;
  struct tm *tt;

  /* GMT time */
  tt = gmtime(&mtime);

  tt->tm_year += 1900;

  /* Start with a capital 'S' .. */
  *s++ = 'S';

  sprintf(s,"%ld", inodenum);
  s += strlen(s);

  /* Year in 'base64', sort of.. */
  *s++ = taspid_encodechars[(tt->tm_year >> 12) & 63];
  *s++ = taspid_encodechars[(tt->tm_year >>  6) & 63];
  *s++ = taspid_encodechars[(tt->tm_year      ) & 63];
  /* Month */
  *s++ = taspid_encodechars[tt->tm_mon];
  /* Day */
  *s++ = taspid_encodechars[tt->tm_mday-1];
  /* Hour */
  *s++ = taspid_encodechars[tt->tm_hour];
  /* Minutes */
  *s++ = taspid_encodechars[tt->tm_min];
  /* Seconds */
  *s++ = taspid_encodechars[tt->tm_sec];

  *s = 0; /* terminate zero */

  /* .. and finally attach the inode-number part of the spool file name. */

}