size_t length_base64(char* src,size_t ssize)
{
  char* inb;
  int i;
  int l;
  int left;
  size_t pos;
  unsigned long triple;

  /* Exit on empty input */
  if (!ssize||src==NULL) {
    log_msg(LOG_LEVEL_DEBUG,"length_base64: empty string");
    return 0;
  }



  /* Initialize working pointers */
  inb = src;

  l = 0;
  triple = 0;
  pos=0;
  left = ssize;
  /*
   * Process entire inbuf.
   */
  while (left != 0)
    {
      left--;
      i = fromb64[(unsigned char)*inb];
      switch(i)
	{
	case FAIL:
	  log_msg(LOG_LEVEL_DEBUG, "length_base64: illegal string: '%s'", src);
	  return 0; 
	  break;
	case SKIP:
	  break;
	default:
	  triple = triple<<6 | (0x3f & i);
	  l++;
	  break;
	}
      if (l == 4 || left == 0)
	{
	  switch(l)
	    {
	    case 2:
	      triple = triple>>4;
	      break;
	    case 3:
	      triple = triple>>2;
	      break;
	    default:
	      break;
	    }
	  for (l  -= 2; l >= 0; l--)
	    {
	      pos++;
	    }
	  triple = 0;
	  l = 0;
	}
      inb++;
    }
  
  return pos;
}
size_t length_base64(char* src,size_t ssize)
{
  char* inb;
  int i;
  int l;
  int left;
  size_t pos;
  unsigned long triple;

   
  if (!ssize||src==NULL) {
    log_msg(LOG_LEVEL_DEBUG,"length_base64: empty string");
    return 0;
  }



   
  inb = src;

  l = 0;
  triple = 0;
  pos=0;
  left = ssize;
   
  while (left != 0)
    {
      left--;
      i = fromb64[(unsigned char)*inb];
      switch(i)
	{
	case FAIL:
	  log_msg(LOG_LEVEL_DEBUG, "length_base64: illegal string: '%s'", src);
	  return 0; 
	  break;
	case SKIP:
	  break;
	default:
	  triple = triple<<6 | (0x3f & i);
	  l++;
	  break;
	}
      if (l == 4 || left == 0)
	{
	  switch(l)
	    {
	    case 2:
	      triple = triple>>4;
	      break;
	    case 3:
	      triple = triple>>2;
	      break;
	    default:
	      break;
	    }
	  for (l  -= 2; l >= 0; l--)
	    {
	      pos++;
	    }
	  triple = 0;
	  l = 0;
	}
      inb++;
    }
  
  return pos;
}