* New type of server hook: CtdlRegisterFixedOutputHook(). This is for
authorArt Cancro <ajc@citadel.org>
Wed, 19 Oct 2005 17:32:55 +0000 (17:32 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 19 Oct 2005 17:32:55 +0000 (17:32 +0000)
  extending the fixed_output() function for arbitrary new MIME types.  The
  usefulness of this for end users is limited, since no clients use MSG0
  anymore.  The real purpose of converting various MIME types to text is to
  make them visible to the full text indexer.
* serv_vcard.c: registered a fixed output hook for text/x-vcard.
:

citadel/ChangeLog
citadel/msgbase.c
citadel/serv_extensions.c
citadel/serv_extensions.h
citadel/serv_vcard.c
citadel/server.h

index 2b8294a26c627985d8b7654d7690ad2428d28ede..78ec35ca78ed7d65bbe3d454e84e78578812e767 100644 (file)
@@ -1,3 +1,11 @@
+Wed Oct 19 13:30:16 EDT 2005 ajc
+* New type of server hook: CtdlRegisterFixedOutputHook().  This is for
+  extending the fixed_output() function for arbitrary new MIME types.  The
+  usefulness of this for end users is limited, since no clients use MSG0
+  anymore.  The real purpose of converting various MIME types to text is to
+  make them visible to the full text indexer.
+* serv_vcard.c: registered a fixed output hook for text/x-vcard.
+
 Tue Oct 18 22:46:41 EDT 2005 Art Cancro <ajc@uncensored.citadel.org>
 * msgbase.c, messages.c, html.c: conversion of HTML to plain text now accepts
   a maximum source length.  MSG0 output of multipart messages was running
index 217c045c49d18d2f756dc8b9798677315baa915d..cf9f72d30b1fb6e3d6f78e612a957bce0fbc1fe7 100644 (file)
@@ -1140,6 +1140,9 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp,
                }
                free(ptr);
        }
