Esempio n. 1
0
static PyObject *
api_sieve_machine_error_text (PyObject *self, PyObject *args)
{
  int status;
  PySieveMachine *py_mach;
  mu_stream_t estr;
  mu_transport_t trans[2];
  PyObject *retval;
  mu_off_t length = 0;
  
  if (!PyArg_ParseTuple (args, "O!", &PySieveMachineType, &py_mach))
    return NULL;
  if (!py_mach->mach)
    PyErr_SetString (PyExc_RuntimeError, "Uninitialized Sieve machine");
      
  mu_sieve_get_diag_stream (py_mach->mach, &estr);
  status = mu_stream_ioctl (estr, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET,
			    trans);
  if (status == 0)
    {
      mu_stream_t str = (mu_stream_t) trans[0];

      mu_stream_size (str, &length);
      status = mu_stream_ioctl (str, MU_IOCTL_TRANSPORT, MU_IOCTL_OP_GET,
				trans);
      mu_stream_truncate (str, 0);
    }
  
  if (status)
    PyErr_SetString (PyExc_RuntimeError, mu_strerror (status));
  retval = PyString_FromStringAndSize ((char*) trans[0], length);

  mu_stream_unref (estr);
  return _ro (retval);
}
Esempio n. 2
0
static int
_streamref_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
{
  struct _mu_streamref *sp = (struct _mu_streamref *)str;
  
  switch (code)
    {
    case MU_IOCTL_SEEK_LIMITS:
      if (!arg)
	return EINVAL;
      else
	{
	  mu_off_t *lim = arg;

	  switch (opcode)
	    {
	    case MU_IOCTL_OP_GET:
	      lim[0] = sp->start;
	      lim[1] = sp->end;
	      return 0;

	    case MU_IOCTL_OP_SET:
	      sp->start = lim[0];
	      sp->end = lim[1];
	      return 0;

	    default:
	      return EINVAL;
	    }
	}
    }
  return streamref_return (sp, mu_stream_ioctl (sp->transport, code,
						opcode, arg));
}
Esempio n. 3
0
static int
set_strerr_flt ()
{
  mu_stream_t flt, trans[2];
  int rc;
  
  rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
  if (rc == 0)
    {
      char sessidstr[10];
      char *argv[] = { "inline-comment", NULL, "-S", NULL };

      snprintf (sessidstr, sizeof sessidstr, "%08lx:", mu_session_id);
      argv[1] = sessidstr;
      rc = mu_filter_create_args (&flt, trans[0], "inline-comment", 3,
				  (const char **)argv,
				  MU_FILTER_ENCODE, MU_STREAM_WRITE);
      mu_stream_unref (trans[0]);
      if (rc == 0)
	{
	  mu_stream_set_buffer (flt, mu_buffer_line, 0);
	  trans[0] = flt;
	  trans[1] = NULL;
	  rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM,
				MU_IOCTL_OP_SET, trans);
	  mu_stream_unref (trans[0]);
	  if (rc)
	    mu_error (_("%s failed: %s"), "MU_IOCTL_SET_STREAM",
		      mu_stream_strerror (mu_strerr, rc));
	}
      else
	mu_error (_("cannot create log filter stream: %s"), mu_strerror (rc));
    }
  else
    {
      mu_error (_("%s failed: %s"), "MU_IOCTL_GET_STREAM",
		mu_stream_strerror (mu_strerr, rc));
    }
  return rc;
}
Esempio n. 4
0
static void
clr_strerr_flt ()
{
  mu_stream_t flt, trans[2];
  int rc;

  rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
  if (rc == 0)
    {
      flt = trans[0];

      rc = mu_stream_ioctl (flt, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
      if (rc == 0)
	{
	  mu_stream_unref (trans[0]);
	  rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM,
				MU_IOCTL_OP_SET, trans);
	  if (rc == 0)
	    mu_stream_unref (flt);
	}
    }
}
Esempio n. 5
0
int
imap4d_init_tls_server ()
{
  mu_stream_t tlsstream, stream[2];
  int rc;

  rc = mu_stream_ioctl (iostream, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, stream);
  if (rc)
    {
      mu_error (_("%s failed: %s"), "MU_IOCTL_GET_STREAM",
		mu_stream_strerror (iostream, rc));
      return 1;
    }
  
  rc = mu_tls_server_stream_create (&tlsstream, stream[0], stream[1], 0);
  if (rc)
    {
      mu_diag_output (MU_DIAG_ERROR, _("cannot open TLS stream: %s"),
		      mu_stream_strerror (tlsstream, rc));
      return 1;
    }

  mu_stream_unref (stream[0]);
  mu_stream_unref (stream[1]);
  stream[0] = stream[1] = tlsstream;

  rc = mu_stream_ioctl (iostream, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_SET, stream);
  if (rc)
    {
      mu_error (_("%s failed: %s"), "MU_IOCTL_SET_STREAM",
		mu_stream_strerror (iostream, rc));
      imap4d_bye (ERR_STREAM_CREATE);
    }
  mu_stream_unref (stream[0]);
  mu_stream_unref (stream[1]);
  
  return 0;
}
Esempio n. 6
0
static int
_iostream_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
{
  struct _mu_iostream *sp = (struct _mu_iostream *)str;

  switch (code)
    {
    case MU_IOCTL_TRANSPORT:
      if (!arg)
	return EINVAL;
      else
	{
	  mu_transport_t *ptrans = arg;

	  switch (opcode)
	    {
	    case MU_IOCTL_OP_GET:
	      ptrans[0] = (mu_transport_t) sp->transport[_MU_STREAM_INPUT];
	      ptrans[1] = (mu_transport_t) sp->transport[_MU_STREAM_OUTPUT];
	      break;

	    case MU_IOCTL_OP_SET:
	      ptrans = arg;
	      sp->transport[_MU_STREAM_INPUT] = (mu_stream_t) ptrans[0];
	      sp->transport[_MU_STREAM_OUTPUT] = (mu_stream_t) ptrans[1];
	      break;

	    default:
	      return EINVAL;
	    }
	}
      break;

    case MU_IOCTL_SUBSTREAM:
    case MU_IOCTL_TOPSTREAM:
      if (!arg)
	return EINVAL;
      else
	{
	  mu_stream_t *pstr = arg;
	  switch (opcode)
	    {
	    case MU_IOCTL_OP_GET:
	      pstr[0] = sp->transport[0];
	      mu_stream_ref (pstr[0]);
	      pstr[1] = sp->transport[1];
	      mu_stream_ref (pstr[1]);
	      break;

	    case MU_IOCTL_OP_SET:
	      mu_stream_unref (sp->transport[0]);
	      sp->transport[0] = pstr[0];
	      mu_stream_ref (sp->transport[0]);
	      
	      mu_stream_unref (sp->transport[1]);
	      sp->transport[1] = pstr[1];
	      mu_stream_ref (sp->transport[1]);
	      break;

	    default:
	      return EINVAL;
	    }
	}
      break;

    case MU_IOCTL_TRANSPORT_BUFFER:
      if (!arg)
	return EINVAL;
      else
	{
	  struct mu_buffer_query *qp = arg;
	  if (!MU_TRANSPORT_VALID_TYPE (qp->type) || !sp->transport[qp->type])
	    return EINVAL;
	  return mu_stream_ioctl (sp->transport[qp->type], code, opcode, arg);
	}
      
    default:
      return ENOSYS;
    }
  return 0;
}