/* ** Access Authentication Schemes */ PUBLIC BOOL HTResponse_setScheme (HTResponse * me, char * scheme) { if (me && scheme) { StrAllocCopy(me->scheme, scheme); return YES; } return NO; }
PUBLIC BOOL HTUserProfile_setNews (HTUserProfile * up, const char * news) { if (up && news) { StrAllocCopy(up->news, news); return YES; } return NO; }
PUBLIC BOOL HTAlert_setReplySecret (HTAlertPar * me, const char * secret) { if (me && secret) { StrAllocCopy(me->secret, secret); return YES; } return NO; }
PUBLIC BOOL HTAlert_setReplyMessage (HTAlertPar * me, const char * message) { if (me && message) { StrAllocCopy(me->message, message); return YES; } return NO; }
/* ** Access Authentication Realms */ PUBLIC BOOL HTResponse_setRealm (HTResponse * me, char * realm) { if (me && realm) { StrAllocCopy(me->realm, realm); return YES; } return NO; }
PUBLIC BOOL HTCookie_setValue (HTCookie * me, const char * value) { if (me && value) { me->value = StrAllocCopy(me->value, value); return YES; } return NO; }
PUBLIC void HTAnchor_setCitehost ARGS2( HTParentAnchor *, me, CONST char *, citehost) { if (me) { StrAllocCopy(me->citehost, citehost); } }
PUBLIC void HTAnchor_setPhysical ARGS2( HTParentAnchor *, me, char *, physical) { if (me) { StrAllocCopy(me->physical, physical); } }
PUBLIC void HTAnchor_setOwner ARGS2( HTParentAnchor *, me, CONST char *, owner) { if (me) { StrAllocCopy(me->owner, owner); } }
PUBLIC BOOL HTCookie_setPath (HTCookie * me, const char * path) { if (me && path) { me->path = StrAllocCopy(me->path, path); return YES; } return NO; }
PUBLIC BOOL HTResponse_setReason (HTResponse * me, char * reason) { if (me && reason && *reason) { StrAllocCopy(me->reason, reason); return YES; } return NO; }
PUBLIC void HTAnchor_setPhysical (HTParentAnchor * me, char * physical) { if (!me || !physical) { HTTRACE(ANCH_TRACE, "HTAnchor.... setPhysical, called with null argument\n"); return; } StrAllocCopy(me->physical, physical); }
PUBLIC BOOL HTCookie_setDomain (HTCookie * me, const char * domain) { if (me && domain) { me->domain = StrAllocCopy(me->domain, domain); return YES; } return NO; }
PUBLIC BOOL HTUserProfile_setEmail (HTUserProfile * up, const char * email) { if (up && email) { StrAllocCopy(up->email, email); return YES; } return NO; }
PUBLIC BOOL HTAnchor_setBase (HTParentAnchor * me, char * base) { if (me && base) { StrAllocCopy(me->content_base, base); return YES; } return NO; }
/* Translate by rules ** ------------------ ** The most recently defined rules are applied last. ** This function walks through the list of rules and translates the ** reference when matches are found. The list is traversed in order ** starting from the head of the list. It returns the address of the ** equivalent string allocated from the heap which the CALLER MUST ** FREE. */ PUBLIC char * HTRule_translate (HTList * list, const char * token, BOOL ignore_case) { HTRule * pres; char * replace = NULL; if (!token || !list) return NULL; HTTRACE(APP_TRACE, "Check rules. for `%s\'\n" _ token); while ((pres = (HTRule *) HTList_nextObject(list))) { char * rest = ignore_case ? HTStrCaseMatch(pres->pattern, token) : HTStrMatch(pres->pattern, token); if (!rest) continue; /* No match at all */ /* We found a match for this entry, now do operation */ switch (pres->op) { case HT_Pass: case HT_Map: if (!pres->replace) { /* No replace */ StrAllocCopy(replace, token); } else if (*rest && pres->insert >= 0) { if ((replace = (char *) HT_MALLOC(strlen(pres->replace)+strlen(rest))) == NULL) HT_OUTOFMEM("HTRule_translate"); strcpy(replace, pres->replace); strcpy(replace+pres->insert, rest); } else { /* Perfect match or no insetion point */ StrAllocCopy(replace, pres->replace); } if (pres->op == HT_Pass) { HTTRACE(APP_TRACE, "............ map into `%s'\n" _ replace); return replace; } break; case HT_Fail: default: HTTRACE(APP_TRACE, "............ FAIL `%s'\n" _ token); return NULL; } } if (!replace) StrAllocCopy(replace, token); return replace; }
PUBLIC BOOL HTAnchor_setMd5 (HTParentAnchor * me, const char * hash) { if (me && hash) { StrAllocCopy(me->content_md5, hash); return YES; } return NO; }
PUBLIC BOOL HTCookie_setName (HTCookie * me, const char * name) { if (me && name) { me->name = StrAllocCopy(me->name, name); return YES; } return NO; }
PUBLIC BOOL HTUserProfile_setFqdn (HTUserProfile * up, const char * fqdn) { if (up && fqdn) { StrAllocCopy(up->fqdn, fqdn); return YES; } return NO; }
PUBLIC void HTAnchor_setStyle ARGS2( HTParentAnchor *, me, CONST char *, style) { if (me) { StrAllocCopy(me->style, style); } }
PUBLIC void HTAnchor_setPrompt ARGS2( HTParentAnchor *, me, CONST char *, prompt) { if (me) { StrAllocCopy(me->isIndexPrompt, prompt); } }
PRIVATE BOOL CSUserList_addLine(HTStream * me) { UserListStruct_t * newEl; char * pURL; char * end; end = strrchr(HTChunk_data(me->buffer), ' '); pURL = end + 1; while (*(end-1) == ' ') end--; *end = 0; if ((newEl = (UserListStruct_t *)HT_CALLOC(1, sizeof(UserListStruct_t))) == NULL) HT_OUTOFMEM("UserListStruct_t"); StrAllocCopy(newEl->name, HTChunk_data(me->buffer)); StrAllocCopy(newEl->url, pURL); /* HTList_addObject(me->URLs, (void *)pURL); */ HTList_addObject(UserList, (void *)newEl); return YES; }
void LYstore_message(const char *message) { if (message != NULL) { char *temp = NULL; StrAllocCopy(temp, message); to_stack(temp); } }
/* ** Existing entries are replaced with new ones */ PRIVATE BOOL add_object (HTList * list, const char * access, const char * url, BOOL regex, int regex_flags) { HTProxy *me; if (!list || !access || !url || !*url) return NO; if ((me = (HTProxy *) HT_CALLOC(1, sizeof(HTProxy))) == NULL) HT_OUTOFMEM("add_object"); StrAllocCopy(me->access, access); /* Access method */ #ifdef HT_POSIX_REGEX /* ** If we support regular expressions then compile one up for ** this regular expression. Otherwise use is as a normal ** access scheme. */ if (regex) { me->regex = get_regex_t(access, regex_flags < 0 ? W3C_DEFAULT_REGEX_FLAGS : regex_flags); } else #endif { char *ptr = me->access; while ((*ptr = TOLOWER(*ptr))) ptr++; } me->url = HTParse(url, "", PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION); if (*(me->url+strlen(me->url)-1) != '/') StrAllocCat(me->url, "/"); me->url = HTSimplify(&me->url); /* See if we already have this one */ { HTList *cur = list; HTProxy *pres; while ((pres = (HTProxy *) HTList_nextObject(cur)) != NULL) { if (!strcmp(pres->access, me->access)) break; /* We already have it */ } if (pres) { HTTRACE(PROT_TRACE, "HTProxy..... replacing for `%s\' access %s\n" _ me->url _ me->access); HT_FREE(pres->access); HT_FREE(pres->url); #ifdef HT_POSIX_REGEX if (pres->regex) regfree(pres->regex); #endif HTList_removeObject(list, (void *) pres); HT_FREE(pres); } HTTRACE(PROT_TRACE, "HTProxy..... adding for `%s\' access %s\n" _ me->url _ me->access); HTList_addObject(list, (void *) me); } return YES; }
PUBLIC void HTAnchor_setIndex ARGS2( HTParentAnchor *, me, CONST char *, address) { if (me) { me->isIndex = YES; StrAllocCopy(me->isIndexAction, address); } }
PUBLIC HTStyleSheet * HTStyleSheet_new (const char * name) { HTStyleSheet * ss; if ((ss = (HTStyleSheet *) HT_CALLOC(1, sizeof(HTStyleSheet))) == NULL) HT_OUTOFMEM("HTStyleSheet_new"); StrAllocCopy(ss->name, name ? name : "unknown"); ss->styles = HTList_new(); return ss; }
PUBLIC BOOL HTAssocList_replaceObject (HTAssocList * list, const char * name, const char * value) { if (list && name) { HTAssocList * cur = list; HTAssoc * assoc; int len = strlen(name); while ((assoc = (HTAssoc *) HTList_nextObject(cur))) { if (!strncasecomp(assoc->name, name, len)) { StrAllocCopy(assoc->name, name); if (value) StrAllocCopy(assoc->value, value); return YES; } } return HTAssocList_addObject(list, name, value); } return NO; }
/* * Put the AddHrefs in a list. It can be used for indexing to * present special filetypes through a CGI. */ PUBLIC void HTAddHref ARGS2(char *, url, char *, type_templ) { HTHrefNode * node; if (!url || !type_templ) return; node = (HTHrefNode*)calloc(1,sizeof(HTHrefNode)); if (!node) outofmem(__FILE__, "HTAddHref"); if (url) StrAllocCopy(node->href_url, url); if (type_templ) StrAllocCopy(node->type_templ, type_templ); if (!hrefs) hrefs = HTList_new(); HTList_addObject(hrefs, (void*)node); CTRACE(stderr, "AddHref..... %s => URL=\"%s\" \n",type_templ,url); }
PUBLIC char * HTPrompt ARGS2(WWW_CONST char *, Msg, WWW_CONST char *, deflt) { extern char *prompt_for_string (char *); char *Tmp = prompt_for_string (Msg); char *rep = 0; StrAllocCopy (rep, (Tmp && *Tmp) ? Tmp : deflt); return rep; }
/* PUBLIC HTAA_parseArgList() * PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD * ON ENTRY: * str is a comma-separated list: * * item, item, item * where * item ::= value * | name=value * | name="value" * * Leading and trailing whitespace is ignored * everywhere except inside quotes, so the following * examples are equal: * * name=value,foo=bar * name="value",foo="bar" * name = value , foo = bar * name = "value" , foo = "bar" * * ON EXIT: * returns a list of name-value pairs (actually HTAssocList*). * For items with no name, just value, the name is * the number of order number of that item. E.g. * "1" for the first, etc. */ HTAssocList *HTAA_parseArgList(char *str) { HTAssocList *assoc_list = HTAssocList_new(); char *cur = NULL; char *name = NULL; int n = 0; if (!str) return assoc_list; while (*str) { SKIPWS(str); /* Skip leading whitespace */ cur = str; n++; while (*cur && *cur != '=' && *cur != ',') cur++; /* Find end of name (or lonely value without a name) */ KILLWS(cur); /* Kill trailing whitespace */ if (*cur == '=') { /* Name followed by a value */ *(cur++) = '\0'; /* Terminate name */ StrAllocCopy(name, str); SKIPWS(cur); /* Skip WS leading the value */ str = cur; if (*str == '"') { /* Quoted value */ str++; cur = str; while (*cur && *cur != '"') cur++; if (*cur == '"') *(cur++) = '\0'; /* Terminate value */ /* else it is lacking terminating quote */ SKIPWS(cur); /* Skip WS leading comma */ if (*cur == ',') cur++; /* Skip separating colon */ } else { /* Unquoted value */ while (*cur && *cur != ',') cur++; KILLWS(cur); /* Kill trailing whitespace */ if (*cur == ',') *(cur++) = '\0'; /* else *cur already NULL */ } } else { /* No name, just a value */ if (*cur == ',') *(cur++) = '\0'; /* Terminate value */ /* else last value on line (already terminated by NULL) */ HTSprintf0(&name, "%d", n); /* Item order number for name */ } HTAssocList_add(assoc_list, name, str); str = cur; } /* while *str */ FREE(name); return assoc_list; }