Sun Aug 24 23:35:19 CEST 2003 Jochen Eisinger <c0ffee@penguin-breeder.org>
authorJochen Eisinger <coffee@silcnet.org>
Sun, 24 Aug 2003 21:42:16 +0000 (21:42 +0000)
committerJochen Eisinger <coffee@silcnet.org>
Sun, 24 Aug 2003 21:42:16 +0000 (21:42 +0000)
* Provide a signal handler to send MIME encoded messages and emit
  a signal when a MIME encoded message is received. Also document
  the signals for usage with the perl interface.

  A sample perl script will be supplied at a later point.

  Affected files are irssi/docs/signals.txt,
  irssi/src/silc/core/client_ops.[ch],
  irssi/src/silc/core/silc-{channels,servers}.c

CHANGES
apps/irssi/docs/signals.txt
apps/irssi/src/silc/core/client_ops.c
apps/irssi/src/silc/core/client_ops.h
apps/irssi/src/silc/core/silc-channels.c
apps/irssi/src/silc/core/silc-servers.c

diff --git a/CHANGES b/CHANGES
index da247f3cdd3b5fb2541c8bc58907e766cab69902..49395ce6db9adae84f7590d2e22d57b4ffa57fe5 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,15 @@
+Sun Aug 24 23:35:19 CEST 2003  Jochen Eisinger <c0ffee@penguin-breeder.org>
+
+       * Provide a signal handler to send MIME encoded messages and emit
+         a signal when a MIME encoded message is received. Also document
+         the signals for usage with the perl interface.
+
+         A sample perl script will be supplied at a later point.
+
+         Affected files are irssi/docs/signals.txt, 
+         irssi/src/silc/core/client_ops.[ch], 
+         irssi/src/silc/core/silc-{channels,servers}.c
+
 Sun Aug 24 12:58:30 CEST 2003  Jochen Eisinger <c0ffee@penguin-breeder.org>
 
        * Use SILC_COMMAND_PING to estimate the round-trip time to the
index df582873684ceb8a2429812ddff940d0398c4337..7c03fad5584641bfe80fffb6bdbef06bff5a85f5 100644 (file)
@@ -324,3 +324,12 @@ gui-readline.c:
 
 gui-printtext.c:
  "beep"
+
+SILC
+---
+
+silc-channels.c:
+ "mime", SERVER_REC, CHANNEL_REC, char *blob, char *enc, char *type, char *nick
+
+silc-servers.c:
+ "mime-send", SERVER_REC, WI_ITEM_REC, char *blob, char *enc, char *type
index a087f47ad4d918eba0c5ee069cc8ff66ca17636c..dfa69c9887897752fb7c4b949166673c3e2534fc 100644 (file)
@@ -288,6 +288,68 @@ int verify_message_signature(SilcClientEntry sender,
   return ret;
 }
 
+char * silc_unescape_data(const char *escaped_data, SilcUInt32 *length)
+{
+  SilcUInt32 ctr, dest=0;
+  char *data;
+
+  data = silc_calloc(strlen(escaped_data), sizeof(char));
+  
+  for (ctr = 0; ctr < strlen(escaped_data); ctr++)
+    if (escaped_data[ctr] == 1)
+      data[dest++] = escaped_data[++ctr] - 1;
+    else
+      data[dest++] = escaped_data[ctr];
+
+  *length = dest;
+  return data;
+}
+
+char * silc_escape_data(const char *data, SilcUInt32 len)
+{
+  char *escaped_data;
+  SilcUInt32 ctr, zeros=0;
+
+  for (ctr = 0; ctr < len; ctr++)
+    if (data[ctr] == 0 || data[ctr] == 1)
+      zeros++;
+
+  escaped_data = silc_calloc(zeros + len, sizeof(char));
+
+  zeros=0;
+  for (ctr = 0; ctr < len; ctr++)
+    switch (data[ctr]) {
+      case 0:
+       escaped_data[zeros++] = 1;
+       escaped_data[zeros++] = 1;
+       break;
+
+      case 1:
+       escaped_data[zeros++] = 1;
+       escaped_data[zeros++] = 2;
+       break;
+
+      default:
+       escaped_data[zeros++] = data[ctr];
+    } 
+
+    return escaped_data;
+}
+
+void silc_emit_mime_sig(SILC_SERVER_REC *server, SILC_CHANNEL_REC *channel,
+               const char *data, SilcUInt32 data_len,
+               const char *encoding, const char *type, const char *nick)
+{
+   char *escaped_data;
+
+   escaped_data = silc_escape_data(data, data_len);
+
+   signal_emit("mime", 6, server, channel, escaped_data, encoding, type, nick);
+   silc_free(escaped_data);
+}
+
+
 /* Message for a channel. The `sender' is the nickname of the sender
    received in the packet. The `channel_name' is the name of the channel. */
 
