/* FARGOS Development, LLC Sample Programs Copyright (C) 2002 FARGOS Development, LLC. All rights reserved. mailto:support@fargos.net for assistance. NOTE: in the future, enhanced versions of these classes may be added to the FARGOS/VISTA Object Management Environment core within the Standard namespace. Developers can avoid any potential conflict if they specify an explicit namespace when creating instances of the sample classes. */ %include implicit { const string NEWSGROUP_SERVICE = "NewsgroupDirectory"; }; class Local . NNTPnewsgroupService { assoc newsgroupNameToDB; } inherits from Object; NNTPnewsgroupService:create() { call "NNTPnewsgroupService:initialize"(arrayToSet(argv)); } NNTPnewsgroupService:delete() { unregisterService(NEWSGROUP_SERVICE, thisObject); } NNTPnewsgroupService:initialize() { // TO DO: use oid that only permits lookup/register operations registerService(NEWSGROUP_SERVICE, thisObject, 0); } NNTPnewsgroupService:registerNewsgroup(string newsgroupName, oid newsgroup) { string bracketKey; if (indexExists(newsgroupNameToDB, newsgroupName) != 0) { return (-1); } newsgroupNameToDB[newsgroupName] = newsgroup; return (0); } NNTPnewsgroupService:unregisterNewsgroup(string newsgroupName, oid newsgroup) { string bracketKey; if (indexExists(newsgroupNameToDB, newsgroupName) == 0) { display("newsgroup name not known=", newsgroupName, "\n"); return (-1); } newsgroupNameToDB = deleteIndex(newsgroupNameToDB, newsgroupName); return (0); } NNTPnewsgroupService:findNewsgroup(string newsgroupName) { string name; if (indexExists(newsgroupNameToDB, newsgroupName) != 0) { return (newsgroupNameToDB[newsgroupName]); } return (nil); } NNTPnewsgroupService:registerArticle(string newsgroupName, oid articleObj, string messageId, int messTime) { // TO DO: auto create NNTPnewsgroup object, if necessary // perform registerArticle() against newsgroup } NNTPnewsgroupService:listNewsgroups(optional string filter1, optional string filter2) { assoc result; set wildcards; int count, i, rc, negate; string s, key1, key2; if (argc == 0) return (newsgroupNameToDB); // fast path if (filter1 == "*") return (newsgroupNameToDB); // fast path for(i=0;i 0; id -= 1) { if (indexExists(articles, id) != 0) { // found info[0] = articles[id][0]; info[1] = id; info[2] = articles[id][1]; return (info); } } return (nil); } NNTPnewsgroup:findArticleAfter(int articleId) { int id; array info; id = nextIndex(articles, articleId); if (indexExists(articles, id) != 0) { // found info[0] = articles[id][0]; info[1] = id; info[2] = articles[id][1]; return (info); } return (nil); } NNTPnewsgroup:getNewsgroupInfo() { assoc attrs; int first; first = nextIndex(articles, 0); if (first == 0) first = 1; // first > last ==> no articles attrs["newsgroupName"] = newsgroupName; attrs["firstArticle"] = first; attrs["lastArticle"] = lastArticle; attrs["articleCount"] = elementCount(articles); attrs["postingOK"] = postingOK; attrs["createTime"] = creationTime; attrs["description"] = newsgroupDescription; return (attrs); } NNTPnewsgroup:getMessageIds(optional int t) { int i, count; array result; for(i=nextIndex(articles, 0);i != 0;i = nextIndex(articles, i)) { if (t >= articles[i][2]) continue; // filter... count += 1; result[count] = articles[i]; } return (result); } /* NNTPnewsgroup:getMessageHeader(int messageID, int bodyLines) { int offset, nextOffset, i; string mess, head; if (indexExists(messages, messageID) == 0) { return (nil); } mess = messages[messageID]; offset = findSubstring(mess, "\r\n\r\n"); // end of MIME header if (offset == -1) { // no end of MIME header, return everything return (mess); } offset += 4; // length of CR LF CR LF for(i=0;i