+
+ config_lines = num_tokens(oldnetconfig, '\n');
+ for (i=0; i<config_lines; ++i) {
+ extract_token(buf, oldnetconfig, i, '\n', sizeof buf);
+ extract_token(pending_directive, buf, 0, '|', sizeof pending_directive);
+ extract_token(pending_email, buf, 1, '|', sizeof pending_email);
+ extract_token(pending_token, buf, 2, '|', sizeof pending_token);
+
+ if (!strcasecmp(pending_token, token)) {
+ if (!strcasecmp(pending_directive, "subpending")) {
+ yes_subscribe = 1;
+ }
+ else if (!strcasecmp(pending_directive, "unsubpending")) {
+ yes_unsubscribe = 1;
+ }
+ }
+ }
+ free(oldnetconfig);
+
+ // We didn't find a pending subscribe or unsubscribe request with the supplied token.
+ if ((!yes_subscribe) && (!yes_unsubscribe)) {
+ cprintf("%d The request you are trying to confirm was not found.\n", ERROR + NO_SUCH_USER);
+ return;
+ }
+
+ // The second pass performs the now confirmed operation.
+ // We will have to do this in two passes. The first pass checks to see if we have a confirmation request matching the token.
+ oldnetconfig = LoadRoomNetConfigFile(CC->room.QRnumber);
+ if (!oldnetconfig) {
+ oldnetconfig = strdup("");
+ }
+
+ // The new netconfig begins with an empty buffer...
+ begin_critical_section(S_NETCONFIGS);
+ char *newnetconfig = malloc(strlen(oldnetconfig) + 1024);
+ newnetconfig[0] = 0;
+
+ config_lines = num_tokens(oldnetconfig, '\n');
+ for (i=0; i<config_lines; ++i) {
+ char buf_email[256];
+ extract_token(buf, oldnetconfig, i, '\n', sizeof buf);
+ extract_token(buf_email, buf, 1, '|', sizeof pending_email);
+ if (strcasecmp(buf_email, pending_email)) {
+ sprintf(&newnetconfig[strlen(newnetconfig)], "%s\n", buf); // only keep lines that do not reference this subscriber
+ }
+ }
+
+ // We have now removed all lines containing the subscriber's email address. This deletes any pending requests.
+ // If this was an unsubscribe operation, they're now gone from the list.
+ // But if this was a subscribe operation, we now need to add them.
+ if (yes_subscribe) {
+ sprintf(&newnetconfig[strlen(newnetconfig)], "listrecp|%s\n", pending_email);
+ }
+
+ // FIXME write it back to disk
+ SaveRoomNetConfigFile(CC->room.QRnumber, newnetconfig);
+ end_critical_section(S_NETCONFIGS);
+ free(oldnetconfig);
+ free(newnetconfig);
+ cprintf("%d The pending request was confirmed.\n", CIT_OK);