@@ -348,9 +410,8 @@ void silc_channel_message(SilcClient client, SilcClientConnection conn,
       /* It is something textual, display it */
       message = (const unsigned char *)data;
     } else {
-      printformat_module("fe-common/silc", server, channel->channel_name,
-                        MSGLEVEL_CRAP, SILCTXT_MESSAGE_DATA,
-                        nick == NULL ? "[<unknown>]" : nick->nick, type);
+      silc_emit_mime_sig(server, chanrec, data, data_len,
+               enc, type, nick == NULL ? NULL : nick->nick);
       message = NULL;
     }
   }
@@ -457,10 +518,8 @@ void silc_private_message(SilcClient client, SilcClientConnection conn,
       /* It is something textual, display it */
       message = (const unsigned char *)data;
     } else {
-      printformat_module("fe-common/silc", server, NULL,
-                        MSGLEVEL_CRAP, SILCTXT_MESSAGE_DATA,
-                        sender->nickname ? sender->nickname : "[<unknown>]",
-                        type);
+      silc_emit_mime_sig(server, NULL, data, data_len,
+                       enc, type, sender->nickname);
       message = NULL;
     }
   }
index 8c3f7630e0d5d6236496b7c196fa561c8c56e7dc..31f5ad2989bc03af515ee948be049a5af09ec0eb 100644 (file)
@@ -70,5 +70,9 @@ void silc_ftp(SilcClient client, SilcClientConnection conn,
 void
 silc_detach(SilcClient client, SilcClientConnection conn,
             const unsigned char *detach_data, SilcUInt32 detach_data_len);
+char *
+silc_unescape_data(const char *escaped_data, SilcUInt32 *length);
+char * 
+silc_escape_data(const char *data, SilcUInt32 len);
 
 #endif
index e28768bdb7bee005437df383e98ec901c0c681c0..72cca3a3a90bf1d02f305b2191f1ce7d82960650 100644 (file)
 
 #include "silc-commands.h"
 
+void sig_mime(SILC_SERVER_REC *server, SILC_CHANNEL_REC *channel,
+               const char *blob, const char *enc, const char *type,
+               const char *nick)
+{
+
+  if (!(IS_SILC_SERVER(server)))
+    return;
+  
+  printformat_module("fe-common/silc", server, 
+                        channel == NULL ? NULL : channel->name,
+                        MSGLEVEL_CRAP, SILCTXT_MESSAGE_DATA,
+                        nick == NULL ? "[<unknown>]" : nick, type);
+
+}
+
 SILC_CHANNEL_REC *silc_channel_create(SILC_SERVER_REC *server,
                                      const char *name,
                                      const char *visible_name,
@@ -1007,6 +1022,7 @@ void silc_channels_init(void)
   signal_add("server connected", (SIGNAL_FUNC) sig_connected);
   signal_add("server quit", (SIGNAL_FUNC) sig_server_quit);
   signal_add("gui exit", (SIGNAL_FUNC) sig_gui_quit);
+  signal_add("mime", (SIGNAL_FUNC) sig_mime);
 
   command_bind_silc("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
   command_bind_silc("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
@@ -1025,6 +1041,7 @@ void silc_channels_deinit(void)
   signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
   signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit);
   signal_remove("gui exit", (SIGNAL_FUNC) sig_gui_quit);
+  signal_remove("mime", (SIGNAL_FUNC) sig_mime);
 
   command_unbind("part", (SIGNAL_FUNC) command_part);
   command_unbind("me", (SIGNAL_FUNC) command_me);
index bf091268d2f2b3dc9a73acc61fed9e367caa84e1..808941d46de1e884190748850cbd5253608266f8 100644 (file)
@@ -175,11 +175,13 @@ static int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg,
 }
 
 void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
-                   const char *data, int data_len,
+                   const char *data,
                    const char *enc, const char *type)
 {
   SILC_CHANNEL_REC *channel;
   QUERY_REC *query;
+  char *unescaped_data;
+  int unescaped_data_len;
   char *mime_data;
   int mime_data_len;
 
@@ -187,9 +189,11 @@ void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
       (enc == NULL) || (type == NULL))
     return;
 
+  unescaped_data = silc_unescape_data(data, &unescaped_data_len);
+
 #define SILC_MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: %s\r\nContent-Transfer-Encoding: %s\r\n\r\n"
 
-  mime_data_len = data_len + strlen(SILC_MIME_HEADER) - 4
+  mime_data_len = unescaped_data_len + strlen(SILC_MIME_HEADER) - 4
     + strlen(enc) + strlen(type);
   if (mime_data_len >= SILC_PACKET_MAX_LEN)
     return;
@@ -198,7 +202,7 @@ void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
   mime_data = silc_calloc(mime_data_len, sizeof(*mime_data));
   snprintf(mime_data, mime_data_len, SILC_MIME_HEADER, type, enc);
   memmove(mime_data + strlen(SILC_MIME_HEADER) - 4 + strlen(enc) + strlen(type),
-         data, data_len);
+         unescaped_data, unescaped_data_len);
 
 #undef SILC_MIME_HEADER
 
@@ -215,6 +219,7 @@ void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to,
   }
 
   silc_free(mime_data);
+  silc_free(unescaped_data);
 }
 
 static int isnickflag_func(char flag)