Exemple #1
0
long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data)
{
  struct stat sbuf;
  int fd = -1;
  int e;
  char tmp[MAILTMPLEN];
  MAILSTREAM *ts = default_proto (T);
  if (compare_cstring (mailbox,"INBOX") && dummy_file (tmp,mailbox) &&
      ((fd = open (tmp,O_RDONLY,NIL)) < 0)) {
    if ((e = errno) == ENOENT)	/* failed, was it no such file? */
      mm_notify (stream,"[TRYCREATE] Must create mailbox before append",
		 (long) NIL);
    sprintf (tmp,"%.80s: %.80s",strerror (e),mailbox);
    mm_log (tmp,ERROR);		/* pass up error */
    return NIL;			/* always fails */
  }
  if (fd >= 0) {		/* found file? */
    fstat (fd,&sbuf);		/* get its size */
    close (fd);			/* toss out the fd */
    if (sbuf.st_size) ts = NIL;	/* non-empty file? */
  }
  if (ts) return (*ts->dtb->append) (stream,mailbox,af,data);
  sprintf (tmp,"Indeterminate mailbox format: %.80s",mailbox);
  mm_log (tmp,ERROR);
  return NIL;
}
Exemple #2
0
char *tcp_name (struct sockaddr *sadr,long flag)
{
  char *ret,*t,adr[MAILTMPLEN],tmp[MAILTMPLEN];
  sprintf (ret = adr,"[%.80s]",ip_sockaddrtostring (sadr));
  if (allowreversedns) {
    blocknotify_t bn = (blocknotify_t)mail_parameters(NIL,GET_BLOCKNOTIFY,NIL);
    void *data;
    if (tcpdebug) {
      sprintf (tmp,"Reverse DNS resolution %s",adr);
      mm_log (tmp,TCPDEBUG);
    }
    (*bn) (BLOCK_DNSLOOKUP,NIL);/* quell alarms */
    data = (*bn) (BLOCK_SENSITIVE,NIL);
				/* translate address to name */
    if (t = tcp_name_valid (ip_sockaddrtoname (sadr))) {
				/* produce verbose form if needed */
      if (flag)	sprintf (ret = tmp,"%s %s",t,adr);
      else ret = t;
    }
    (*bn) (BLOCK_NONSENSITIVE,data);
    (*bn) (BLOCK_NONE,NIL);	/* alarms OK now */
    if (tcpdebug) mm_log ("Reverse DNS resolution done",TCPDEBUG);
  }
  return cpystr (ret);
}
static void place(void *ptr, size_t size)
{
    mm_log("placing at %p, size %d\n", ptr, (int)size);

    size_t free_size = GET_SIZE(HDRP(ptr));
    size_t rem = free_size - size;
    if (rem < DSIZE+WSIZE*2)
    {
        size = free_size;
    }

    /* Delete from the freelist */
    delete_free_block(ptr);

    PUT(HDRP(ptr), PACK(size, 1));
    PUT(FTRP(ptr), PACK(size, 1));

    mm_log("header = (%d,%d)\n", GET_SIZE(HDRP(ptr)), GET_ALLOC(HDRP(ptr)));
    mm_log("footer = (%d,%d)\n", GET_SIZE(FTRP(ptr)), GET_ALLOC(FTRP(ptr)));

    /* See if we should split */
    if (size != free_size)
    {
        void *split_pt = ptr + size;

        init_free_block(split_pt, free_size-size);
    }
}
Exemple #4
0
char *tcp_name (struct sockaddr_in *sin,long flag)
{
  char *ret,*t,adr[MAILTMPLEN],tmp[MAILTMPLEN];
  sprintf (ret = adr,"[%.80s]",inet_ntoa (sin->sin_addr));
  if (allowreversedns) {
    struct hostent *he;
    blocknotify_t bn = (blocknotify_t)mail_parameters(NIL,GET_BLOCKNOTIFY,NIL);
    void *data;
    if (tcpdebug) {
      sprintf (tmp,"Reverse DNS resolution %s",adr);
      mm_log (tmp,TCPDEBUG);
    }
    (*bn) (BLOCK_DNSLOOKUP,NIL);/* quell alarms */
    data = (*bn) (BLOCK_SENSITIVE,NIL);
				/* translate address to name */
    if (t = tcp_name_valid ((he = gethostbyaddr ((char *) &sin->sin_addr,
						 sizeof (struct in_addr),
						 sin->sin_family)) ?
			    (char *) he->h_name : NIL)) {
				/* produce verbose form if needed */
      if (flag)	sprintf (ret = tmp,"%s %s",t,adr);
      else ret = t;
    }
    (*bn) (BLOCK_NONSENSITIVE,data);
    (*bn) (BLOCK_NONE,NIL);	/* alarms OK now */
    if (tcpdebug) mm_log ("Reverse DNS resolution done",TCPDEBUG);
  }
  return cpystr (ret);
}
/* 
 * mm_malloc - Allocate a block by incrementing the brk pointer.
 *     Always allocate a block whose size is a multiple of the alignment.
 */
