/* 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 URL_DIR_PREFIX = "/services/URLdirectory:"; const int REDIRECT_CODE = 302; // should be 303 const int REDIRECT_TYPE = "Moved Temporarily"; // should be See Other }; class Local . HTTPlistNNTPnewsgroups { oid urlDirectory; oid newsgroupDir; string pageName; int lastRetrievalTime; int defaultTimeout; } inherits from HTTPreplacedText; HTTPlistNNTPnewsgroups:create(string serverName) { int rc; assoc substVars; string pageTemplate; pageName = "/NNTPnewsgroup/listNewsgroups"; urlDirectory = lookupLocalService(URL_DIR_PREFIX + serverName); newsgroupDir = lookupLocalService("NewsgroupDirectory"); pageTemplate = ""; // nothing yet call "HTTPreplacedText:initialize"(urlDirectory, pageTemplate, "text/plain", substVars, pageName); rc = send "registerObject"(pageName, thisObject, 1) to urlDirectory; } HTTPlistNNTPnewsgroups:delete() {} HTTPlistNNTPnewsgroups:_makeList() { assoc infoList; array list; set elements; string s; int i, count; infoList = send "listNewsgroups" to newsgroupDir; display("INFO LIST=", infoList); for(i=nextIndex(infoList, 0);i != 0;i=nextIndex(infoList, i)) { list[count] = getKeyForIndex(infoList, i); count += 1; } display("List=",list); list = sortArray(list, 0); for(i=0;indexExists(list, i) != 0;i += 1) { elements += "\r\n"; } s = makeAsString(elements); return (s); } HTTPlistNNTPnewsgroups:checkIfStillValid() { return (1); } HTTPlistNNTPnewsgroups:getFileData() { int t; any d, result; t = getLocalRelativeTime(); if ((t - lastRetrievalTime) > defaultTimeout) { d = call "_makeList"(); call "setFileData"(d, defaultTimeout); lastRetrievalTime = t; } result = call "HTTPcachedObject:getFileData"(); return (result); } HTTPlistNNTPnewsgroups:getRequest(array requestData, assoc options, string replyMethod, oid replyDest) { any d; int t; t = getLocalRelativeTime(); if ((t - lastRetrievalTime) > defaultTimeout) { d = call "_makeList"(); call "setFileData"(d, defaultTimeout); lastRetrievalTime = t; } call "HTTPcachedObject:getRequest"(arrayToSet(argv)); } class Local . HTTPadminNNTPnewsgroups { oid urlDirectory; oid newsgroupDir; string pageName; int lastRetrievalTime; int defaultTimeout; } inherits from HTTPreplacedText; HTTPadminNNTPnewsgroups:create(string serverName) { int rc; assoc substVars; string pageTemplate; pageName = "/NNTPnewsgroup/adminNewsgroup"; urlDirectory = lookupLocalService(URL_DIR_PREFIX + serverName); newsgroupDir = lookupLocalService("NewsgroupDirectory"); pageTemplate = ""; // nothing yet call "HTTPreplacedText:initialize"(urlDirectory, pageTemplate, "text/html", substVars, pageName); rc = send "registerObject"(pageName, thisObject, 1) to urlDirectory; } HTTPadminNNTPnewsgroups:delete() {} HTTPadminNNTPnewsgroups:checkIfStillValid() { return (1); } HTTPadminNNTPnewsgroups:getRequest(array requestData, assoc options, string replyMethod, oid replyDest) { string body; body = makeAsString("", requestData[0], " is not permitted against ", requestData[1], ""); send "returnError"(405, "Method Not Allowed", body) to replyDest; } HTTPadminNNTPnewsgroups:headRequest(array requestData, assoc options, string replyMethod, oid replyDest) alias for getRequest; HTTPadminNNTPnewsgroups:postRequest(array requestData, assoc options, string replyMethod, oid replyDest) { assoc formInfo, acl; int returnCode, rc; string returnMess; string op, text, hdr, body; any groupName; oid newsgroup; formInfo = parseHTTPformData(options["ENTITY_CONTENT"], assoc); op = formInfo["operation"]; groupName = formInfo["newsgroupName"]; newsgroup = send "findNewsgroup"(groupName) to newsgroupDir; returnCode = 200; // assume OK returnMess = "OK"; if (op == "deleteNewsgroup") { if (newsgroup == nil) { returnCode = 404; returnMess = "Not Found"; body = makeAsString("No such newsgroup ", safeURI(groupName), "\r\n"); } else { // rc = send "authenticate"(formInfo["currentPassword"]) to newsgroup; rc = 1; if (rc == 0) { // failed returnCode = 403; returnMess = "Forbidden"; body = "Password was not valid\r\n"; } else { send "deleteYourself" to newsgroup; body = "Newsgroup deleted.\r\n"; } } } else if (op == "createNewsgroup") { if (newsgroup != nil) { returnCode = 409; returnMess = "Conflict"; body = makeAsString("Newsgroup already exists with name ", safeURI(groupName), ".\r\n"); } else { /* if (formInfo["newPassword"] != formInfo["verifyPassword"]) { returnCode = 409; returnMess = "Conflict"; body = "New password did not match\r\n"; } else { */ acl = makeDefaultACL(); newsgroup = send "createObject"("NNTPnewsgroup", acl, groupName, formInfo["description"], formInfo["newPassword"]) to ObjectCreator; body = "Newsgroup created.\r\n"; // } } } else { returnCode = 400; returnMess = "Bad Request"; body = "unrecognized operation\r\n"; } hdr = makeAsString("Content-type: text/plain\r\nContent-length: ", length(body), "\r\n\r\n"); send (replyMethod)(returnCode, returnMess, hdr, body) to replyDest; }