From: Art Cancro Date: Mon, 11 Aug 2008 19:57:40 +0000 (+0000) Subject: The CtdlWriteObject() API no longer uses a temp file X-Git-Tag: v7.86~2041 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=6eb43187a82c686ce1855d15b7ba8485d1c461bb The CtdlWriteObject() API no longer uses a temp file --- diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index b14177888..41bedf026 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -105,8 +105,6 @@ icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) { * to the currently selected room. */ void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) { - char temp[PATH_MAX]; - FILE *fp = NULL; char *ser = NULL; icalcomponent *encaps = NULL; struct CtdlMessage *msg = NULL; @@ -131,24 +129,16 @@ void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) { /* If the caller supplied a user, write to that user's default calendar room */ if (u) { - /* Make a temp file out of it */ - CtdlMakeTempFileName(temp, sizeof temp); - fp = fopen(temp, "w"); - if (fp != NULL) { - fwrite(ser, strlen(ser), 1, fp); - fclose(fp); - - /* This handy API function does all the work for us. */ - CtdlWriteObject(USERCALENDARROOM, /* which room */ - "text/calendar", /* MIME type */ - temp, /* temp file */ - u, /* which user */ - 0, /* not binary */ - 0, /* don't delete others of this type */ - 0 /* no flags */ - ); - unlink(temp); - } + /* This handy API function does all the work for us. */ + CtdlWriteObject(USERCALENDARROOM, /* which room */ + "text/calendar", /* MIME type */ + ser, /* data */ + strlen(ser)+1, /* length */ + u, /* which user */ + 0, /* not binary */ + 0, /* don't delete others of this type */ + 0 /* no flags */ + ); } /* If the caller did not supply a user, write to the currently selected room */ diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index 05fbccea1..2fb909784 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -254,20 +254,12 @@ void populate_vcard_from_sreg(HashList *sreg_keys) { /* Only save the vCard if there is some useful data in it */ if (pop > 0) { - char temp[PATH_MAX]; - FILE *fp; char *ser; - - CtdlMakeTempFileName(temp, sizeof temp); ser = vcard_serialize(v); if (ser) { - fp = fopen(temp, "w"); - if (fp) { - fwrite(ser, strlen(ser), 1, fp); - fclose(fp); - CtdlWriteObject(USERCONFIGROOM, "text/x-vcard", temp, &CC->user, 0, 0, 0); - unlink(temp); - } + CtdlWriteObject(USERCONFIGROOM, "text/x-vcard", + ser, strlen(ser)+1, &CC->user, 0, 0, 0 + ); free(ser); } } diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index 2f126f408..a6f6f9d51 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -794,22 +794,13 @@ struct vCard *vcard_get_user(struct ctdluser *u) { * Write our config to disk */ void vcard_write_user(struct ctdluser *u, struct vCard *v) { - char temp[PATH_MAX]; - FILE *fp; char *ser; - CtdlMakeTempFileName(temp, sizeof temp); ser = vcard_serialize(v); - - fp = fopen(temp, "w"); - if (fp == NULL) return; if (ser == NULL) { - fprintf(fp, "begin:vcard\r\nend:vcard\r\n"); - } else { - fwrite(ser, strlen(ser), 1, fp); - free(ser); + ser = strdup("begin:vcard\r\nend:vcard\r\n"); } - fclose(fp); + if (!ser) return; /* This handy API function does all the work for us. * NOTE: normally we would want to set that last argument to 1, to @@ -817,15 +808,16 @@ void vcard_write_user(struct ctdluser *u, struct vCard *v) { * have to, because the vcard_upload_beforesave() hook above * is going to notice what we're trying to do, and delete the old vCard. */ - CtdlWriteObject(USERCONFIGROOM, /* which room */ - VCARD_MIME_TYPE,/* MIME type */ - temp, /* temp file */ - u, /* which user */ - 0, /* not binary */ - 0, /* don't delete others of this type */ - 0); /* no flags */ - - unlink(temp); + CtdlWriteObject(USERCONFIGROOM, /* which room */ + VCARD_MIME_TYPE, /* MIME type */ + ser, /* data */ + strlen(ser)+1, /* length */ + u, /* which user */ + 0, /* not binary */ + 0, /* don't delete others of this type */ + 0); /* no flags */ + + free(ser); } diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 6dedd7ee3..ccee9818d 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -4424,24 +4424,21 @@ void TDAP_AdjRefCount(long msgnum, int incr) * Note: this could be much more efficient. Right now we use two temporary * files, and still pull the message into memory as with all others. */ -void CtdlWriteObject(char *req_room, /* Room to stuff it in */ - char *content_type, /* MIME type of this object */ - char *tempfilename, /* Where to fetch it from */ +void CtdlWriteObject(char *req_room, /* Room to stuff it in */ + char *content_type, /* MIME type of this object */ + char *raw_message, /* Data to be written */ + off_t raw_length, /* Size of raw_message */ struct ctdluser *is_mailbox, /* Mailbox room? */ - int is_binary, /* Is encoding necessary? */ - int is_unique, /* Del others of this type? */ - unsigned int flags /* Internal save flags */ + int is_binary, /* Is encoding necessary? */ + int is_unique, /* Del others of this type? */ + unsigned int flags /* Internal save flags */ ) { - FILE *fp; struct ctdlroom qrbuf; char roomname[ROOMNAMELEN]; struct CtdlMessage *msg; - - char *raw_message = NULL; char *encoded_message = NULL; - off_t raw_length = 0; if (is_mailbox != NULL) { MailboxName(roomname, sizeof roomname, is_mailbox, req_room); @@ -4450,24 +4447,10 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ safestrncpy(roomname, req_room, sizeof(roomname)); } - fp = fopen(tempfilename, "rb"); - if (fp == NULL) { - CtdlLogPrintf(CTDL_CRIT, "Cannot open %s: %s\n", - tempfilename, strerror(errno)); - return; - } - fseek(fp, 0L, SEEK_END); - raw_length = ftell(fp); - rewind(fp); CtdlLogPrintf(CTDL_DEBUG, "Raw length is %ld\n", (long)raw_length); - raw_message = malloc((size_t)raw_length + 2); - fread(raw_message, (size_t)raw_length, 1, fp); - fclose(fp); - if (is_binary) { - encoded_message = malloc((size_t) - (((raw_length * 134) / 100) + 4096 ) ); + encoded_message = malloc((size_t) (((raw_length * 134) / 100) + 4096 ) ); } else { encoded_message = malloc((size_t)(raw_length + 4096)); @@ -4495,7 +4478,6 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ ); } else { - raw_message[raw_length] = 0; memcpy( &encoded_message[strlen(encoded_message)], raw_message, @@ -4503,8 +4485,6 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ ); } - free(raw_message); - CtdlLogPrintf(CTDL_DEBUG, "Allocating\n"); msg = malloc(sizeof(struct CtdlMessage)); memset(msg, 0, sizeof(struct CtdlMessage)); @@ -4594,20 +4574,9 @@ char *CtdlGetSysConfig(char *sysconfname) { return(conf); } -void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) { - char temp[PATH_MAX]; - FILE *fp; - - CtdlMakeTempFileName(temp, sizeof temp); - fp = fopen(temp, "w"); - if (fp == NULL) return; - fprintf(fp, "%s", sysconfdata); - fclose(fp); - - /* this handy API function does all the work for us */ - CtdlWriteObject(SYSCONFIGROOM, sysconfname, temp, NULL, 0, 1, 0); - unlink(temp); +void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) { + CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0); } diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 754656d58..560977361 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -119,8 +119,15 @@ int CtdlForEachMessage(int mode, void (*CallBack) (long, void *), void *userdata); int CtdlDeleteMessages(char *, long *, int, char *); -void CtdlWriteObject(char *, char *, char *, struct ctdluser *, - int, int, unsigned int); +void CtdlWriteObject(char *req_room, /* Room to stuff it in */ + char *content_type, /* MIME type of this object */ + char *raw_message, /* Data to be written */ + off_t raw_length, /* Size of raw_message */ + struct ctdluser *is_mailbox, /* Mailbox room? */ + int is_binary, /* Is encoding necessary? */ + int is_unique, /* Del others of this type? */ + unsigned int flags /* Internal save flags */ +); struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body); void CtdlFreeMessage(struct CtdlMessage *msg); void serialize_message(struct ser_ret *, struct CtdlMessage *);