+       else if (PerformFixedOutputHooks(cbtype, content, length)) {
+               /* above function returns nonzero if it handled the part */
+       }
        else if (strncasecmp(cbtype, "multipart/", 10)) {
                cprintf("Part %s: %s (%s) (%ld bytes)\r\n",
                        partnum, filename, cbtype, (long)length);
index e5cf68524315533a7c25f154660bee8f915005eb..f2b0c78d4e2f33edf8400d5354b420e03db99593 100644 (file)
@@ -36,6 +36,7 @@ struct MessageFunctionHook *MessageHookTable = NULL;
 struct NetprocFunctionHook *NetprocHookTable = NULL;
 struct DeleteFunctionHook *DeleteHookTable = NULL;
 struct ServiceFunctionHook *ServiceHookTable = NULL;
+struct FixedOutputHook *FixedOutputTable = NULL;
 
 struct ProtoFunctionHook {
        void (*handler) (char *cmdbuf);
@@ -351,6 +352,60 @@ void CtdlUnregisterDeleteHook(void (*handler)(char *, long) )
 }
 
 
+
+
+void CtdlRegisterFixedOutputHook(char *content_type, void (*handler)(char *, int) )
+{
+       struct FixedOutputHook *newfcn;
+
+       newfcn = (struct FixedOutputHook *)
+           malloc(sizeof(struct FixedOutputHook));
+       newfcn->next = FixedOutputTable;
+       newfcn->h_function_pointer = handler;
+       safestrncpy(newfcn->content_type, content_type, sizeof newfcn->content_type);
+       FixedOutputTable = newfcn;
+
+       lprintf(CTDL_INFO, "Registered a new fixed output function for %s\n", newfcn->content_type);
+}
+
+
+void CtdlUnregisterFixedOutputHook(char *content_type)
+{
+       struct FixedOutputHook *cur, *p;
+
+       for (cur = FixedOutputTable; cur != NULL; cur = cur->next) {
+               /* This will also remove duplicates if any */
+               while (cur != NULL && (!strcasecmp(content_type, cur->content_type))) {
+                       lprintf(CTDL_INFO, "Unregistered fixed output function for %s\n", content_type);
+                       p = cur->next;
+                       if (cur == FixedOutputTable) {
+                               FixedOutputTable = p;
+                       }
+                       free(cur);
+                       cur = p;
+               }
+       }
+}
+
+/* returns nonzero if we found a hook and used it */
+int PerformFixedOutputHooks(char *content_type, char *content, int content_length)
+{
+       struct FixedOutputHook *fcn;
+
+       for (fcn = FixedOutputTable; fcn != NULL; fcn = fcn->next) {
+               lprintf(CTDL_DEBUG, "comparing %s to %s\n", content_type, fcn->content_type);
+               if (!strcasecmp(content_type, fcn->content_type)) {
+                       (*fcn->h_function_pointer) (content, content_length);
+                       return(1);
+               }
+       }
+       return(0);
+}
+
+
+
+
+
 void CtdlRegisterXmsgHook(int (*fcn_ptr) (char *, char *, char *), int order)
 {
 
@@ -556,6 +611,8 @@ void PerformDeleteHooks(char *room, long msgnum)
 
 
 
+
+
 int PerformXmsgHooks(char *sender, char *recp, char *msg)
 {
        struct XmsgFunctionHook *fcn;
index a3974ecaed36fafb31ff55ad6e562dd1d094cedb..9b669783993185d522258016a622dadb499341f0 100644 (file)
@@ -79,12 +79,18 @@ void CtdlRegisterServiceHook(int tcp_port,
                         void (*h_greeting_function) (void),
                         void (*h_command_function) (void),
                         void (*h_async_function) (void)
-       ) ;
+);
 void CtdlUnregisterServiceHook(int tcp_port,
                        char *sockpath,
                         void (*h_greeting_function) (void),
                         void (*h_command_function) (void),
                         void (*h_async_function) (void)
-       ) ;
+);
+
+void CtdlRegisterFixedOutputHook(char *content_type,
+                       void (*output_function) (char *supplied_data, int len)
+);
+void CtdlUnRegisterFixedOutputHook(char *content_type);
+int PerformFixedOutputHooks(char *, char *, int);
 
 #endif /* SERV_EXTENSIONS_H */
index 0c35d8c188996f55a01be54da04457790d44b85b..a106a872f3a4ba7669ecc1cd8a70bc419faf5d72 100644 (file)
@@ -1064,6 +1064,33 @@ void store_harvested_addresses(void) {
 }
 
 
+/* 
+ * Function to output a vCard as plain text.  Nobody uses MSG0 anymore, so
+ * really this is just so we expose the vCard data to the full text indexer.
+ */
+void vcard_fixed_output(char *ptr, int len) {
+       char *serialized_vcard;
+       struct vCard *v;
+       char *key, *value;
+       int i = 0;
+
+       cprintf("vCard:\n");
+       serialized_vcard = malloc(len + 1);
+       safestrncpy(serialized_vcard, ptr, len+1);
+       v = vcard_load(serialized_vcard);
+       free(serialized_vcard);
+
+       i = 0;
+       while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
+               value = vcard_get_prop(v, "", 0, i++, 0);
+               cprintf("%20s : %s\n", key, value);
+       }
+
+       vcard_free(v);
+}
+
+
+
 char *serv_vcard_init(void)
 {
        struct ctdlroom qr;
@@ -1081,6 +1108,7 @@ char *serv_vcard_init(void)
        CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER);
        CtdlRegisterNetprocHook(vcard_extract_from_network);
        CtdlRegisterSessionHook(store_harvested_addresses, EVT_TIMER);
+       CtdlRegisterFixedOutputHook("text/x-vcard", vcard_fixed_output);
 
        /* Create the Global ADdress Book room if necessary */
        create_room(ADDRESS_BOOK_ROOM, 3, "", 0, 1, 0, VIEW_ADDRESSBOOK);
index 06b48fc20edc5a63c3dc4ae645f4bf6157d75322..610de480d7cefa5e825dae646533e44476f50ecd 100644 (file)
@@ -289,6 +289,12 @@ struct CleanupFunctionHook {
 };
 extern struct CleanupFunctionHook *CleanupHookTable;
 
+struct FixedOutputHook {
+       struct FixedOutputHook *next;
+       char content_type[64];
+       void (*h_function_pointer) (char *, int);
+};
+extern struct FixedOutputHook *FixedOutputTable;