X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fnntp%2Fserv_nntp.c;h=db3e1dc22d6afe9f7db612f30e4af373ab4ccbbf;hb=6ea59f0428823b216cd1a6f19116a9147e97191b;hp=e4897d6c3f3bbfe160729cc252debb3da5d91718;hpb=0adb29d5fa73df9c3760478405aaf71fa37054c4;p=citadel.git diff --git a/citadel/modules/nntp/serv_nntp.c b/citadel/modules/nntp/serv_nntp.c index e4897d6c3..db3e1dc22 100644 --- a/citadel/modules/nntp/serv_nntp.c +++ b/citadel/modules/nntp/serv_nntp.c @@ -1,5 +1,5 @@ // -// NNTP server module FIXME THIS IS NOT FINISHED +// NNTP server module (RFC 3977) // // Copyright (c) 2014 by the citadel.org team // @@ -960,6 +960,52 @@ void nntp_last_next(const char *cmd) { } +// +// back end for the XOVER command , called for each message number +// +void nntp_xover_backend(long msgnum, void *userdata) { + + struct listgroup_range *lr = (struct listgroup_range *)userdata; + + // check range if supplied + if (msgnum < lr->lo) return; + if ((lr->hi != 0) && (msgnum > lr->hi)) return; + + struct CtdlMessage *msg = CtdlFetchMessage(msgnum, 0); + if (msg == NULL) { + return; + } + + // Teh RFC says we need: + // ------------------------- + // Subject header content + // From header content + // Date header content + // Message-ID header content + // References header content + // :bytes metadata item + // :lines metadata item + + time_t msgtime = atol(msg->cm_fields[eTimestamp]); + char strtimebuf[26]; + ctime_r(&msgtime, strtimebuf); + + // here we go -- print the line o'data + cprintf("%ld\t%s\t%s <%s>\t%s\t%s\t%s\t100\t10\r\n", + msgnum, + msg->cm_fields[eMsgSubject], + msg->cm_fields[eAuthor], + msg->cm_fields[erFc822Addr], + strtimebuf, + msg->cm_fields[emessageId], + msg->cm_fields[eWeferences] + ); + + CM_Free(msg); +} + + +// // // XOVER is used by some clients, even if we don't offer it // @@ -968,33 +1014,34 @@ void nntp_xover(const char *cmd) { citnntp *nntpstate = (citnntp *) CC->session_specific_data; char range[256]; - long lowest = (-1) ; - long highest = (-1) ; + struct listgroup_range lr; extract_token(range, cmd, 1, ' ', sizeof range); - lowest = atol(range); - if (lowest <= 0) { - lowest = nntpstate->current_article_number; - highest = nntpstate->current_article_number; + lr.lo = atol(range); + if (lr.lo <= 0) { + lr.lo = nntpstate->current_article_number; + lr.hi = nntpstate->current_article_number; } else { char *dash = strchr(range, '-'); if (dash != NULL) { ++dash; - highest = atol(dash); - if (highest == 0) { - highest = LONG_MAX; + lr.hi = atol(dash); + if (lr.hi == 0) { + lr.hi = LONG_MAX; } - if (highest < lowest) { - highest = lowest; + if (lr.hi < lr.lo) { + lr.hi = lr.lo; } } else { - highest = lowest; + lr.hi = lr.lo; } } - cprintf("500 not implemented yet FIXME lowest=%ld highest=%ld\r\n", lowest, highest); + cprintf("224 Overview information follows\r\n"); + CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL, nntp_xover_backend, &lr); + cprintf(".\r\n"); }