Example #1
0
/**
 * If szStripPrefix is not nullptr, only options, whose names start with the prefix
 * are processed. The prefix is then stripped from the names.
 * If szStripPrefix is nullptr, all options are processed; without stripping.
 */
void ScriptController::PrepareEnvOptions(const char* stripPrefix)
{
	int prefixLen = stripPrefix ? strlen(stripPrefix) : 0;

	for (Options::OptEntry& optEntry : g_Options->GuardOptEntries())
	{
		const char* value = GetOptValue(optEntry.GetName(), optEntry.GetValue());
		if (stripPrefix && !strncmp(optEntry.GetName(), stripPrefix, prefixLen) &&
			(int)strlen(optEntry.GetName()) > prefixLen)
		{
			SetEnvVarSpecial("NZBPO", optEntry.GetName() + prefixLen, value);
		}
		else if (!stripPrefix)
		{
			SetEnvVarSpecial("NZBOP", optEntry.GetName(), value);
		}
	}
}
Example #2
0
void CMIMEItem::FromString(LPSTR& lpSrc, LPCTSTR lpBoundParent)
{
	char szBuf[65540];
	int n;
	BOOL bBody = FALSE;
	LPSTR lpOrg = lpSrc;
	int nBound = 0;
	int nBoundParent = 0;
	m_lstHeaders.Empty();
	m_lstBody.Empty();
	m_lstTrail.Empty();
	while (n = sGets((LPCTSTR&)lpSrc, szBuf, 65536)) {
		if (szBuf[n-1] == '\n') {
			szBuf[n-1] = '\r';
			szBuf[n] = '\n';
			szBuf[n+1] = '\0';
			n++;
		}
		if (bBody) {
			if (strncmp(szBuf, "--", 2) == 0) {
				szBuf[n-2] = '\0'; n -= 2;
				if (m_lpBoundary) { // multipart
					if (!nBound) nBound = strlen(m_lpBoundary);
					if (strcmp(&szBuf[2], m_lpBoundary) == 0) {
						CMIMEItem* pSub = new CMIMEItem;
						pSub->FromString(lpSrc, m_lpBoundary);
						if (!m_lpChild) {
							m_lpChild = pSub;
						} else {
							CMIMEItem* pNext = m_lpChild;
							while (pNext->m_lpNext) {
								pNext = pNext->m_lpNext;
							}
							pNext->m_lpNext = pSub;
						}
						lpOrg = lpSrc;
						continue;
					} else 
					if (strncmp(&szBuf[2], m_lpBoundary, nBound) == 0 &&
						strcmp(&szBuf[nBound+2], "--") == 0) {
						if (lpBoundParent) {
							lpOrg = lpSrc;
							while (n = sGets((LPCTSTR&)lpSrc, szBuf, 65536)) {
								if (szBuf[n-1] == '\n') {
									szBuf[n-1] = '\r';
									szBuf[n] = '\n';
									szBuf[n+1] = '\0';
									n++;
								}
								if (!nBoundParent) nBoundParent = strlen(lpBoundParent);
								if (strncmp(&szBuf[2], lpBoundParent, nBoundParent) == 0) {
									lpSrc = lpOrg;
									break;
								}
								m_lstTrail.AddTail(szBuf);
								lpOrg = lpSrc;
							}
						}
						break;
					}
				}
				if (lpBoundParent) {
					if (!nBoundParent) nBoundParent = strlen(lpBoundParent);
					if (strncmp(&szBuf[2], lpBoundParent, nBoundParent) == 0) {
						lpSrc = lpOrg;
						break;
					}
				}
				szBuf[n] = '\r'; n += 2;
			}
			m_lstBody.AddTail(szBuf);
		} else {
			if (szBuf[0] == '\r' && szBuf[1] == '\n') {
				m_lstHeaders.AddTail(szBuf);
				bBody = TRUE;
			} else {
				while (*lpSrc == ' ' || *lpSrc == '\t') {
					LPSTR lpBuf = &szBuf[n];
					int nn = sGets((LPCTSTR&)lpSrc, lpBuf, 65536-n);
					if (lpBuf[nn-1] == '\n') {
						lpBuf[nn-1] = '\r';
						lpBuf[nn] = '\n';
						lpBuf[nn+1] = '\0';
						nn++;
					}
					n += nn;
					if (n >= 65536) {
						// Header too long. Give up.
						break;
					}
				}
				m_lstHeaders.AddTail(szBuf);
				if (strnicmp(szBuf, "Content-Type:", 13) == 0) {
					LPSTR lpsz = &szBuf[13];
					LPSTR lpType = strtok(lpsz, "/ \t");
					LPSTR lpSubType = strtok(NULL, "; \r\n\t");
					if (lpType && lpSubType) {
						strncpy(m_szType, lpType, 40); m_szType[40] = '\0';
						strncpy(m_szSubType, lpSubType, 40); m_szSubType[40] = '\0';

						LPSTR lpOpt, lpVal;
						LPSTR lpOption = strtok(NULL, "");
						if (lpOption) {
							lpOption = GetOptValue(lpOption, lpOpt, lpVal);
							while (lpOption) {
								if (stricmp(lpOpt, "boundary") == 0) {
									if (m_lpBoundary) free(m_lpBoundary);
									m_lpBoundary = strdup(lpVal);
								}
								if (*lpOption == '\0') break;
								lpOption = GetOptValue(lpOption, lpOpt, lpVal);
							}
						}
					}
				}

			}
		}
		lpOrg = lpSrc;
	}
}