+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
}
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);
struct NetprocFunctionHook *NetprocHookTable = NULL;
struct DeleteFunctionHook *DeleteHookTable = NULL;
struct ServiceFunctionHook *ServiceHookTable = NULL;
+struct FixedOutputHook *FixedOutputTable = NULL;
struct ProtoFunctionHook {
void (*handler) (char *cmdbuf);
}
+
+
+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)
{
+
+
int PerformXmsgHooks(char *sender, char *recp, char *msg)
{
struct XmsgFunctionHook *fcn;
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 */
}
+/*
+ * 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;
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);
};
extern struct CleanupFunctionHook *CleanupHookTable;
+struct FixedOutputHook {
+ struct FixedOutputHook *next;
+ char content_type[64];
+ void (*h_function_pointer) (char *, int);
+};
+extern struct FixedOutputHook *FixedOutputTable;