void *mm_malloc(size_t size)
{
    mm_log("\nmalloc(%d)\n\n", (int)size);

    ASSERT;
        
    char *bp;
    /* Ignore spurious requests */
    if (size == 0)
        return NULL;

    size_t asize = adjust_requested_block_size(size);
    
    /* Search the free list for a fit */
    bp = find_fit(asize);
    if (!bp)
    {
        mm_log("requesting more memory...\n");
        /* No fit found. Get more memory and place the block */
        size_t extendsize = MAX(asize,CHUNKSIZE);
        if ((bp = extend_heap(extendsize/WSIZE)) == NULL)
            return NULL;
    }
    
    place(bp, asize);
    
    return bp;
}
Exemple #6
0
static void
i_t1_set_aa(int st) {
  int i;
  unsigned long cst[17];

  mm_log((1, "i_t1_set_aa(%d)\n", st));

  if (t1_aa == st)
    return;

  switch(st) {
  case 0:
    T1_AASetBitsPerPixel( 8 );
    T1_AASetLevel( T1_AA_NONE );
    T1_AANSetGrayValues( 0, 255 );
    mm_log((1,"setting T1 antialias to none\n"));
    break;
  case 1:
    T1_AASetBitsPerPixel( 8 );
    T1_AASetLevel( T1_AA_LOW );
    T1_AASetGrayValues( 0,65,127,191,255 );
    mm_log((1,"setting T1 antialias to low\n"));
    break;
  case 2:
    T1_AASetBitsPerPixel(8);
    T1_AASetLevel(T1_AA_HIGH);
    for(i=0;i<17;i++) cst[i]=(i*255)/16;
    T1_AAHSetGrayValues( cst );
    mm_log((1,"setting T1 antialias to high\n"));
  }
  
  t1_aa = st;
}
Exemple #7
0
long tcp_getdata (TCPSTREAM *stream)
{
  int i;
  fd_set fds,efds;
  struct timeval tmo;
  time_t t = time (0);
  blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  if (stream->tcpsi == INVALID_SOCKET) return NIL;
  (*bn) (BLOCK_TCPREAD,NIL);
  while (stream->ictr < 1) {	/* if nothing in the buffer */
    if (tcpdebug) mm_log ("Reading TCP data",TCPDEBUG);
				/* simple case if not a socket */
    if (stream->tcpsi != stream->tcpso)
      while (((i = read (stream->tcpsi,stream->ibuf,BUFLEN)) < 0) &&
	     (errno == EINTR));
    else {
      time_t tl = time (0);
      time_t now = tl;
      int ti = ttmo_read ? now + ttmo_read : 0;
      tmo.tv_usec = 0;
      FD_ZERO (&fds);		/* initialize selection vector */
      FD_ZERO (&efds);		/* handle errors too */
				/* set bit in selection vectors */
      FD_SET (stream->tcpsi,&fds);
      FD_SET (stream->tcpsi,&efds);
      errno = NIL;		/* initially no error */
      do {			/* block under timeout */
	tmo.tv_sec = ti ? ti - now : 0;
	i = select (stream->tcpsi+1,&fds,NIL,&efds,ti ? &tmo : NIL);
	now = time (0);		/* fake timeout if interrupt & time expired */
	if ((i < 0) && ((errno = WSAGetLastError ()) == WSAEINTR) && ti &&
	    (ti <= now)) i = 0;
      } while ((i < 0) && (errno == WSAEINTR));
				/* success from select, read what we can */
      if (i > 0) while (((i = recv (stream->tcpsi,stream->ibuf,BUFLEN,0)) ==
			 SOCKET_ERROR) &&
			((errno = WSAGetLastError ()) == WSAEINTR));
      else if (!i) {		/* timeout, ignore if told to resume */
	if (tmoh && (*tmoh) (now - t,now - tl)) continue;
				/* otherwise punt */
	if (tcpdebug) mm_log ("TCP data read timeout",TCPDEBUG);
	return tcp_abort (&stream->tcpsi);
      }
    }
    if (i <= 0) {		/* error seen? */
      if (tcpdebug) {
	char *s,tmp[MAILTMPLEN];
	if (i) sprintf (s = tmp,"TCP data read I/O error %d",errno);
	else s = "TCP data read end of file";
	mm_log (tmp,TCPDEBUG);
      }
      return tcp_abort (&stream->tcpsi);
    }
    stream->iptr = stream->ibuf;/* point at TCP buffer */
    stream->ictr = i;		/* set new byte count */
    if (tcpdebug) mm_log ("Successfully read TCP data",TCPDEBUG);
  }
  (*bn) (BLOCK_NONE,NIL);
  return T;
}
Exemple #8
0
static undef_int
i_init_t1_low(int t1log) {
  int init_flags = IGNORE_CONFIGFILE|IGNORE_FONTDATABASE;

  mm_log((1,"init_t1(%d)\n", t1log));

  i_clear_error();

  if (t1_active_fonts) {
    mm_log((1, "Cannot re-initialize T1 - active fonts\n"));
    i_push_error(0, "Cannot re-initialize T1 - active fonts");
    return 1;
  }

  if (t1_initialized) {
    T1_CloseLib();
    t1_initialized = 0;
  }
  
  if (t1log)
    init_flags |= LOGFILE;
  if ((T1_InitLib(init_flags) == NULL)){
    mm_log((1,"Initialization of t1lib failed\n"));
    i_push_error(0, "T1_InitLib failed");
    return(1);
  }
  T1_SetLogLevel(T1LOG_DEBUG);

  ++t1_initialized;

  return(0);
}
Exemple #9
0
long dummy_rename (MAILSTREAM *stream,char *old,char *newname)
{
  struct stat sbuf;
  char c,*s,tmp[MAILTMPLEN],mbx[MAILTMPLEN],oldname[MAILTMPLEN];
  long ret = NIL;
				/* no trailing \ allowed */
  if (!dummy_file (oldname,old) || !(s = dummy_file (mbx,newname)) ||
      ((s = strrchr (s,'\\')) && !s[1])) {
    sprintf (mbx,"Can't rename %.80s to %.80s: invalid name",old,newname);
    mm_log (mbx,ERROR);
    return NIL;
  }
				/* found superior to destination name? */
  if (s && (s != mbx) && ((mbx[1] != ':') || (s != mbx + 2))) {
    c = s[1];			/* remember character after delimiter */
    *s = s[1] = '\0';		/* tie off name at delimiter */
				/* name doesn't exist, create it */
    if (stat (mbx,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) {
      *s = '\\';		/* restore delimiter */
      if (!dummy_create (stream,mbx)) return NIL;
    }
    else *s = '\\';		/* restore delimiter */
    s[1] = c;			/* restore character after delimiter */
  }
				/* rename of non-ex INBOX creates dest */
  if (!compare_cstring (old,"INBOX") && stat (oldname,&sbuf))
    return dummy_create (NIL,mbx);
  if (rename (oldname,mbx)) {
    sprintf (tmp,"Can't rename mailbox %.80s to %.80s: %.80s",old,newname,
	     strerror (errno));
    mm_log (tmp,ERROR);
    return NIL;
  }
  return LONGT;			/* return success */
}
Exemple #10
0
long auth_gssapi_client (authchallenge_t challenger,authrespond_t responder,
			 char *service,NETMBX *mb,void *stream,
			 unsigned long *trial,char *user)
{
  gss_buffer_desc chal;
  kinit_t ki = (kinit_t) mail_parameters (NIL,GET_KINIT,NIL);
  long ret = NIL;
  *trial = 65535;		/* never retry */
				/* get initial (empty) challenge */
  if ((chal.value = (*challenger) (stream,(unsigned long *) &chal.length)) != NULL) {
    if (chal.length) {		/* abort if challenge non-empty */
      mm_log ("Server bug: non-empty initial GSSAPI challenge",WARN);
      (*responder) (stream,NIL,0);
      ret = LONGT;		/* will get a BAD response back */
    }
    else if (mb->authuser[0] && strcmp (mb->authuser,myusername ())) {
      mm_log ("Can't use Kerberos: invalid /authuser",WARN);
      (*responder) (stream,NIL,0);
      ret = LONGT;		/* will get a BAD response back */
    }
    else ret = auth_gssapi_client_work (challenger,chal,responder,service,mb,
					stream,user,ki);
  }
  return ret;
}
Exemple #11
0
static
void
i_tt_init_raster_map( TT_Raster_Map* bit, i_img_dim width, i_img_dim height, int smooth ) {

  mm_log((1,"i_tt_init_raster_map( bit %p, width %" i_DF ", height %" i_DF
	  ", smooth %d)\n", bit, i_DFc(width), i_DFc(height), smooth));
  
  bit->rows  = height;
  bit->width = ( width + 3 ) & -4;
  bit->flow  = TT_Flow_Down;
  
  if ( smooth ) {
    bit->cols  = bit->width;
    bit->size  = bit->rows * bit->width;
  } else {
    bit->cols  = ( bit->width + 7 ) / 8;    /* convert to # of bytes     */
    bit->size  = bit->rows * bit->cols;     /* number of bytes in buffer */
  }

  /* rows can be 0 for some glyphs, for example ' ' */
  if (bit->rows && bit->size / bit->rows != bit->cols) {
    i_fatal(0, "Integer overflow calculating bitmap size (%d, %d)\n",
            bit->width, bit->rows);
  }
  
  mm_log((1,"i_tt_init_raster_map: bit->width %d, bit->cols %d, bit->rows %d, bit->size %ld)\n", bit->width, bit->cols, bit->rows, bit->size ));

  bit->bitmap = (void *) mymalloc( bit->size ); /* checked 6Nov05 tonyc */
  if ( !bit->bitmap ) i_fatal(0,"Not enough memory to allocate bitmap (%d)!\n",bit->size );
}
Exemple #12
0
static char *ssl_analyze_status (SECURITY_STATUS err,char *buf)
{
  switch (err) {
  case SEC_E_OK:		/* no error */
  case SEC_I_CONTINUE_NEEDED:
  case SEC_I_INCOMPLETE_CREDENTIALS:
  case SEC_E_INCOMPLETE_MESSAGE:
    return NIL;
  case SEC_E_NO_AUTHENTICATING_AUTHORITY:
    mm_log ("unexpected SEC_E_NO_AUTHENTICATING_AUTHORITY",NIL);
    return "*No authority could be contacted for authentication";
  case SEC_E_WRONG_PRINCIPAL:
    mm_log ("unexpected SEC_E_WRONG_PRINCIPAL",NIL);
  case CERT_E_CN_NO_MATCH:
    return "*Server name does not match certificate";
  case SEC_E_UNTRUSTED_ROOT:
    mm_log ("unexpected SEC_E_UNTRUSTED_ROOT",NIL);
  case CERT_E_UNTRUSTEDROOT:
    return "*Self-signed certificate or untrusted authority";
  case SEC_E_CERT_EXPIRED:
    mm_log ("unexpected SEC_E_CERT_EXPIRED",NIL);
  case CERT_E_EXPIRED:
    return "*Certificate has expired";
  case CERT_E_REVOKED:
    return "*Certificate revoked";
  case SEC_E_INVALID_TOKEN:
    return "Invalid token, probably not an SSL server";
  case SEC_E_UNSUPPORTED_FUNCTION:
    return "SSL not supported on this machine - upgrade your system software";
  }
  sprintf (buf,"Unexpected SSPI or certificate error %lx - report this",err);
  return buf;
}
Exemple #13
0
int
i_t1_has_chars(i_t1_font_t font, const char *text, size_t len, int utf8,
               char *out) {
  int count = 0;
  int font_num = font->font_id;
  
  i_mutex_lock(mutex);

  mm_log((1, "i_t1_has_chars(font_num %d, text %p, len %u, utf8 %d)\n", 
          font_num, text, (unsigned)len, utf8));

  i_clear_error();
  if (T1_LoadFont(font_num)) {
    t1_push_error();
    i_mutex_unlock(mutex);
    return 0;
  }

  while (len) {
    unsigned long c;
    if (utf8) {
      c = i_utf8_advance(&text, &len);
      if (c == ~0UL) {
        i_push_error(0, "invalid UTF8 character");
	i_mutex_unlock(mutex);
        return 0;
      }
    }
    else {
      c = (unsigned char)*text++;
      --len;
    }
    
    if (c >= 0x100) {
      /* limit of 256 characters for T1 */
      *out++ = 0;
    }
    else {
      char const * name = T1_GetCharName(font_num, (unsigned char)c);

      if (name) {
        *out++ = strcmp(name, ".notdef") != 0;
      }
      else {
        mm_log((2, "  No name found for character %lx\n", c));
        *out++ = 0;
      }
    }
    ++count;
  }

  i_mutex_unlock(mutex);

  return count;
}
Exemple #14
0
int main ()
{
	int* vm_ptr;
	int PAGE_SIZE = sysconf(_SC_PAGE_SIZE);
	//printf("%d\n", PAGE_SIZE);
	int vm_size = 16*PAGE_SIZE;
	int temp;

	vm_ptr=memalign(PAGE_SIZE, vm_size);
	if(vm_ptr==NULL)
	{
		printf("FAILURE in virtual memory allocation\n");	
		return 0;
	}

	mm_init((void*)vm_ptr, vm_size, 4, PAGE_SIZE, 1);
	mm_log();	

	/* virtual memory access starts */
	/*
 *r1
w2
r3
r4
r5
r2
r1
r3
r5
 * */
	temp = vm_ptr[8];					// Read virtual page 1
	mm_log();											
	vm_ptr[8 + ((int)((1*PAGE_SIZE)/sizeof(int)))] = 72; 	// Write virtual page 2
	mm_log();										
	temp = vm_ptr[8 + ((int)((2*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 3
	mm_log();									
	temp = vm_ptr[8 + ((int)((3*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 4
	mm_log();								
	temp = vm_ptr[8 + ((int)((4*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 5 
	mm_log();							
	temp = vm_ptr[8 + ((int)((1*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 2
	mm_log();						
	temp = vm_ptr[9];					// Read virtual page 1
	mm_log();					
	temp = vm_ptr[2 + ((int)((1*PAGE_SIZE)/sizeof(int)))]; // Read virtual page 3
	mm_log();				
	temp = vm_ptr[8 + ((int)((4*PAGE_SIZE)/sizeof(int)))]; // Read virtual page 5
	mm_log();				

	/* virtual memory access ends */

	free(vm_ptr);
	return 0;
}
Exemple #15
0
static void
i_tt_uninit(void *p) {
  i_tt_engine *tteng = p;

  if (tteng->initialized) {
    mm_log((1, "finalizing FT1 state %p\n", tteng));
    TT_Done_FreeType(tteng->engine);
  }
  mm_log((1, "freeing FT1 state %p\n", tteng));
  myfree(tteng);
}
Exemple #16
0
long tcp_getbuffer (TCPSTREAM *stream,unsigned long size,char *s)
{
  unsigned long n;
				/* make sure socket still alive */
  if (stream->tcpsi < 0) return NIL;
				/* can transfer bytes from buffer? */
  if (n = min (size,stream->ictr)) {
    memcpy (s,stream->iptr,n);	/* yes, slurp as much as we can from it */
    s += n;			/* update pointer */
    stream->iptr +=n;
    size -= n;			/* update # of bytes to do */
    stream->ictr -=n;
  }
  if (size) {
    int i;
    fd_set fds,efds;
    struct timeval tmo;
    time_t t = time (0);
    blocknotify_t bn=(blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
    (*bn) (BLOCK_TCPREAD,NIL);
    while (size > 0) {		/* until request satisfied */
      time_t tl = time (0);
      time_t now = tl;
      time_t ti = ttmo_read ? now + ttmo_read : 0;
      if (tcpdebug) mm_log ("Reading TCP buffer",TCPDEBUG);
      tmo.tv_usec = 0;
      FD_ZERO (&fds);		/* initialize selection vector */
      FD_ZERO (&efds);		/* handle errors too */
      FD_SET (stream->tcpsi,&fds);
      FD_SET (stream->tcpsi,&efds);
      errno = NIL;		/* block and read */
      do {			/* block under timeout */
	tmo.tv_sec = ti ? ti - now : 0;
	i = select (stream->tcpsi+1,&fds,0,&efds,ti ? &tmo : 0);
	now = time (0);		/* fake timeout if interrupt & time expired */
	if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
      } while ((i < 0) && (errno == EINTR));
      if (i > 0) {		/* select says there's data to read? */
	while (((i = read (stream->tcpsi,s,(int) min (maxposint,size))) < 0) &&
	       (errno == EINTR));
	if (i < 1) return tcp_abort (stream);
	s += i;			/* point at new place to write */
	size -= i;		/* reduce byte count */
	if (tcpdebug) mm_log ("Successfully read TCP buffer",TCPDEBUG);
      }
      else if (i || !tmoh || !(*tmoh) (now - t,now - tl))
	return tcp_abort (stream);
    }
    (*bn) (BLOCK_NONE,NIL);
  }
  *s = '\0';			/* tie off string */
  return T;
}
Exemple #17
0
long smtp_auth (SENDSTREAM *stream,NETMBX *mb,char *tmp)
{
  unsigned long trial,auths;
  char *lsterr = NIL;
  char usr[MAILTMPLEN];
  AUTHENTICATOR *at;
  long ret = NIL;
  for (auths = ESMTP.auth, stream->saslcancel = NIL;
       !ret && stream->netstream && auths &&
       (at = mail_lookup_auth (find_rightmost_bit (&auths) + 1)); ) {
    if (lsterr) {		/* previous authenticator failed? */
      sprintf (tmp,"Retrying using %s authentication after %.80s",
	       at->name,lsterr);
      mm_log (tmp,NIL);
      fs_give ((void **) &lsterr);
    }
    trial = 0;			/* initial trial count */
    tmp[0] = '\0';		/* empty buffer */
    if (stream->netstream) do {
      if (lsterr) {
	sprintf (tmp,"Retrying %s authentication after %.80s",at->name,lsterr);
	mm_log (tmp,WARN);
	fs_give ((void **) &lsterr);
      }
      stream->saslcancel = NIL;
      if (smtp_send (stream,"AUTH",at->name) == SMTPAUTHREADY) {
				/* hide client authentication responses */
	if (!(at->flags & AU_SECURE)) stream->sensitive = T;
	if ((*at->client) (smtp_challenge,smtp_response,"smtp",mb,stream,
			   &trial,usr)) {
	  if (stream->replycode == SMTPAUTHED) {
	    ESMTP.auth = NIL;	/* disable authenticators */
	    ret = LONGT;
	  }
				/* if main program requested cancellation */
	  else if (!trial) mm_log ("SMTP Authentication cancelled",ERROR);
	}
	stream->sensitive = NIL;/* unhide */
      }
				/* remember response if error and no cancel */
      if (!ret && trial) lsterr = cpystr (stream->reply);
    } while (!ret && stream->netstream && trial &&
	     (trial < smtp_maxlogintrials));
  }
  if (lsterr) {			/* previous authenticator failed? */
    if (!stream->saslcancel) {	/* don't do this if a cancel */
      sprintf (tmp,"Can not authenticate to SMTP server: %.80s",lsterr);
      mm_log (tmp,ERROR);
    }
    fs_give ((void **) &lsterr);
  }
  return ret;			/* authentication failed */
}
Exemple #18
0
long tcp_getdata (TCPSTREAM *stream)
{
  int i;
  fd_set fds,efds;
  struct timeval tmo;
  time_t t = time (0);
  blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  if (stream->tcpsi < 0) return NIL;
  (*bn) (BLOCK_TCPREAD,NIL);
  while (stream->ictr < 1) {	/* if nothing in the buffer */
    time_t tl = time (0);	/* start of request */
    time_t now = tl;
    time_t ti = ttmo_read ? now + ttmo_read : 0;
    if (tcpdebug) mm_log ("Reading TCP data",TCPDEBUG);
    tmo.tv_usec = 0;
    FD_ZERO (&fds);		/* initialize selection vector */
    FD_ZERO (&efds);		/* handle errors too */
    FD_SET (stream->tcpsi,&fds);/* set bit in selection vectors */
    FD_SET (stream->tcpsi,&efds);
    errno = NIL;		/* initially no error */
    do {			/* block under timeout */
      tmo.tv_sec = ti ? ti - now : 0;
      i = select (stream->tcpsi+1,&fds,NIL,&efds,ti ? &tmo : NIL);
      now = time (0);		/* fake timeout if interrupt & time expired */
      if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
    } while ((i < 0) && (errno == EINTR));
    if (i) {			/* non-timeout result from select? */
				/* read what we can */
      if (i > 0) while (((i = read (stream->tcpsi,stream->ibuf,BUFLEN)) < 0) &&
			(errno == EINTR));
      if (i <= 0) {		/* error seen? */
	if (tcpdebug) {
	  char *s,tmp[MAILTMPLEN];
	  if (i) sprintf (s = tmp,"TCP data read I/O error %d",errno);
	  else s = "TCP data read end of file";
	  mm_log (s,TCPDEBUG);
	}
	return tcp_abort (stream);
      }
      stream->ictr = i;		/* success, set new count and pointer */
      stream->iptr = stream->ibuf;
      if (tcpdebug) mm_log ("Successfully read TCP data",TCPDEBUG);
    }
				/* timeout, punt unless told not to */
    else if (!tmoh || !(*tmoh) (now - t,now - tl)) {
      if (tcpdebug) mm_log ("TCP data read timeout",TCPDEBUG);
      return tcp_abort (stream);/* error or timeout no-continue */
    }
  }
  (*bn) (BLOCK_NONE,NIL);
  return T;
}
Exemple #19
0
long tcp_sout (TCPSTREAM *stream,char *string,unsigned long size)
{
  int i;
  fd_set fds,efds;
  struct timeval tmo;
  time_t t = time (0);
  blocknotify_t bn = (blocknotify_t) mail_parameters (NIL,GET_BLOCKNOTIFY,NIL);
  if (stream->tcpso < 0) return NIL;
  (*bn) (BLOCK_TCPWRITE,NIL);
  while (size > 0) {		/* until request satisfied */
    time_t tl = time (0);	/* start of request */
    time_t now = tl;
    time_t ti = ttmo_write ? now + ttmo_write : 0;
    if (tcpdebug) mm_log ("Writing to TCP",TCPDEBUG);
    tmo.tv_usec = 0;
    FD_ZERO (&fds);		/* initialize selection vector */
    FD_ZERO (&efds);		/* handle errors too */
    FD_SET (stream->tcpso,&fds);/* set bit in selection vector */
    FD_SET(stream->tcpso,&efds);/* set bit in error selection vector */
    errno = NIL;		/* block and write */
    do {			/* block under timeout */
      tmo.tv_sec = ti ? ti - now : 0;
      i = select (stream->tcpso+1,NIL,&fds,&efds,ti ? &tmo : NIL);
      now = time (0);		/* fake timeout if interrupt & time expired */
      if ((i < 0) && (errno == EINTR) && ti && (ti <= now)) i = 0;
    } while ((i < 0) && (errno == EINTR));
    if (i) {			/* non-timeout result from select? */
				/* write what we can */
      if (i > 0) while (((i = write (stream->tcpso,string,size)) < 0) &&
			(errno == EINTR));
      if (i <= 0) {		/* error seen? */
	if (tcpdebug) {
	  char tmp[MAILTMPLEN];
	  sprintf (tmp,"TCP write I/O error %d",errno);
	  mm_log (tmp,TCPDEBUG);
	}
	return tcp_abort (stream);
      }
      string += i;		/* how much we sent */
      size -= i;		/* count this size */
      if (tcpdebug) mm_log ("successfully wrote to TCP",TCPDEBUG);
    }
				/* timeout, punt unless told not to */
    else if (!tmoh || !(*tmoh) (now - t,now - tl)) {
      if (tcpdebug) mm_log ("TCP write timeout",TCPDEBUG);
      return tcp_abort (stream);
    }
  }
  (*bn) (BLOCK_NONE,NIL);
  return T;			/* all done */
}
Exemple #20
0
size_t
i_tt_glyph_name(TT_Fonthandle *handle, unsigned long ch, char *name_buf, 
                 size_t name_buf_size) {
#ifdef FTXPOST
  TT_Error rc;
  TT_String *psname;
  TT_UShort index;

  i_clear_error();

  if (!handle->loaded_names) {
    TT_Post post;
    mm_log((1, "Loading PS Names"));
    handle->load_cond = TT_Load_PS_Names(handle->face, &post);
    ++handle->loaded_names;
  }

  if (handle->load_cond) {
    i_push_errorf(handle->load_cond, "error loading names (%#x)",
		  (unsigned)handle->load_cond);
    return 0;
  }
  
  index = TT_Char_Index(handle->char_map, ch);
  if (!index) {
    i_push_error(0, "no such character");
    return 0;
  }

  rc = TT_Get_PS_Name(handle->face, index, &psname);

  if (rc) {
    i_push_error(rc, "error getting name");
    return 0;
  }

  strncpy(name_buf, psname, name_buf_size);
  name_buf[name_buf_size-1] = '\0';

  return strlen(psname) + 1;
#else
  mm_log((1, "FTXPOST extension not enabled\n"));
  i_clear_error();
  i_push_error(0, "Use of FTXPOST extension disabled");

  return 0;
#endif
}
Exemple #21
0
MAILSTREAM *dummy_open (MAILSTREAM *stream)
{
  int fd;
  char err[MAILTMPLEN],tmp[MAILTMPLEN];
  struct stat sbuf;
				/* OP_PROTOTYPE call */
  if (!stream) return &dummyproto;
  err[0] = '\0';		/* no error message yet */
				/* can we open the file? */
  if (!dummy_file (tmp,stream->mailbox))
    sprintf (err,"Can't open this name: %.80s",stream->mailbox);
  else if ((fd = open (tmp,O_RDONLY,NIL)) < 0) {
				/* no, error unless INBOX */
    if (compare_cstring (stream->mailbox,"INBOX"))
      sprintf (err,"%.80s: %.80s",strerror (errno),stream->mailbox);
  }
  else {			/* file had better be empty then */
    fstat (fd,&sbuf);		/* sniff at its size */
    close (fd);
    if (sbuf.st_size)		/* bogus format if non-empty */
      sprintf (err,"%.80s (file %.80s) is not in valid mailbox format",
	       stream->mailbox,tmp);
  }
  if (err[0]) {			/* if an error happened */
    mm_log (err,stream->silent ? WARN : ERROR);
    return NIL;
  }
  else if (!stream->silent) {	/* only if silence not requested */
    mail_exists (stream,0);	/* say there are 0 messages */
    mail_recent (stream,0);	/* and certainly no recent ones! */
    stream->uid_validity = time (0);
  }
  stream->inbox = T;		/* note that it's an INBOX */
  return stream;		/* return success */
}
Exemple #22
0
long dummy_create_path (MAILSTREAM *stream,char *path,long dirmode)
{
  struct stat sbuf;
  char c,*s,tmp[MAILTMPLEN];
  int fd;
  long ret = NIL;
  char *t = strrchr (path,'\\');
  char *pt = (path[1] == ':') ? path + 2 : path;
  int wantdir = t && !t[1];
  if (wantdir) *t = '\0';	/* flush trailing delimiter for directory */
				/* found superior to this name? */
  if ((s = strrchr (pt,'\\')) && (s != pt)) {
    strncpy (tmp,path,(size_t) (s - path));
    tmp[s - path] = '\0';	/* make directory name for stat */
    c = *++s;			/* tie off in case need to recurse */
    *s = '\0';
				/* name doesn't exist, create it */
    if ((stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&
	!dummy_create_path (stream,path,dirmode)) return NIL;
    *s = c;			/* restore full name */
  }
  if (wantdir) {		/* want to create directory? */
    ret = !mkdir (path);
    *t = '\\';			/* restore directory delimiter */
  }
				/* create file */
  else if ((fd = open (path,O_WRONLY|O_CREAT|O_EXCL,S_IREAD|S_IWRITE)) >= 0)
    ret = !close (fd);		/* close file */
  if (!ret) {			/* error? */
    sprintf (tmp,"Can't create mailbox node %.80s: %.80s",path,
	     strerror (errno));
    mm_log (tmp,ERROR);
  }
  return ret;			/* return status */
}
Exemple #23
0
int lockname (char *lock,char *fname,int op)
{
  int ld;
  char c,*s;
  if (!((s = lockdir (lock,getenv ("TEMP"),NIL)) ||
	(s = lockdir (lock,getenv ("TMP"),NIL)) ||
	(s = lockdir (lock,getenv ("TMPDIR"),NIL)) ||
				/* C:\TEMP is last resort */
	(s = lockdir (lock,defaultDrive (),"TEMP")))) {
    mm_log ("Unable to find temporary directory",ERROR);
    return -1;
  }
				/* generate file name */
  while (c = *fname++) switch (c) {
  case '/': case '\\': case ':':
    *s++ = '!';			/* convert bad chars to ! */
    break;
  default:
    *s++ = c;
    break;
  }
  *s++ = c;			/* tie off name */
				/* get the lock */
  if (((ld = open (lock,O_BINARY|O_RDWR|O_CREAT,S_IREAD|S_IWRITE)) >= 0) && op)
    flock (ld,op);		/* apply locking function */
  return ld;			/* return locking file descriptor */
}
Exemple #24
0
char *dos_default_gets (readfn_t f,void *stream,unsigned long size,
			GETS_DATA *md)
{
  readprogress_t *rp = mail_parameters (NIL,GET_READPROGRESS,NIL);
  char *ret,tmp[MAILTMPLEN+1];
  unsigned long i,j,dsc,rdi = 0;
  unsigned long dos_max = 63 * 1024;
  if (!dos_gets_buf)		/* one-time initialization */
    dos_gets_buf = (char *) fs_get ((size_t) dos_max + 1);
  ret = (md->flags & MG_COPY) ?
    ((char *) fs_get ((size_t) size + 1)) : dos_gets_buf;
  if (size > dos_max) {
    sprintf (tmp,"Mailbox %s, %s %lu[%.80s], %lu octets truncated to %ld",
	     md->stream->mailbox,(md->flags & MG_UID) ? "UID" : "#",
	     md->msgno,md->what,size,(long) dos_max);
    mm_log (tmp,WARN);		/* warn user */
    dsc = size - dos_max;	/* number of bytes to discard */
    size = dos_max;		/* maximum length string we can read */
  }
  else dsc = 0;			/* nothing to discard */
  dos_gets_buf[size] = '\0';	/* tie off string */
  if (rp) for (i = size; j = min ((long) MAILTMPLEN,(long) i); i -= j) {
    (*f) (stream,j,ret + rdi);
    (*rp) (md,rdi += j);
  }
  else (*f) (stream,size,dos_gets_buf);
				/* toss out everything after that */
  for (i = dsc; j = min ((long) MAILTMPLEN,(long) i); i -= j) {
    (*f) (stream,j,tmp);
    if (rp) (*rp) (md,rdi += j);
  }
  return ret;
}
/*
 * mm_free - Freeing a block does nothing.
 */
void mm_free(void *ptr)
{
    size_t size = GET_SIZE(HDRP(ptr));
    mm_log("\nfree(%p)\n", ptr);

    init_free_block(ptr, size);
}
Exemple #26
0
void mm_notify (MAILSTREAM *stream,char *string,long errflg)
{
  char tmp[MAILTMPLEN];
  tmp[11] = '\0';		/* see if TRYCREATE */
  if (!strcmp (ucase (strncpy (tmp,string,11)),"[TRYCREATE]")) trycreate = T;
  mm_log (string,errflg);	/* just do mm_log action */
}
/* 
 * mm_init - initialize the malloc package.
 */
int mm_init(void)
{
    /* Create the initial empty heap */
    if ((heap_listp = mem_sbrk(4*WSIZE)) == (void *)-1)
        return -1;
    
    PUT(heap_listp, 0); /* Alignment padding */
    PUT(heap_listp + (1*WSIZE), PACK(DSIZE, 1)); /* Prologue header */
    PUT(heap_listp + (2*WSIZE), PACK(DSIZE, 1)); /* Prologue footer */
    PUT(heap_listp + (3*WSIZE), PACK(0, 1)); /* Epilogue header */
    heap_listp += (2*WSIZE);

    mm_log("\n\n*** init ***\n");

    free_tailp = NULL;
    free_headp = NULL;

    /* Extend the empty heap with a free block of CHUNKSIZE bytes */
    if (extend_heap(CHUNKSIZE/WSIZE) == NULL)
        return -1;

    ASSERT;
    
    return 0;
}
Exemple #28
0
undef_int
i_tt_bbox( TT_Fonthandle *handle, double points,const char *txt,size_t len,i_img_dim cords[6], int utf8) {
  int inst;

  i_clear_error();
  mm_log((1,"i_tt_box(handle %p,points %f,txt '%.*s', len %ld, utf8 %d)\n",
	  handle, points, (int)len, txt, (long)len, utf8));

  if ( (inst=i_tt_get_instance(handle,points,-1)) < 0) {
    i_push_errorf(0, "i_tt_get_instance(%g)", points);
    mm_log((1,"i_tt_text: get instance failed\n"));
    return 0;
  }

  return i_tt_bbox_inst(handle, inst, txt, len, cords, utf8);
}
Exemple #29
0
void *
DSO_open(char *file, char **evalstring) {
  HMODULE d_handle;
  func_ptr *function_list;
  DSO_handle *dso_handle;
  
  void (*f)(void *s,void *u); /* these will just have to be void for now */

  mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",file,file,evalstring) );

  *evalstring = NULL;
  if ((d_handle = LoadLibrary(file)) == NULL) {
    mm_log((1, "DSO_open: LoadLibrary(%s) failed: %lu\n", file, GetLastError()));
    return NULL;
  }
  if ( (*evalstring = (char *)GetProcAddress(d_handle, I_EVALSTR)) == NULL) {
    mm_log((1,"DSO_open: GetProcAddress didn't fine '%s': %lu\n", I_EVALSTR, GetLastError()));
    FreeLibrary(d_handle);
    return NULL;
  }
  if ((f = (void (*)(void *, void*))GetProcAddress(d_handle, I_INSTALL_TABLES)) == NULL) {
    mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_INSTALL_TABLES, GetLastError()));
    FreeLibrary(d_handle);
    return NULL;
  }
  mm_log((1, "Calling install tables\n"));
  f(&symbol_table, &i_UTIL_table);
  mm_log((1, "Call ok\n"));
  
  if ( (function_list = (func_ptr *)GetProcAddress(d_handle, I_FUNCTION_LIST)) == NULL) {
    mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_FUNCTION_LIST, GetLastError()));
    FreeLibrary(d_handle);
    return NULL;
  }
  if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { /* checked 17jul05 tonyc */
    mm_log( (1, "DSO_Open: out of memory\n") );
    FreeLibrary(d_handle);
    return NULL;
  }
  dso_handle->handle=d_handle; /* needed to close again */
  dso_handle->function_list=function_list;
  if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
    free(dso_handle);
    FreeLibrary(d_handle); 
    return NULL; 
  }
  strcpy(dso_handle->filename,file);

  mm_log( (1,"DSO_open <- %p\n",dso_handle) );
  return (void*)dso_handle;

}
Exemple #30
0
int main ()
{
	int* vm_ptr;
	int PAGE_SIZE = sysconf(_SC_PAGE_SIZE);
	//printf("%d\n", PAGE_SIZE);
	int vm_size = 16*PAGE_SIZE;
	NUM_VM_PAGES = vm_size/PAGE_SIZE;
	int temp;
	FILE* f1 = fopen("test1.txt", "w");

	vm_ptr=memalign(PAGE_SIZE, vm_size);
	if(vm_ptr==NULL)
	{
		printf("FAILURE in virtual memory allocation\n");	
		return 0;
	}

	mm_init((void*)vm_ptr, vm_size, 4, PAGE_SIZE, 1);
	mm_log(f1);	

	/* virtual memory access starts */
	
	temp = vm_ptr[8];					// Read virtual page 1
	mm_log(f1);												 
	vm_ptr[8 + ((int)((1*PAGE_SIZE)/sizeof(int)))] = 72; 	// Write virtual page 2
	mm_log(f1);												 
	vm_ptr[16] = 12;					// Write virtual page 1 
	mm_log(f1);												 
	temp = vm_ptr[8 + ((int)((2*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 3
	mm_log(f1);												 
	temp = vm_ptr[8 + ((int)((3*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 4
	mm_log(f1);												 
	temp = vm_ptr[24];					// Read virtual page 1 
	mm_log(f1);												 
	temp = vm_ptr[8 + ((int)((4*PAGE_SIZE)/sizeof(int)))];	// Read virtual page 5
	mm_log(f1);												 
	vm_ptr[32] = 64;					// Write virtual page 1  
	mm_log(f1);												 
	temp = vm_ptr[16 + ((int)((1*PAGE_SIZE)/sizeof(int)))]; // Read virtual page 2
	mm_log(f1);												 

	/* virtual memory access ends */

	free(vm_ptr);
	fclose(f1);
	return 0;
}