diff options
author | onefang | 2020-04-21 02:39:18 +1000 |
---|---|---|
committer | onefang | 2020-04-21 02:39:18 +1000 |
commit | 05cf05e423f26005bab5797f0e5b53d05ede56c5 (patch) | |
tree | 746d8c04f1867983c6372e07a67435bb8aee19de /src/sledjchisl/sledjchisl.c | |
parent | Fix some leaks. (diff) | |
download | opensim-SC-05cf05e423f26005bab5797f0e5b53d05ede56c5.zip opensim-SC-05cf05e423f26005bab5797f0e5b53d05ede56c5.tar.gz opensim-SC-05cf05e423f26005bab5797f0e5b53d05ede56c5.tar.bz2 opensim-SC-05cf05e423f26005bab5797f0e5b53d05ede56c5.tar.xz |
Part of the validated member list code.
Diffstat (limited to 'src/sledjchisl/sledjchisl.c')
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index b05aaa0..8980bd4 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c | |||
@@ -4761,6 +4761,96 @@ static int accountOut(reqData *Rd, inputForm *iF, inputValue *iV) | |||
4761 | return ret; | 4761 | return ret; |
4762 | } | 4762 | } |
4763 | 4763 | ||
4764 | typedef struct _RdAndListTbl RdAndListTbl; | ||
4765 | struct _RdAndListTbl | ||
4766 | { | ||
4767 | reqData *Rd; | ||
4768 | qlisttbl_t *list; | ||
4769 | }; | ||
4770 | static int accountFilterValidated(struct dirtree *node) | ||
4771 | { | ||
4772 | if (!node->parent) return DIRTREE_RECURSE | DIRTREE_SHUTUP; | ||
4773 | |||
4774 | if (S_ISREG(node->st.st_mode)) | ||
4775 | { | ||
4776 | struct stat st; | ||
4777 | struct timespec now; | ||
4778 | RdAndListTbl *rdl = (RdAndListTbl *) node->parent->extra; | ||
4779 | qhashtbl_t *tnm = qhashtbl(0, 0); | ||
4780 | char *name = node->name; | ||
4781 | char *where = xmprintf("%s/users/%s", scData, node->name); | ||
4782 | int rt = LuaToHash(rdl->Rd, where, "user", tnm, 0, &st, &now, "user"); | ||
4783 | |||
4784 | //t("accountFilterValidatedVoucher %s (%s) -> %s -> %s", name, getStrH(tnm, "level"), getStrH(tnm, "name"), getStrH(tnm, "voucher")); | ||
4785 | if ((0 == rt) && (strcmp("-100", getStrH(tnm, "level")) == 0)) | ||
4786 | rdl->list->put(rdl->list, getStrH(tnm, "name"), tnm, sizeof(*tnm)); | ||
4787 | else | ||
4788 | tnm->free(tnm); | ||
4789 | free(where); | ||
4790 | } | ||
4791 | return 0; | ||
4792 | } | ||
4793 | qlisttbl_t *getAccounts(reqData *Rd) | ||
4794 | { | ||
4795 | qlisttbl_t *ret = qlisttbl(0); | ||
4796 | RdAndListTbl rdl = {Rd, ret}; | ||
4797 | char *path = xmprintf("%s/users", scData); | ||
4798 | struct dirtree *new = dirtree_add_node(0, path, 0); | ||
4799 | |||
4800 | new->extra = (long) &rdl; | ||
4801 | dirtree_handle_callback(new, accountFilterValidated); | ||
4802 | ret->sort(ret); | ||
4803 | free(path); | ||
4804 | |||
4805 | return ret; | ||
4806 | } | ||
4807 | static void accountExploreValidatedVouchersWeb(reqData *Rd, inputForm *oF, inputValue *oV) | ||
4808 | { | ||
4809 | qlisttbl_t *list =getAccounts(Rd); | ||
4810 | char *name = getStrH(Rd->stuff, "name"); | ||
4811 | |||
4812 | Rd->shs.UUID = NULL; | ||
4813 | accountWebHeaders(Rd, oF, name); | ||
4814 | accountWebFields(Rd, oF, oV); | ||
4815 | |||
4816 | count = list->size(list); | ||
4817 | Rd->reply->addstrf(Rd->reply, "<table border=\"1\"><caption>Validated users</caption>\n"); | ||
4818 | Rd->reply->addstr(Rd->reply, "<tr>"); | ||
4819 | Rd->reply->addstr(Rd->reply, "<th>name</th>"); | ||
4820 | Rd->reply->addstr(Rd->reply, "<th>voucher</th>"); | ||
4821 | Rd->reply->addstr(Rd->reply, "<th>level</th>"); | ||
4822 | Rd->reply->addstr(Rd->reply, "<th>title</th>"); | ||
4823 | Rd->reply->addstr(Rd->reply, "</tr>\n<tr>"); | ||
4824 | |||
4825 | qlisttbl_obj_t obj; | ||
4826 | memset((void *) &obj, 0, sizeof(obj)); | ||
4827 | list->lock(list); | ||
4828 | while(list->getnext(list, &obj, NULL, false) == true) | ||
4829 | { | ||
4830 | qhashtbl_t *tnm = (qhashtbl_t *) obj.data; | ||
4831 | char *nm = qstrreplace("tr", xstrdup(obj.name), " ", "_"); | ||
4832 | |||
4833 | Rd->reply->addstrf(Rd->reply, "<tr><td><a href='https://%s%s/users/%s'>%s</a></td>", Rd->Host, Rd->RUri, nm, obj.name); | ||
4834 | Rd->reply->addstrf(Rd->reply, "<td>%s</td><td>%s</td><td>%s</td></tr>", getStrH(tnm, "voucher"), getStrH(tnm, "level"), getStrH(tnm, "title")); | ||
4835 | free(nm); | ||
4836 | tnm->clear(tnm); | ||
4837 | // TODO - crazy time again, either it frees twice, or not at all. | ||
4838 | // list->removeobj(list, &obj); | ||
4839 | // tnm->free(tnm); | ||
4840 | } | ||
4841 | list->unlock(list); | ||
4842 | Rd->reply->addstr(Rd->reply, "</table>"); | ||
4843 | list->free(list); | ||
4844 | |||
4845 | accountWebSubs(Rd, oF); | ||
4846 | accountWebFooter(Rd, oF); | ||
4847 | } | ||
4848 | static int accountExploreValidatedVoucher(reqData *Rd, inputForm *iF, inputValue *iV) | ||
4849 | { | ||
4850 | int ret = 0; | ||
4851 | return ret; | ||
4852 | } | ||
4853 | |||
4764 | 4854 | ||
4765 | qhashtbl_t *accountPages = NULL; | 4855 | qhashtbl_t *accountPages = NULL; |
4766 | inputForm *newInputForm(char *name, char *title, char *help, inputFormShowFunc web, inputFormShowFunc eWeb) | 4856 | inputForm *newInputForm(char *name, char *title, char *help, inputFormShowFunc web, inputFormShowFunc eWeb) |
@@ -5106,6 +5196,14 @@ void account_html(char *file, reqData *Rd, HTMLfile *thisFile) | |||
5106 | addSubmit(iF, "logout", "logout", NULL, accountOut, "accountLogin"); | 5196 | addSubmit(iF, "logout", "logout", NULL, accountOut, "accountLogin"); |
5107 | 5197 | ||
5108 | 5198 | ||
5199 | iF = newInputForm("accountValidated", "account validated list", NULL, accountExploreValidatedVouchersWeb, accountLoginWeb); | ||
5200 | addSession(iF); | ||
5201 | fld = addInputField(iF, LUA_TSTRING, "name", "name", NULL, nameValidate, nameWeb); | ||
5202 | inputFieldExtra(fld, FLD_HIDDEN, 42, 63); | ||
5203 | addSubmit(iF, "login", "", NULL, accountView, "accountView"); // Coz we sometimes want to trigger this from code. | ||
5204 | addSubmit(iF, "cancel", "cancel", NULL, accountView, "accountView"); | ||
5205 | |||
5206 | |||
5109 | iF = newInputForm("accountEdit", "account edit", NULL, accountEditWeb, accountLoginWeb); | 5207 | iF = newInputForm("accountEdit", "account edit", NULL, accountEditWeb, accountLoginWeb); |
5110 | addSession(iF); | 5208 | addSession(iF); |
5111 | // fld = addInputField(iF, LUA_TSTRING, "UUID", "UUID", NULL, UUIDValidate, UUIDWeb); | 5209 | // fld = addInputField(iF, LUA_TSTRING, "UUID", "UUID", NULL, UUIDValidate, UUIDWeb); |