Esempio n. 1
0
int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
{
	const char *Args;
	void *vLine, *vHandler;
	const char *Pos = NULL;

	Hdr->HR.ReqLine = Line;
	/* The requesttype... GET, POST... */
	StrBufExtract_token(Buf, Hdr->HR.ReqLine, 0, ' ');
	if (GetHash(HttpReqTypes, SKEY(Buf), &vLine) &&
	    (vLine != NULL))
	{
		Hdr->HR.eReqType = *(long*)vLine;
	}
	else {
		Hdr->HR.eReqType = eGET;
		return 1;
	}
	StrBufCutLeft(Hdr->HR.ReqLine, StrLength(Buf) + 1);

	/* the HTTP Version... */
	StrBufExtract_token(Buf, Hdr->HR.ReqLine, 1, ' ');
	StrBufCutRight(Hdr->HR.ReqLine, StrLength(Buf) + 1);
	
	if (StrLength(Buf) == 0) {
		Hdr->HR.eReqType = eGET;
		return 1;
	}

	StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0);

	/* chop Filename / query arguments */
	Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?');
	if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/
		Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&');
	if (Args != NULL) {
		Args ++; /* skip the ? */
		StrBufPlain(Hdr->PlainArgs, 
			    Args, 
			    StrLength(Hdr->HR.ReqLine) -
			    (Args - ChrPtr(Hdr->HR.ReqLine)));
		StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1);
	} /* don't parse them yet, maybe we don't even care... */
	
	/* now lookup what we are going to do with this... */
	/* skip first slash */
	StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
	do {
		StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');

		GetHash(HandlerHash, SKEY(Buf), &vHandler),
		Hdr->HR.Handler = (WebcitHandler*) vHandler;
		if (Hdr->HR.Handler == NULL)
			break;
		/*
		 * If the request is prefixed by "/webcit" then chop that off.  This
		 * allows a front end web server to forward all /webcit requests to us
		 * while still using the same web server port for other things.
		 */
		if ((Hdr->HR.Handler->Flags & URLNAMESPACE) != 0)
			continue;
		break;
	} while (1);
	/* remove the handlername from the URL */
	if ((Pos != NULL) && (Pos != StrBufNOTNULL)){
		StrBufCutLeft(Hdr->HR.ReqLine, 
			      Pos - ChrPtr(Hdr->HR.ReqLine));
	}

	if (Hdr->HR.Handler != NULL) {
		if ((Hdr->HR.Handler->Flags & BOGUS) != 0) {
			return 1;
		}
		Hdr->HR.DontNeedAuth = (
			((Hdr->HR.Handler->Flags & ISSTATIC) != 0) ||
			((Hdr->HR.Handler->Flags & ANONYMOUS) != 0)
		);
	}
	else {
		/* If this is a "flat" request for the root, display the configured landing page. */
		int return_value;
		StrBuf *NewLine = NewStrBuf();
		Hdr->HR.DontNeedAuth = 1;
		StrBufAppendPrintf(NewLine, "GET /landing?go=%s?failvisibly=1 HTTP/1.0", ChrPtr(Buf));
		if (verbose) syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
		return_value = ReadHttpSubject(Hdr, NewLine, Buf);
		FreeStrBuf(&NewLine);
		return return_value;
	}

	return 0;
}
Esempio n. 2
0
ParsedURL *LoadRelayUrls(OneQueItem *MyQItem,
			 char *Author,
			 char *Address)
{
	int nRelays = 0;
	ParsedURL *RelayUrls = NULL;
	char mxbuf[SIZ];
	ParsedURL **Url = &MyQItem->URL;

	nRelays = get_hosts(mxbuf, "fallbackhost");
	if (nRelays > 0) {
		StrBuf *All;
		StrBuf *One;
		const char *Pos = NULL;
		All = NewStrBufPlain(mxbuf, -1);
		One = NewStrBufPlain(NULL, StrLength(All) + 1);
		
		while ((Pos != StrBufNOTNULL) &&
		       ((Pos == NULL) ||
			!IsEmptyStr(Pos)))
		{
			StrBufExtract_NextToken(One, All, &Pos, '|');
			if (!ParseURL(Url, One, DefaultMXPort)) {
				SMTPC_syslog(LOG_DEBUG,
					     "Failed to parse: %s\n",
					     ChrPtr(One));
			}
			else {
				(*Url)->IsRelay = 1;
				MyQItem->HaveRelay = 1;
			}
		}
		FreeStrBuf(&All);
		FreeStrBuf(&One);
	}
	nRelays = get_hosts(mxbuf, "smarthost");
	if (nRelays > 0) {
		char *User;
		StrBuf *All;
		StrBuf *One;
		const char *Pos = NULL;
		All = NewStrBufPlain(mxbuf, -1);
		One = NewStrBufPlain(NULL, StrLength(All) + 1);
		
		while ((Pos != StrBufNOTNULL) &&
		       ((Pos == NULL) ||
			!IsEmptyStr(Pos)))
		{
			StrBufExtract_NextToken(One, All, &Pos, '|');
			User = strchr(ChrPtr(One), ' ');
			if (User != NULL) {
				if (!strcmp(User + 1, Author) ||
				    !strcmp(User + 1, Address))
					StrBufCutAt(One, 0, User);
				else {
					MyQItem->HaveRelay = 1;
					continue;
				}
			}
			if (!ParseURL(Url, One, DefaultMXPort)) {
				SMTPC_syslog(LOG_DEBUG,
					     "Failed to parse: %s\n",
					     ChrPtr(One));
			}
			else {
				///if (!Url->IsIP)) // todo dupe me fork ipv6
				(*Url)->IsRelay = 1;
				MyQItem->HaveRelay = 1;
			}
		}
		FreeStrBuf(&All);
		FreeStrBuf(&One);
	}
	return RelayUrls;
}