From 9700e3678e1a683c99291cd244f6370308bd5ff6 Mon Sep 17 00:00:00 2001 From: Michael Zucci Date: Tue, 17 May 2005 06:01:47 +0000 Subject: Initial work on hand-bindings for mono plugins svn path=/trunk/; revision=29375 --- plugins/mono/Camel.cs | 1223 +++++++++++++++++++++++++++++++++++++++++++++ plugins/mono/ChangeLog | 0 plugins/mono/Evolution.cs | 174 +++++++ 3 files changed, 1397 insertions(+) create mode 100644 plugins/mono/Camel.cs create mode 100644 plugins/mono/ChangeLog create mode 100644 plugins/mono/Evolution.cs (limited to 'plugins/mono') diff --git a/plugins/mono/Camel.cs b/plugins/mono/Camel.cs new file mode 100644 index 0000000000..d14158edfc --- /dev/null +++ b/plugins/mono/Camel.cs @@ -0,0 +1,1223 @@ + +using System; +using System.Collections; +using System.ComponentModel; +using System.Runtime.InteropServices; + +namespace Camel { + [StructLayout (LayoutKind.Sequential)] + public struct CamelException { + public int id; + public string desc; + } + + public class Arg { + public enum Tag : uint { + END = 0, + IGNORE = 1, + FIRST = 1024, + + TYPE = 0xf0000000, /* type field for tags */ + TAG = 0x0fffffff, /* tag field for args */ + + OBJ = 0x00000000, /* object */ + INT = 0x10000000, /* int */ + DBL = 0x20000000, /* double */ + STR = 0x30000000, /* c string */ + PTR = 0x40000000, /* ptr */ + BOO = 0x50000000 /* bool */ + } + } + + public class Exception : System.ApplicationException { + public enum Type { + NONE = 0, + SYSTEM = 1 + } + + public Type id; + public string desc; + + public Exception(CamelException ex) { + id = (Type)ex.id; + desc = ex.desc; + } + + public Exception(Type _id, string _desc) { + id = _id; + desc = _desc; + } + } + + public class Util { + [DllImport("camel-1.2")] static extern int camel_init(string certdir, bool nss); + + public static void Init(string certdir, bool nss) { + if (camel_init(certdir, nss) != 0) + throw new Exception(Exception.Type.SYSTEM, "Init failure"); + } + + public static string [] getUIDArray(IntPtr o) { + GPtrArray pa = (GPtrArray)Marshal.PtrToStructure(o, typeof(GPtrArray)); + string [] uids = new string[pa.len]; + + for (int i=0;i use StringBuilder + [DllImport("camel-1.2")] static extern IntPtr camel_url_decode(ref string url); + + public URL(string uri) { + CamelException ex = new CamelException(); + + cobject = camel_url_new(uri, ref ex); + if (ex.id != 0) + throw new Exception(ex); + } + + public URL(URL bbase, string uri) { + cobject = camel_url_new_with_base(bbase.cobject, uri); + } + + ~URL() { + camel_url_free(cobject); + } + + /* its ugly but it works */ + private string field(string name) { + return Marshal.PtrToStringAuto(Marshal.ReadIntPtr(cobject, (int)Marshal.OffsetOf(typeof(CamelURL), name))); + } + + public string protocol { + set { camel_url_set_protocol(cobject, value); } + get { return field("protocol"); } + } + + public string user { + set { camel_url_set_user(cobject, value); } + get { return field("user"); } + } + + public string authmech { + set { camel_url_set_authmech(cobject, value); } + get { return field("authmech"); } + } + + public string passwd { + set { camel_url_set_passwd(cobject, value); } + get { return field("passwd"); } + } + + public string host { + set { camel_url_set_host(cobject, value); } + get { return field("host"); } + } + + public int port { + set { camel_url_set_port(cobject, value); } + get { return (int)Marshal.ReadIntPtr(cobject, (int)Marshal.OffsetOf(typeof(CamelURL), "port")); } + } + + public string path { + set { camel_url_set_path(cobject, value); } + get { return field("path"); } + } + + public string query { + set { camel_url_set_query(cobject, value); } + get { return field("query"); } + } + + public string fragment { + set { camel_url_set_fragment(cobject, value); } + get { return field("fragment"); } + } + + public Params paramlist { + get { + if (param_list == null) + param_list = new Params(this); + return param_list; + } + } + + public override string ToString() { + return camel_url_to_string(cobject, 0); + } + + public static string encode(string val) { + return camel_url_encode(val, null); + } + + public static string encode(string val, string escape) { + return camel_url_encode(val, escape); + } + } +} + +namespace Camel.Hash { + public class Stream : System.IO.Stream { + protected Camel.Stream substream; + + public Stream(Camel.Stream sub) { + substream = sub; + } + + public override bool CanSeek { get { return false; } } + public override bool CanRead { get { return true; } } + public override bool CanWrite { get { return true; } } + public override long Length { + get { + throw new System.IO.IOException("Cannot get stream length"); + } + } + public override long Position { + get { + throw new System.IO.IOException("Cannot get stream position"); + } + set { + if (value == 0) { + substream.reset(); + } else { + throw new System.IO.IOException("Cannot set stream position"); + } + } + } + + public override int Read(byte[] buffer, int offset, int count) { + // FIXME: how to add the offset to the buffer? + return substream.read(buffer, count); + } + + public override void Write(byte[] buffer, int offset, int count) { + // FIXME: how to add the offset to the buffer? + substream.write(buffer, count); + } + + public override void Flush() { + substream.flush(); + } + + public override long Seek(long offset, System.IO.SeekOrigin seek) { + throw new System.IO.IOException("Seeking not supported"); + } + + public override void SetLength(long len) { + throw new System.IO.IOException("Cannot set stream length"); + } + } +} + +/* +namespace Evolution.Mail { + class Component : GLib.Object { + public Component(IntPtr raw) : base(raw) {} + public Component() : base() {} + + ~Component() { + Dispose(); + } + + [DllImport("libevolution-mail.so")] static extern IntPtr mail_component_peek(); + [DllImport("libevolution-mail.so")] static extern IntPtr mail_component_peek_base_directory(IntPtr component); + [DllImport("libevolution-mail.so")] static extern IntPtr mail_component_peek(); + + public static Component peek() { + return new Component(mail_component_peek()); + } + + public String baseDirectory { + get {} + } +} +*/ diff --git a/plugins/mono/ChangeLog b/plugins/mono/ChangeLog new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/mono/Evolution.cs b/plugins/mono/Evolution.cs new file mode 100644 index 0000000000..99772d8ca2 --- /dev/null +++ b/plugins/mono/Evolution.cs @@ -0,0 +1,174 @@ +using System; +using System.Runtime.InteropServices; +using System.Reflection; + +using Camel; + +[StructLayout (LayoutKind.Sequential)] +struct EMPopupTargetSelect { + int type; + int mask; + IntPtr parent; + IntPtr folder; + string folderURI; + IntPtr uids; +}; + +[StructLayout (LayoutKind.Sequential)] +struct EMPopupTargetFolder { + int type; + int mask; + IntPtr parent; + string folderURI; +}; + + +[StructLayout (LayoutKind.Sequential)] +struct aCamelObject { +IntPtr klass; +uint magic; +IntPtr hooks; +uint bitfield1; +// ref_count:24 +uint ref_count { // highly non-portable + get { return (bitfield1 & 0xffffff) >> 0; } + set { bitfield1 = (bitfield1 & 0xff000000) | ((value << 0) & 0xffffff); } +} +// flags:8 +uint flags { // highly non-portable + get { return (bitfield1 & 0xff000000) >> 24; } + set { bitfield1 = (bitfield1 & 0xffffff) | ((value << 24) & 0xff000000); } +} +IntPtr next; +IntPtr prev; +} + +namespace Evolution { + [StructLayout (LayoutKind.Sequential)] + public class PopupTarget { + public IntPtr popup; + public IntPtr widget; + public int type; + public int mask; + }; + + [StructLayout (LayoutKind.Sequential)] + public class MenuTarget { + public IntPtr menu; + public IntPtr widget; + public int type; + public int mask; + }; + + [StructLayout (LayoutKind.Sequential)] + public class EventTarget { + public IntPtr aevent; + public int type; + public int mask; + }; +}; + +namespace Evolution.Mail { + /* ********************************************************************** */ + [StructLayout (LayoutKind.Sequential)] + public class PopupTargetSelect : PopupTarget { + public IntPtr _folder; + public string uri; + public IntPtr _uids; + + public static PopupTargetSelect get(IntPtr o) { + return (PopupTargetSelect)Marshal.PtrToStructure(o, typeof(PopupTargetSelect)); + } + + public Camel.Folder folder { + get { return (Camel.Folder)Camel.Object.fromCamel(_folder); } + } + + public string [] uids { + get { return Camel.Util.getUIDArray(_uids); } + } + } + + [StructLayout (LayoutKind.Sequential)] + public class PopupTargetURI : Evolution.PopupTarget { + public string uri; + + public static PopupTargetURI get(IntPtr o) { + return (PopupTargetURI)Marshal.PtrToStructure(o, typeof(PopupTargetURI)); + } + } + + [StructLayout (LayoutKind.Sequential)] + public class PopupTargetPart : PopupTarget { + public string mimeType; + public IntPtr _part; + + public static PopupTargetPart get(IntPtr o) { + return (PopupTargetPart)Marshal.PtrToStructure(o, typeof(PopupTargetPart)); + } + + public Camel.Object part { + get { return (Camel.Object)Camel.Object.fromCamel(_part); } + } + } + + [StructLayout (LayoutKind.Sequential)] + public struct PopupTargetFolder { + public Evolution.PopupTarget target; + public string uri; + + public static PopupTargetFolder get(IntPtr o) { + return (PopupTargetFolder)Marshal.PtrToStructure(o, typeof(PopupTargetFolder)); + } + } + + /* ********************************************************************** */ + [StructLayout (LayoutKind.Sequential)] + public class MenuTargetSelect : MenuTarget { + public IntPtr _folder; + public string uri; + public IntPtr _uids; + + public static MenuTargetSelect get(IntPtr o) { + return (MenuTargetSelect)Marshal.PtrToStructure(o, typeof(MenuTargetSelect)); + } + + public Camel.Folder folder { + get { return (Camel.Folder)Camel.Object.fromCamel(_folder); } + } + + public string [] uids { + get { return Camel.Util.getUIDArray(_uids); } + } + } + + /* ********************************************************************** */ + [StructLayout (LayoutKind.Sequential)] + public class EventTargetFolder : EventTarget { + public string uri; + + public static EventTargetFolder get(IntPtr o) { + return (EventTargetFolder)Marshal.PtrToStructure(o, typeof(EventTargetFolder)); + } + } + + [StructLayout (LayoutKind.Sequential)] + public class EventTargetMessage : EventTarget { + public IntPtr _folder; + public string uid; + public IntPtr _message; + + public static EventTargetMessage get(IntPtr o) { + return (EventTargetMessage)Marshal.PtrToStructure(o, typeof(EventTargetMessage)); + } + + public Camel.Folder folder { + get { return (Camel.Folder)Camel.Object.fromCamel(_folder); } + } + + public Camel.MimeMessage message { + get { return (Camel.MimeMessage)Camel.Object.fromCamel(_message); } + } + + } +}; -- cgit v1.2.3