mbhelp_t::~mbhelp_t () //************************************************************************* // //************************************************************************* { if (helpf) s_fclose(helpf); if (idxf) s_fclose(idxf); }
time_t wx::read_wx_data (char *oneline, time_t time_m) //************************************************************************* // Reads wx-data which is next to time_m, returns data and // timestamp of data found. // returns 0 when no data is found //************************************************************************* { char name[20]; int found = 0; char times[13]; char data[80]; time_t times_l; long line = 0; strcpy(name, "wx:read_wx_data"); FILE *wxf = s_fopen(time2wxfn(time_m), "srt"); if (! wxf) { trace(report, name, "fopen %s err", time2wxfn(time_m)); return 0L; } while (! found && ! feof(wxf)) { fgets(data, 80, wxf); line++; rm_crlf(data); if (strlen(data) != 70) { trace(replog, name, "%s line %ld len %d invalid", time2wxfn(time_m), line, strlen(data)); s_fclose(wxf); return 0L; } //extract time stamp strncpy(times, data+57, 12); times[12] = 0; times_l = atol(times); //printf("%ld %ld %s\n",line,times_l,datestr(times_l,12)); if (times_l>=time_m-360 && //max. 6min in advance (midnight) times_l< time_m+3960) //max. 1h 6min past (daylightsaving) found++; } s_fclose(wxf); if (! found) { trace(report, name, "data missing"); return 0L; } else { data[56] = 0; strcpy(oneline, data+6); return times_l; } }
int grep (char *name, char *pattern, bitfeld options) //************************************************************************* // // // //************************************************************************* { FILE *f; CRegEx cr; int matches = 0; cr.m_options = options; if (name[0]) { if (cr.regex_compile(pattern)) { f = s_fopen(name, "srt"); if (f) { setvbuf(f, NULL, _IOFBF, 4096); matches = cr.grepfile(f); s_fclose(f); } else putf(ms(m_filenotopen), name); } else putf(ms(m_badregex)); } return matches; }
/* * Send "QUIT" command and close the connection to the server * * Side effects: Closes the connection to the server. * You can't use "put_server" or "get_server" after this * routine is called. * * TODO: remember servers response string and if it contains anything else * than just "." (i.e. transfer statistics) present it to the user? * */ void close_server( void) { if (nntp_wr_fp == NULL || nntp_rd_fp == NULL) return; if (!batch_mode || verbose) my_fputs(_(txt_disconnecting), stdout); nntp_command("QUIT", OK_GOODBYE, NULL, 0); quitting = TRUE; /* Don't reconnect just for this */ (void) s_fclose(nntp_wr_fp); (void) s_fclose(nntp_rd_fp); s_end(); nntp_wr_fp = nntp_rd_fp = NULL; }
int mbhelp_t::helpopen (char *speech) //************************************************************************* // //************************************************************************* { time_t helptime = 0L; sprintf(helpname, MSGPATH "/help.%s", speech); strlwr(helpname); if ((helpf = s_fopen(helpname, "srt")) != NULL) { sprintf(idxname, MSGPATH "/helpidx.%s", speech); strlwr(idxname); idxf = s_fopen(idxname, "srb"); { if (idxf) { fscanf(idxf, "%ld", &helptime); if (file_isreg(helpname) != helptime) { s_fclose(idxf); idxf = NULL; } } if (! idxf) { if (! helpindex()) // generate index file { s_fclose(helpf); // do not loose filehandles if no correct index helpf = NULL; return 0; } } fgets(inbuf, LINELEN, idxf); // skip the first line containing filetime return 1; } } else return 0; }
/* Function: iSrchFilterGetSearchBitmapFromFilter() Purpose: This function collects and searches filters and returns a bit map if there are any filters. The filter can either be a list name (mapping to a file), or a list of terms. If it is a list of terms, then each term has to be comma separated and must not contain any spaces. A search bitmap will not be allocated if no terms were found and an existing bitmap was not passed Parameters: pssSrchSearch search structure psiSrchIndex index structure uiLanguageID language ID pspfSrchParserFilter search parser string filter uiStartDocumentID start document ID restriction (0 for no restriction) uiEndDocumentID end document ID restriction (0 for no restriction) ppsbSrchBitmap return pointer for the search bitmap structure Globals: none Returns: SRCH error code */ static int iSrchFilterGetSearchBitmapFromFilter ( struct srchSearch *pssSrchSearch, struct srchIndex *psiSrchIndex, unsigned int uiLanguageID, struct srchParserFilter *pspfSrchParserFilter, unsigned int uiStartDocumentID, unsigned int uiEndDocumentID, struct srchBitmap **ppsbSrchBitmap ) { int iError = SRCH_NoError; void *pvLngStemmer = NULL; unsigned int uiSrchParserSearchCacheID = SRCH_PARSER_MODIFIER_UNKNOWN_ID; unsigned char pucConfigValue[SRCH_INFO_SYMBOL_MAXIMUM_LENGTH + 1] = {'\0'}; unsigned char pucFilterFilePath[UTL_FILE_PATH_MAX + 1] = {'\0'}; FILE *pfFilterFile = NULL; off_t zFilterFileLength = 0; unsigned char *pucFilterFileMappingPtr = NULL; time_t tFilterFileLastUpdate = (time_t)0; wchar_t *pwcTerms = NULL; wchar_t *pwcNormalizedExcludedTermsStrtokPtr = NULL; struct srchTermDictInfo *pstdiSrchTermDictInfos = NULL; struct srchTermDictInfo *pstdiSrchTermDictInfosPtr = NULL; unsigned int uiSrchTermDictInfosLength = 0; unsigned int uiI = 0; unsigned int uiNormalizedTermsLength = 0; wchar_t *pwcTerm = NULL; unsigned char *pucTerm = NULL; unsigned char *pucFieldIDBitmap = NULL; /* iUtlLogDebug(UTL_LOG_CONTEXT, "iSrchFilterGetSearchBitmapFromFilter - pspfSrchParserFilter->pwcFilter: '%ls'", pspfSrchParserFilter->pwcFilter); */ ASSERT(pssSrchSearch != NULL); ASSERT(psiSrchIndex != NULL); ASSERT(uiLanguageID >= 0); ASSERT(pspfSrchParserFilter != NULL); ASSERT(uiStartDocumentID >= 0); ASSERT(uiEndDocumentID >= 0); ASSERT(ppsbSrchBitmap != NULL); /* Create the stemmer */ if ( (iError = iLngStemmerCreateByID(psiSrchIndex->uiStemmerID, uiLanguageID, &pvLngStemmer)) != LNG_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to create a stemmer, lng error: %d.", iError); iError = SRCH_FilterCreateStemmerFailed; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Get the parser search cache ID */ if ( (iError = iSrchParserGetModifierID(pssSrchSearch->pvSrchParser, SRCH_PARSER_MODIFIER_SEARCH_CACHE_ID, &uiSrchParserSearchCacheID)) != SRCH_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to get the parser search cache ID, srch error: %d.", iError); goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Terms based filter */ if ( pspfSrchParserFilter->uiFilterTypeID == SRCH_PARSER_FILTER_TYPE_TERMS_ID ) { ; } /* List based filter */ else if ( pspfSrchParserFilter->uiFilterTypeID == SRCH_PARSER_FILTER_TYPE_LIST_ID ) { unsigned char *pucFilterDirectoryPath = NULL; unsigned char *pucFilterName = NULL; unsigned char pucFilterFileName[UTL_FILE_PATH_MAX + 1] = {'\0'}; /* Check for the filter file if there is a location for these files */ if ( (iError = iUtlConfigGetValue(pssSrchSearch->pvUtlConfig, SRCH_SEARCH_CONFIG_FILTER_FILES_LOCATION, pucConfigValue, SRCH_INFO_SYMBOL_MAXIMUM_LENGTH + 1)) != UTL_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to get the file file location from the search configuration, symbol name: '%s', utl error: %d.", SRCH_SEARCH_CONFIG_FILTER_FILES_LOCATION, iError); iError = SRCH_FilterInvalidFilterFileLocation; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Get a pointer to the filter directory path, exclude the file protocol url if it is there */ pucFilterDirectoryPath = (s_strncasecmp(pucConfigValue, SRCH_FILTER_FILE_PROTOCOL_URL, s_strlen(SRCH_FILTER_FILE_PROTOCOL_URL)) == 0) ? pucConfigValue + s_strlen(SRCH_FILTER_FILE_PROTOCOL_URL) : pucConfigValue; /* Convert the filter from wide characters to utf-8, pucFilterName is allocated */ if ( (iError = iLngConvertWideStringToUtf8_d(pspfSrchParserFilter->pwcFilter, 0, &pucFilterName)) != LNG_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to convert a filter name from wide characters to utf-8, lng error: %d.", iError); iError = SRCH_FilterCharacterSetConvertionFailed; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Create the filter file name */ snprintf(pucFilterFileName, UTL_FILE_PATH_MAX + 1, "%s%s", pucFilterName, SRCH_FILTER_FILENAME_EXTENSION); /* Free the utf-8 filter file name */ s_free(pucFilterName); /* Create the filter file path */ if ( (iError = iUtlFileMergePaths(pucFilterDirectoryPath, pucFilterFileName, pucFilterFilePath, UTL_FILE_PATH_MAX + 1)) != UTL_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to create the filter file path, file file name: '%s', filter directory path: '%s', utl error: %d", pucFilterFileName, pucFilterDirectoryPath, iError); iError = SRCH_FilterInvalidFilterFile; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Check if the filter file is there */ if ( bUtlFileIsFile(pucFilterFilePath) == false ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to find the filter file: '%s'.", pucFilterFilePath); iError = SRCH_FilterInvalidFilterFile; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Open the filter file */ if ( (pfFilterFile = s_fopen(pucFilterFilePath, "r")) == NULL ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to open the filter file: '%s'.", pucFilterFilePath); iError = SRCH_FilterInvalidFilterFile; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Get the filter file modification date */ if ( (iError = iUtlFileGetFileModificationTimeT(pfFilterFile, &tFilterFileLastUpdate)) != UTL_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to get the last modification time of the filter file: '%s', utl error: %d.", pucFilterFilePath, iError); iError = SRCH_FilterInvalidFilterFile; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } /* Get the bitmap from the search cache, note that we dont need to differentiate between terms or lists ** since terms will have a tFilterFileLastUpdate of 0 and lists will have a non-zero tFilterFileLastUpdate */ if ( uiSrchParserSearchCacheID == SRCH_PARSER_MODIFIER_SEARCH_CACHE_ENABLE_ID ) { if ( (iError = iSrchCacheGetSearchBitmap(pssSrchSearch->pvSrchCache, psiSrchIndex, pspfSrchParserFilter->pwcFilter, tFilterFileLastUpdate, ppsbSrchBitmap)) == SRCH_NoError ) { /* We are all set */ goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } /* Terms based filter */ if ( pspfSrchParserFilter->uiFilterTypeID == SRCH_PARSER_FILTER_TYPE_TERMS_ID ) { /* Make a straight copy of the terms */ if ( (pwcTerms = s_wcsdup(pspfSrchParserFilter->pwcFilter)) == NULL ) { iError = SRCH_MemError; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } iSrchReportAppend(pssSrchSearch->pvSrchReport, "%s The search filtered on the following terms: '%ls'\n", REP_SEARCH_RESTRICTION, pspfSrchParserFilter->pwcFilter); } /* List based filter */ else if ( pspfSrchParserFilter->uiFilterTypeID == SRCH_PARSER_FILTER_TYPE_LIST_ID ) { /* Get the file length */ if ( (iError = iUtlFileGetFileLength(pfFilterFile, &zFilterFileLength)) != UTL_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to get the length of the filter file: '%s', utl error: %d.", pucFilterFilePath, iError); iError = SRCH_FilterInvalidFilterFile; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Map in the entire file */ if ( (iError = iUtlFileMemoryMap(fileno(pfFilterFile), 0, zFilterFileLength, PROT_READ, (void **)&pucFilterFileMappingPtr) != UTL_NoError) ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to map in the filter file: '%s', utl error: %d.", pucFilterFilePath, iError); iError = SRCH_FilterInvalidFilterFile; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Convert the terms from utf-8 to wide characters, pwcTerms is allocated */ if ( (iError = iLngConvertUtf8ToWideString_d(pucFilterFileMappingPtr, zFilterFileLength, &pwcTerms)) != LNG_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to convert the terms from utf-8 to wide characters, lng error: %d.", iError); iError = SRCH_FilterCharacterSetConvertionFailed; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Unmap the filter file */ iUtlFileMemoryUnMap(pucFilterFileMappingPtr, zFilterFileLength); pucFilterFileMappingPtr = NULL; /* Close the filter file */ s_fclose(pfFilterFile); pfFilterFile = NULL; /* Convert newlines to commas */ iUtlStringsReplaceCharacterInWideString(pwcTerms, L'\n', L','); iSrchReportAppend(pssSrchSearch->pvSrchReport, "%s The search filtered on the following list: '%ls'\n", REP_SEARCH_RESTRICTION, pspfSrchParserFilter->pwcFilter); } /* Allocate a field ID bitmap only if there are any fields other than field ID 0 */ if ( psiSrchIndex->uiFieldIDMaximum > 0 ) { /* Allocate the field ID bitmap - field ID 0 is not a field */ if ( (pucFieldIDBitmap = (unsigned char *)s_malloc(sizeof(unsigned char) * UTL_BITMAP_GET_BITMAP_BYTE_LENGTH(psiSrchIndex->uiFieldIDMaximum))) == NULL ) { iError = SRCH_MemError; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } /* Loop parsing the terms */ for ( pwcTerm = s_wcstok(pwcTerms, SRCH_FILTER_TERM_SEPARATORS, (wchar_t **)&pwcNormalizedExcludedTermsStrtokPtr); pwcTerm != NULL; pwcTerm = s_wcstok(NULL, SRCH_FILTER_TERM_SEPARATORS, (wchar_t **)&pwcNormalizedExcludedTermsStrtokPtr) ) { /* Trim the string if needed, we do this so that we can handle lists like 'bats, lions, elephants' */ iUtlStringsTrimWideString(pwcTerm); /* Term contains spaces, treat as a phrase */ if ( s_wcschr(pwcTerm, L' ') != NULL ) { wchar_t *pwcTermStrtokPtr = NULL; wchar_t *pwcSubTerm = NULL; struct srchPostingsList *psplSrchPostingsList = NULL; /* Get the first subterm - wcstok_r along spaces */ pwcSubTerm = s_wcstok(pwcTerm, L" ", (wchar_t **)&pwcTermStrtokPtr); /* Loop while there are subterm */ while ( pwcSubTerm != NULL ) { boolean bFieldIDBitmapSet = false; /* Clear the bitmap */ if ( pucFieldIDBitmap != NULL ) { UTL_BITMAP_CLEAR_POINTER(pucFieldIDBitmap, psiSrchIndex->uiFieldIDMaximum); } /* Process the term, this returns a pointer to the processed term and sets the bitmap as needed */ if ( (iError = iSrchFilterProcessTerm(pssSrchSearch, psiSrchIndex, pvLngStemmer, pwcSubTerm, pucFieldIDBitmap, psiSrchIndex->uiFieldIDMaximum, &pwcSubTerm, &bFieldIDBitmapSet)) != SRCH_NoError ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Skip the term if it was stemmed out of existence */ if ( bUtlStringsIsWideStringNULL(pwcSubTerm) == false ) { unsigned char *pucSubTerm = NULL; struct srchPostingsList *psplSrchPostingsTempList = NULL; /* Convert the subterm from wide characters to utf-8, pucSubTerm is allocated */ if ( (iError = iLngConvertWideStringToUtf8_d(pwcSubTerm, 0, &pucSubTerm)) != LNG_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to convert a filter term from wide characters to utf-8, lng error: %d.", iError); iError = SRCH_FilterCharacterSetConvertionFailed; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Search to postings list */ iError = iSrchTermSearchGetSearchPostingsListFromTerm(pssSrchSearch, psiSrchIndex, pucSubTerm, SRCH_SEARCH_TERM_WEIGHT_DEFAULT, (bFieldIDBitmapSet == true) ? pucFieldIDBitmap : NULL, (bFieldIDBitmapSet == true) ? psiSrchIndex->uiFieldIDMaximum : 0, 0, 0, 0, &psplSrchPostingsTempList); /* Free the subterm */ s_free(pucSubTerm); /* Check the returned error */ if ( iError != SRCH_NoError ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Break here if there was no terms returned as this will kill the phrase */ if ( (psplSrchPostingsTempList == NULL) || (psplSrchPostingsTempList->uiSrchPostingsLength == 0) ) { iSrchPostingFreeSrchPostingsList(psplSrchPostingsTempList); psplSrchPostingsTempList = NULL; iSrchPostingFreeSrchPostingsList(psplSrchPostingsList); psplSrchPostingsList = NULL; break; } /* Merge the postings lists, ADJ with a distance of 1 and a strict boolean match */ if ( psplSrchPostingsList != NULL ) { if ( (iError = iSrchPostingMergeSrchPostingsListsADJ(psplSrchPostingsList, psplSrchPostingsTempList, 1, SRCH_PARSER_MODIFIER_BOOLEAN_OPERATION_STRICT_ID, &psplSrchPostingsList)) != SRCH_NoError ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } else { psplSrchPostingsList = psplSrchPostingsTempList; } } /* Get the next subterm */ pwcSubTerm = s_wcstok(NULL, L" ", (wchar_t **)&pwcTermStrtokPtr); } /* Set the search bitmap structure from the search postings list structure */ if ( psplSrchPostingsList != NULL ) { struct srchPosting *pspSrchPostingsPtr = NULL; struct srchPosting *pspSrchPostingsEnd = NULL; unsigned int uiLastDocumentID = 0; unsigned char *pucBitmapPtr = NULL; /* We only process the search postings list structure if there is something in it */ if ( psplSrchPostingsList->uiSrchPostingsLength > 0 ) { /* Allocate the search bitmap structure if it has not yet been allocated */ if ( *ppsbSrchBitmap == NULL ) { if ( (iError = iSrchBitmapCreate(NULL, psiSrchIndex->uiDocumentCount + 1, false, ppsbSrchBitmap)) != SRCH_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to create a new search bitmap, srch error: %d.", iError); goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } /* Dereference the bitmap array */ pucBitmapPtr = (*ppsbSrchBitmap)->pucBitmap; /* Set the bitmap for these documents */ for ( pspSrchPostingsPtr = psplSrchPostingsList->pspSrchPostings, pspSrchPostingsEnd = psplSrchPostingsList->pspSrchPostings + psplSrchPostingsList->uiSrchPostingsLength; pspSrchPostingsPtr < pspSrchPostingsEnd; pspSrchPostingsPtr++ ) { /* Set the document in the bitmap if it has not already been set */ if ( pspSrchPostingsPtr->uiDocumentID != uiLastDocumentID ) { UTL_BITMAP_SET_BIT_IN_POINTER(pucBitmapPtr, pspSrchPostingsPtr->uiDocumentID); uiLastDocumentID = pspSrchPostingsPtr->uiDocumentID; } } } /* Free the postings list */ iSrchPostingFreeSrchPostingsList(psplSrchPostingsList); psplSrchPostingsList = NULL; } } /* Term does not contain spaces, treat as a term */ else { boolean bFieldIDBitmapSet = false; /* Clear the bitmap */ if ( pucFieldIDBitmap != NULL ) { UTL_BITMAP_CLEAR_POINTER(pucFieldIDBitmap, psiSrchIndex->uiFieldIDMaximum); } /* Process the term, this returns a pointer to the processed term and sets the bitmap as needed */ if ( (iError = iSrchFilterProcessTerm(pssSrchSearch, psiSrchIndex, pvLngStemmer, pwcTerm, pucFieldIDBitmap, psiSrchIndex->uiFieldIDMaximum, &pwcTerm, &bFieldIDBitmapSet)) != SRCH_NoError ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Skip the term if it was stemmed out of existence */ if ( bUtlStringsIsWideStringNULL(pwcTerm) == false ) { /* Convert the term from wide characters to utf-8, pucTerm is allocated */ if ( (iError = iLngConvertWideStringToUtf8_d(pwcTerm, 0, &pucTerm)) != LNG_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to convert a filter term from wide characters to utf-8, lng error: %d.", iError); iError = SRCH_FilterCharacterSetConvertionFailed; goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Expand the term if it contains a wildcard (or two) */ if ( s_strpbrk(pucTerm, SRCH_PARSER_WILDCARDS_STRING) != NULL ) { /* Expand the term */ iError = iSrchTermDictLookupWildCard(psiSrchIndex, pucTerm, (bFieldIDBitmapSet == true) ? pucFieldIDBitmap : NULL, (bFieldIDBitmapSet == true) ? psiSrchIndex->uiFieldIDMaximum : 0, &pstdiSrchTermDictInfos, &uiSrchTermDictInfosLength); /* Check for non recoverable errors */ if ( !((iError == SRCH_NoError) || (iError == SRCH_TermDictTermBadRange) || (iError == SRCH_TermDictTermBadWildCard) || (iError == SRCH_IndexHasNoTerms) || (iError == SRCH_TermDictTermNotFound) || (iError == SRCH_TermDictTermDoesNotOccur)) ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } /* Reset the error */ iError = SRCH_NoError; /* Loop through all the terms in the term list */ for ( pstdiSrchTermDictInfosPtr = pstdiSrchTermDictInfos, uiI = 0; uiI < uiSrchTermDictInfosLength; pstdiSrchTermDictInfosPtr++, uiI++ ) { /* Search to bitmap */ if ( (iError = iSrchTermSearchGetSearchBitmapFromTerm(pssSrchSearch, psiSrchIndex, pstdiSrchTermDictInfosPtr->pucTerm, (bFieldIDBitmapSet == true) ? pucFieldIDBitmap : NULL, ((bFieldIDBitmapSet == true) ? psiSrchIndex->uiFieldIDMaximum : 0), 0, uiStartDocumentID, uiEndDocumentID, ppsbSrchBitmap)) != SRCH_NoError ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } } else { /* Search to bitmap */ if ( (iError = iSrchTermSearchGetSearchBitmapFromTerm(pssSrchSearch, psiSrchIndex, pucTerm, (bFieldIDBitmapSet == true) ? pucFieldIDBitmap : NULL, ((bFieldIDBitmapSet == true) ? psiSrchIndex->uiFieldIDMaximum : 0), 0, uiStartDocumentID, uiEndDocumentID, ppsbSrchBitmap)) != SRCH_NoError ) { goto bailFromiSrchFilterGetSearchBitmapFromFilter; } } /* Free the term */ s_free(pucTerm); } } } /* Store the bipmap to cache if the cache is enabled */ if ( uiSrchParserSearchCacheID == SRCH_PARSER_MODIFIER_SEARCH_CACHE_ENABLE_ID ) { if ( *ppsbSrchBitmap != NULL ) { iSrchCacheSaveSearchBitmap(pssSrchSearch->pvSrchCache, psiSrchIndex, pspfSrchParserFilter->pwcFilter, tFilterFileLastUpdate, *ppsbSrchBitmap); } } /* Bail label */ bailFromiSrchFilterGetSearchBitmapFromFilter: /* Free the stemmer */ iLngStemmerFree(pvLngStemmer); pvLngStemmer = NULL; /* List based filter */ if ( pspfSrchParserFilter->uiFilterTypeID == SRCH_PARSER_FILTER_TYPE_LIST_ID ) { /* Unmap the terms file */ iUtlFileMemoryUnMap(pucFilterFileMappingPtr, zFilterFileLength); pucFilterFileMappingPtr = NULL; /* Close the terms file */ s_fclose(pfFilterFile); } /* Free the term information structure */ if ( pstdiSrchTermDictInfos != NULL ) { for ( pstdiSrchTermDictInfosPtr = pstdiSrchTermDictInfos, uiI = 0; uiI < uiSrchTermDictInfosLength; pstdiSrchTermDictInfosPtr++, uiI++ ) { s_free(pstdiSrchTermDictInfosPtr->pucTerm); } s_free(pstdiSrchTermDictInfos); } s_free(pucFieldIDBitmap); s_free(pucTerm); s_free(pwcTerms); /* Handle the error */ if ( iError != SRCH_NoError ) { iSrchBitmapFree(*ppsbSrchBitmap); *ppsbSrchBitmap = NULL; } return (iError); }
int mbtransfer (char *ziel) //************************************************************************* // // TRANSFER-Prozedur // (wird fuer jedes transferierte File einzeln aufgerufen) // //************************************************************************* { char name[20]; strcpy(name, "mbtransfer"); lastfunc(name); char *line = b->line; int findex; FILE *oldf, *newf; char usermail = 0; int retwert = NO; int nocp; //no-copy flag char oldsubject[101]; unsigned long int oldfpos; char oldmsgty; char oldmailfname[10]; time_t oldmsgtime; char old_ziel[DIRLEN+1]; int old_usermail; char oldboardname[10]; char oldmailpath[FNAMELEN+1]; char zielcall[CALLEN+1]; char newcall[CALLEN+1]; int gleichesboard = NO; unsigned long nummer; #ifdef USERLT short int old_lt; #endif #ifdef DEBUG_FWD trace(report, "mbtransfer", "ziel: %s", ziel); #endif strupr(ziel); nexttoken(ziel, zielcall, CALLEN); strcpy(oldmailpath, b->mailpath); if (sema_test("sendlock") || m.disable) { putf(ms(m_sendnotpossible)); return NO; } if (mbcallok(zielcall)) { // Use newcall if (get_newcall(zielcall, newcall)) { strcpy(zielcall, newcall); putf(ms(m_usingnewcall), newcall); } } char *bbuf = (char *) t_malloc(sizeof(tvar_t) - sizeof(task_t), "tran"); char *oldfname; oldfname = (char *) t_malloc(sizeof(char) * (FNAMELEN+1), "tra2"); if (! bbuf || ! oldfname) return NO; memcpy(bbuf, (char *) b + sizeof(task_t), sizeof(tvar_t) - sizeof(task_t)); strlwr(b->mailpath); strcpy(oldfname, b->mailpath); strcpy(oldmailfname, b->mailfname); oldmsgtime = filename2time(b->mailfname); if ((oldf = s_fopen(oldfname, "srt")) != NULL) { fgets(b->line, BUFLEN - 1, oldf); // Befehlszeile einlesen mbsend_parse(line, 0); if (b->mailtype == 'A' || (b->mailtype == 'B' && b->eraseinfo == 'T')) { retwert = NIL; s_fclose(oldf); goto error_exit; } oldmsgty = b->conttype; // save mailflags ...(conttype) fgets(b->line, BUFLEN - 1, oldf); // Forwardzeile vernichten fgets(b->line, BUFLEN - 1, oldf); // Read-Zeile fgets(oldsubject, BETREFFLEN, oldf); // Betreff cut_blank(oldsubject); // Newline entfernen if (mbcallok(zielcall)) *b->at = 0; // Verteiler loeschen -> Neubestimmen strcpy(old_ziel, b->ziel); #ifdef USERLT old_lt = b->lifetime; b->lifetime = 0; #endif old_usermail = b->usermail; mbsend_parse(ziel, 2); if (! stricmp(b->ziel, b->mailpath+strlen(b->mailpath)-strlen(b->ziel)-8)) { retwert = NIL; s_fclose(oldf); goto error_exit; } b->conttype = oldmsgty; // set mailflags again.. (conttype) if (b->mailtype == 'B' && ! old_usermail) strcpy(b->ziel, old_ziel); weiterleiten(1, b->zielboard); waitfor(e_ticsfull); findex = finddir(b->zielboard, b->sysop); if (findex && !(strlen(b->zielboard)==1 && !b->sysop)) { if (xmkdir(b->boardpath)) { trace(serious, name, "mkdir %s error", b->boardpath); s_fclose(oldf); goto error_exit; } nocp = ! strcmp(b->herkunft, b->logincall) || b->sysop; //kein "CP " wenn Sysop! if (nocp || b->mailtype == 'B') strcpy(b->betreff, oldsubject); else sprintf(b->betreff, "CP %s: %.67s", b->logincall, oldsubject); //Bei Nicht-Bulletin BID neu generieren bzw. wenn BID fehlt if (b->mailtype != 'B'|| ! *b->bid) strcpy(b->bid, newbid()); make_mask(b->mailpath, b->boardfullname); strcpy(b->mask, b->mailpath); // Ursprungsboardnamen aus b->mailpath holen und mit ziel vergleichen strcpy(oldboardname, b->boardname); oldmailpath[strlen(oldmailpath)-8] = 0; if (finddir(oldmailpath,0) > 0) { if (! strcmp(ziel, b->boardname)) gleichesboard = YES; } else gleichesboard = NO; strcpy(b->boardname,oldboardname); // b->boardname wieder herstellen // bei Usermail oder gleichem Board zum Sortieren // Filezeit/-namen neu setzen if (mbcallok(zielcall) || gleichesboard) { strcpy(b->mailfname, time2filename(0)); } else strcpy(b->mailfname, oldmailfname); if (! strstr(b->mailpath, "*.*")) trace(fatal, name, "mask %s", b->mailpath); strcpy(strstr(b->mailpath, "*.*"), b->mailfname); strlwr(b->mailpath); if ((newf = s_fopen(b->mailpath, "sw+t")) != NULL) { s_fsetopt(newf, 1); #ifdef USERLT set_boardlife_max(old_lt); b->lifetime = old_lt; #endif writeheader(newf, 1); if (b->mailtype != 'B') { if (fgets(b->line, BUFLEN - 1, oldf)) { do { // fputs(line,f); skip old R-lines waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line == 'R' && line[1] == ':'); } fprintf(newf, "%s\n", makeheader(1)); fprintf(newf, "X-Transfer: %s by %s @ %s\n", datestr(ad_time(), 12), b->logincall, m.boxadress); fprintf(newf, "X-Original-Date: %s\n", datestr(oldmsgtime, 10)); do { if(( ! strncasecmp(line, "from", 4) || ! strncmp(line, "de: ", 4) || ! strncmp(line, "de ", 3) || ! strncmp(line, "fm ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (( ! strncasecmp(line, "to: ", 4) || ! strncasecmp(line, "to ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (! strncmp(line, "X-MID: ", 7)) fprintf(newf, "X-Old-MID: %s", line + 7); else if (! strncmp(line, "X-BID: ", 7)) fprintf(newf, "X-Old-BID: %s", line + 7); else fputs(line, newf); waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line != LF); fputc(LF, newf); } //Files binaer behandeln oldfpos = ftell(oldf); s_fclose(oldf); s_fclose(newf); writemailflags(); if ((oldf = s_fopen(oldfname, "srb")) != NULL) { if ((newf = s_fopen(b->mailpath, "sab")) != NULL) //append to file { fseek(oldf, oldfpos, SEEK_SET); do { //oe3dzw: Transferroutine transparent int len; len = fread(line, 1, 255, oldf); if (len) fwrite(line, 1, len, newf); waitfor(e_ticsfull); } while (! feof(oldf)); if (b->binstart) //bei binaeren Mails offset neu berechnen { b->binstart += ftell(newf) - ftell(oldf); if (b->binstart < 0) trace(serious, name, "offset %ld in %s", b->binstart, b->mailpath); } s_fclose(newf); if (b->binstart) writelines(); //Neuen Binstart speichern if (b->bytes) { if (old_usermail || gleichesboard) nummer = appenddirlist(1); else nummer = appenddirlist(0); //change old CHECKLINE if (b->usermail) { add_fwdfile("", get_fdelay(b->herkunft), 0); sprintf(b->line, "%s %lu", b->herkunft, nummer); mbtalk("\001", b->zielboard, b->line); trigger_ufwd(b->zielboard); } else { handle fh; char found; if (old_usermail) add_fwdfile("", get_fdelay(b->herkunft), 0); else add_fwdfile("", get_fdelay(b->herkunft), 1); if (findex > 0) tree[findex - 1].newestmail = oldmsgtime; if ((fh = s_open(CHECKNAME, "sr+b")) != EOF) { seek_fname(fh, b->mailfname, &found, 1); long pos = ltell(fh); if (found) { _read(fh, b->line, BLEN); sprintf(b->line + 15, "%-8s", b->boardname); b->line[23] = '~'; #ifdef USERLT char nlt[4]; sprintf(nlt, "%3.3d", b->boardlife_max); memcpy(b->line + 51, nlt, 3); #endif lseek(fh, -(LBLEN), SEEK_CUR); _write(fh, b->line, BLEN); } s_close(fh); if (found && (fh = s_open(CHECKNUMNAME, "sr+b")) != EOF) { lseek(fh, 2*(pos >> 6), SEEK_SET); //2* da 32bit! _write(fh, &nummer, 4); // 4Byte=32 bit s_close(fh); } } else trace(serious, name, "check"); } inc_mailgot(b->boardname); writemailflags(); retwert = OK;
/* Function: iPrsParseTextFile() Purpose: Adds term to the index for a given file. Parameters: pppPrsParser structure containing the various parser options we use to parse the data ppfPrsFormat file profile pointing to the various file options we use to parse the data pucFilePath file path to be parsed pfInputFile data stream to be parsed pfIndexerFile structured index stream output file pfDataLength return pointer for the data length parsed Globals: none Returns: 0 on success, -1 on error */ int iPrsParseTextFile ( struct prsParser *pppPrsParser, struct prsFormat *ppfPrsFormat, unsigned char *pucFilePath, FILE *pfInputFile, FILE *pfIndexerFile, float *pfDataLength ) { int iError = UTL_NoError; int iStatus = 0; FILE *pfLocalFile = NULL; unsigned char *pucLine = NULL; unsigned char *pucNormalizedLine = NULL; wchar_t *pwcLine = NULL; unsigned int uiLineLength = 0; unsigned int ulLineCapacity = 0; unsigned int uiNormalizedLineCapacity = 0; wchar_t *pwcParseLinePtr = NULL; off_t zCurrentOffset = 0; off_t zStartOffset = 0; off_t zEndOffset = 0; unsigned int uiTermPosition = 0; unsigned char pucTrueFilePath[UTL_FILE_PATH_MAX + 1] = {'\0'}; unsigned int uiLanguageID = LNG_LANGUAGE_ANY_ID; unsigned int uiFieldID = 0; boolean bIndexLine = false; boolean bParseLine = false; boolean bTermPositions = false; boolean bIndexing = false; boolean bSetStartCharacter = true; boolean bFinishDocument = false; float fLineLength = 0; float fDataLength = 0; /* Check the parameters */ if ( pppPrsParser == NULL ) { iUtlLogError(UTL_LOG_CONTEXT, "Null 'pppPrsParser' parameter passed to 'iPrsParseTextFile'."); return (-1); } if ( ppfPrsFormat == NULL ) { iUtlLogError(UTL_LOG_CONTEXT, "Null 'ppfPrsFormat' parameter passed to 'iPrsParseTextFile'."); return (-1); } if ( pfIndexerFile == NULL ) { iUtlLogError(UTL_LOG_CONTEXT, "Null 'pfIndexerFile' parameter passed to 'iPrsParseTextFile'."); return (-1); } if ( (bUtlStringsIsStringNULL(pucFilePath) == true) && (pfInputFile == NULL) ) { iUtlLogError(UTL_LOG_CONTEXT, "Null or empty 'pucFilePath' &'pfInputFile' parameters passed to 'iPrsParseTextFile'."); return (-1); } if ( (bUtlStringsIsStringNULL(pucFilePath) == false) && (pfInputFile != NULL) ) { iUtlLogError(UTL_LOG_CONTEXT, "Invalid 'pucFilePath' &'pfInputFile' parameters passed to 'iPrsParseTextFile'."); return (-1); } if ( pfDataLength == NULL ) { iUtlLogError(UTL_LOG_CONTEXT, "Null 'pfDataLength' parameter passed to 'iPrsParseTextFile'."); return (-1); } /* Preset the data length return pointer */ *pfDataLength = 0; /* Open the file path if it was provided */ if ( bUtlStringsIsStringNULL(pucFilePath) == false ) { /* Get the real file path of this file */ if ( (iError = iUtlFileGetTruePath(pucFilePath, pucTrueFilePath, UTL_FILE_PATH_MAX + 1)) != UTL_NoError ) { iUtlLogError(UTL_LOG_CONTEXT, "Failed to get the true path of the file path: '%s', utl error: %d.", pucFilePath, iError); iStatus = -1; goto bailFromlPrsParseTextFile; } /* Open the file to index */ if ( (pfLocalFile = s_fopen(pucTrueFilePath, "r")) == NULL ) { /* Send a message ** M message */ if ( fprintf(pfIndexerFile, "M File: '%s' could not be opened.\n", pucTrueFilePath) < 0 ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to send a message line to the indexer"); } iStatus = -1; goto bailFromlPrsParseTextFile; } /* Send a message to the indexer ** M (Message to be displayed by the indexer) */ if ( pppPrsParser->bSuppressMessages == false ) { if ( fprintf(pfIndexerFile, "M Parsing file: '%s'.\n", pucTrueFilePath) < 0 ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to send a message line to the indexer"); } } } /* Otherwise read from the input file */ else if ( pfInputFile != NULL ) { pfLocalFile = pfInputFile; } /* Otherwise croak */ else { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to find data either from a file path or an input file stream"); } /* Initialize for the first document */ zCurrentOffset = 0; zStartOffset = 0; zEndOffset = 0; uiTermPosition = 1; bIndexing = false; bSetStartCharacter = true; bFinishDocument = false; /* Loop around reading every line in the file */ while ( true ) { boolean bEoF = false; unsigned char *pucLineEndPtr = NULL; /* Reset the line to an empty string, note that pucLine is dynamically ** allocated so we make sure that it is allocated before doing so */ if ( pucLine != NULL ) { pucLine[0] = '\0'; } /* Reset the line length */ uiLineLength = 0; /* This ugly little loop reads stuff from the file we are indexing making sure that ** it reads an entire actual line (ie not limited by the fact that fgets() can only ** read fixed length buffers) and erases any end of line characters */ do { /* Allocate/reallocate lines if needed */ if ( (pucLine == NULL) || (ulLineCapacity == 0) || ((uiLineLength + BUFSIZ) > ulLineCapacity) ) { unsigned char *pucLinePtr = NULL; /* Extend the line */ if ( (pucLinePtr = (unsigned char *)s_realloc(pucLine, (size_t)(sizeof(unsigned char) * (ulLineCapacity + BUFSIZ)))) == NULL ) { iStatus = -1; goto bailFromlPrsParseTextFile; } /* Hand over the pointer */ pucLine = pucLinePtr; /* Clear the new allocation */ s_memset(pucLine + ulLineCapacity, 0, BUFSIZ); /* Set the line capacity */ ulLineCapacity += BUFSIZ; /* Extend the normalized line if normalization is supported */ if ( pppPrsParser->pvLngUnicodeNormalizer != NULL ) { unsigned char *pucNormalizedLinePtr = NULL; /* Set the normalized line capacity */ uiNormalizedLineCapacity = ulLineCapacity * LNG_UNICODE_NORMALIZATION_EXPANSION_MULTIPLIER_MAX; /* Extend the normalized line */ if ( (pucNormalizedLinePtr = (unsigned char *)s_realloc(pucNormalizedLine, (size_t)(sizeof(unsigned char) * uiNormalizedLineCapacity))) == NULL ) { iStatus = -1; goto bailFromlPrsParseTextFile; } /* Hand over the pointer */ pucNormalizedLine = pucNormalizedLinePtr; } /* Extend the wide character line */ { wchar_t *pwcLinePtr = NULL; /* Extend the wide character line */ if ( (pwcLinePtr = (wchar_t *)s_realloc(pwcLine, (size_t)(sizeof(wchar_t) * ulLineCapacity))) == NULL ) { iStatus = -1; goto bailFromlPrsParseTextFile; } /* Hand over the pointer */ pwcLine = pwcLinePtr; } } /* Read the next line chunk, appending to the current line and setting the end of file flag */ bEoF = (s_fgets(pucLine + uiLineLength, ulLineCapacity - uiLineLength, pfLocalFile) == NULL) ? true : false; /* Get the new line length here for optimization */ uiLineLength = s_strlen(pucLine); /* Erase the trailing new line - be platform sensitive, handle PC first, then Unix and Mac */ if ( (uiLineLength >= 2) && (pucLine[uiLineLength - 2] == '\r') ) { pucLineEndPtr = pucLine + (uiLineLength - 2); uiLineLength -= 2; } else if ( (uiLineLength >= 1) && ((pucLine[uiLineLength - 1] == '\n') || (pucLine[uiLineLength - 1] == '\r')) ) { pucLineEndPtr = pucLine + (uiLineLength - 1); uiLineLength -= 1; } else if ( (uiLineLength >= 1) && (bEoF == true) ) { pucLineEndPtr = pucLine + uiLineLength; } else { pucLineEndPtr = NULL; } if ( pucLineEndPtr != NULL ) { *pucLineEndPtr = '\0'; } } while ( (pucLineEndPtr == NULL) && (bEoF == false) ); /* Increment the line length */ fLineLength++; /* Increment the data length */ fDataLength += uiLineLength; /* Set the current character */ zCurrentOffset += uiLineLength; /* Check to see if we have reached the end of the file, if we have we finish the document and bail */ if ( (bEoF == true) && (pucLineEndPtr == NULL) ) { /* Finish the document if we are indexing */ if ( bIndexing == true ) { /* Finish the document */ if ( iPrsFinishDocument(pppPrsParser, ppfPrsFormat, pfIndexerFile, pucTrueFilePath, zStartOffset, zCurrentOffset - 1, uiTermPosition - 1) != 0 ) { iStatus = -1; goto bailFromlPrsParseTextFile; } } break; } /* Reset the wide character line */ if ( pwcLine != NULL ) { pwcLine[0] = L'\0'; } /* Set the parse line pointer */ pwcParseLinePtr = pwcLine; /* Convert the line from its native character set to wide characters */ if ( bUtlStringsIsStringNULL(pucLine) == false ) { /* Set the line pointer */ unsigned char *pucLinePtr = pucLine; /* Use a separate variable for the line length */ unsigned int uiLineAllocatedByteLength = ulLineCapacity * sizeof(wchar_t); /* Clean the unicode if requested */ if ( pppPrsParser->bCleanUnicode == true ) { /* Clean the unicode */ if ( (iError = iLngUnicodeCleanUtf8String(pucLinePtr, PRS_UNICODE_REPLACEMENT_CHARACTER)) != LNG_NoError ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to clean the string, lng error: %d, string: '%s'", iError, pucLinePtr); } } /* Normalize the line if the unicode normalizer is enabled */ if ( pppPrsParser->pvLngUnicodeNormalizer != NULL ) { /* Normalize the line */ if ( (iError = iLngUnicodeNormalizeString(pppPrsParser->pvLngUnicodeNormalizer, pucLinePtr, uiLineLength, &pucNormalizedLine, &uiNormalizedLineCapacity)) != LNG_NoError ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to normalize the string, lng error: %d, string: '%s'", iError, pucLinePtr); } /* Set the line pointer */ pucLinePtr = pucNormalizedLine; uiLineLength = s_strlen(pucLinePtr); } /* Convert the line from utf-8 to wide character, note the conversion error handling */ if ( (iError = iLngConverterConvertString(pppPrsParser->pvLngConverter, ((pppPrsParser->bSkipUnicodeErrors == true) ? LNG_CONVERTER_SKIP_ON_ERROR : LNG_CONVERTER_RETURN_ON_ERROR), pucLinePtr, uiLineLength, (unsigned char **)&pwcLine, &uiLineAllocatedByteLength)) != LNG_NoError ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to convert the string from utf-8 set to wide characters, lng error: %d, string: '%s'", iError, pucLinePtr); } /* Set the parse line pointer */ pwcParseLinePtr = pwcLine; } /* Check for a document start if a start function was supplied */ if ( (ppfPrsFormat->bPrsDocumentStartFunction != NULL) && (ppfPrsFormat->bPrsDocumentStartFunction(pwcParseLinePtr) == true) ) { /* We need to finish the current document if we are currently indexing */ if ( bIndexing == true ) { /* Set the end character if it has not been set, this occurs if we have ** both a start function and an end function, and we detect a new document ** start without having first detected a document end */ if ( zEndOffset <= zStartOffset ) { zEndOffset = (zCurrentOffset - uiLineLength) - 1; } /* Finish the document, we do this here because we dont want to process the current line, it belongs to the new document */ if ( iPrsFinishDocument(pppPrsParser, ppfPrsFormat, pfIndexerFile, pucTrueFilePath, zStartOffset, zEndOffset, uiTermPosition - 1) != 0 ) { iStatus = -1; goto bailFromlPrsParseTextFile; } /* Check to see if we have reached the document count limit and bail if we have */ if ( (pppPrsParser->uiDocumentCountMax > 0) && (pppPrsParser->uiDocumentCount >= pppPrsParser->uiDocumentCountMax) ) { break; } /* Initialize for the next document */ uiTermPosition = 1; } else { /* Turn on indexing */ bIndexing = true; } /* Set the start character */ zStartOffset = zCurrentOffset - uiLineLength; bSetStartCharacter = false; } /* We are always indexing if there is no start function, because if we ** reach the end of a document, we are automatically indexing the next one */ else if ( ppfPrsFormat->bPrsDocumentStartFunction == NULL ) { /* Make sure indexing is turned on */ bIndexing = true; /* Set the start character if needed */ if ( bSetStartCharacter == true ) { zStartOffset = zCurrentOffset - uiLineLength; bSetStartCharacter = false; } } /* Check for a document end if an end function was supplied */ if ( (ppfPrsFormat->bPrsDocumentEndFunction != NULL) && (ppfPrsFormat->bPrsDocumentEndFunction(pwcParseLinePtr) == true) && (fLineLength > 1) ) { /* Finish the document if we run into a document end */ if ( bIndexing == true ) { /* Request that we set a new start character, finish the document, and turn off indexing */ bSetStartCharacter = true; bFinishDocument = true; bIndexing = false; /* Set the end character */ zEndOffset = zCurrentOffset - 1; } } /* No end function */ else if ( ppfPrsFormat->bPrsDocumentEndFunction == NULL ) { /* Set the end character */ zEndOffset = zCurrentOffset - 1; } /* Just loop to read the next line if we are not indexing and we dont need to finish a document */ if ( (bIndexing == false) && (bFinishDocument == false) ) { continue; } /* Clear the parameters */ uiLanguageID = LNG_LANGUAGE_ANY_ID; uiFieldID = 0; bIndexLine = true; bParseLine = true; bTermPositions = true; /* Process the document line */ if ( ppfPrsFormat->vPrsDocumentLineFunction != NULL ) { ppfPrsFormat->vPrsDocumentLineFunction(pwcParseLinePtr, &uiLanguageID, &uiFieldID, &bIndexLine, &bParseLine, &bTermPositions); } /* Index the contents of the line */ if ( bIndexLine == true ) { /* Parse the line */ if ( bParseLine == true ) { /* Parse the text line */ if ( iPrsParseTextLine(pppPrsParser, ppfPrsFormat, pfIndexerFile, pwcParseLinePtr, pwcParseLinePtr + s_wcslen(pwcParseLinePtr), uiLanguageID, uiFieldID, (bTermPositions == true) ? &uiTermPosition : NULL) != 0 ) { if ( fprintf(pfIndexerFile, "M Failed to add the document terms.\n") < 0 ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to send a message line to the indexer"); } } } /* Get a term from the line and add */ else { wchar_t *pwcLinePtr = NULL; /* Find the start of the term */ for ( pwcLinePtr = pwcParseLinePtr; *pwcLinePtr != L'\0'; pwcLinePtr++ ) { if ( iswalnum(*pwcLinePtr) != 0 ) { break; } } /* Is the term long enough to add? */ if ( s_wcslen(pwcLinePtr) >= pppPrsParser->uiTermLengthMinimum ) { /* Send the language line if the language is known */ if ( uiLanguageID != LNG_LANGUAGE_ANY_ID ) { unsigned char pucLanguageCode[LNG_LANGUAGE_CODE_LENGTH + 1] = {'\0'}; if ( iLngGetLanguageCodeFromID(uiLanguageID, pucLanguageCode, LNG_LANGUAGE_CODE_LENGTH + 1) == LNG_NoError ) { /* Send the language ** L language{A} */ if ( fprintf(pfIndexerFile, "L %s\n", pucLanguageCode) < 0 ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to send a language line to the indexer"); } } } /* Send the term to the indexer */ if ( iPrsSendTermToIndexer(pppPrsParser, ppfPrsFormat, pfIndexerFile, pwcLinePtr, pwcLinePtr + s_wcslen(pwcLinePtr), uiFieldID, (bTermPositions == true) ? uiTermPosition : 0) != 0 ) { if ( fprintf(pfIndexerFile, "M Failed to add a document term.\n") < 0 ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to send a message line to the indexer"); } } /* Increment the term position */ if ( bTermPositions == true ) { uiTermPosition++; } } } } /* Finish the document if we were requested to do so */ if ( bFinishDocument == true ) { /* Finish the current document */ if ( iPrsFinishDocument(pppPrsParser, ppfPrsFormat, pfIndexerFile, pucTrueFilePath, zStartOffset, zEndOffset, uiTermPosition - 1) != 0 ) { if ( fprintf(pfIndexerFile, "M Failed to finish adding a document.\n") < 0 ) { iUtlLogPanic(UTL_LOG_CONTEXT, "Failed to send a message line to the indexer"); } } /* Check to see if we have reached the document count limit */ if ( (pppPrsParser->uiDocumentCountMax > 0) && (pppPrsParser->uiDocumentCount >= pppPrsParser->uiDocumentCountMax) ) { break; } /* Initialize for the next document */ uiTermPosition = 1; /* Turn off the flag requesting that we finish the document */ bFinishDocument = false; } } /* while (true) */ /* Bail label */ bailFromlPrsParseTextFile: /* Close the file descriptor if we opened it ourselves */ if ( bUtlStringsIsStringNULL(pucFilePath) == false ) { s_fclose(pfLocalFile); } /* Free the line pointers */ s_free(pucLine); s_free(pucNormalizedLine); s_free(pwcLine); /* Increment the data length return pointer */ *pfDataLength += fDataLength; return (iStatus); }
int sysbef (char *befbuf) //************************************************************************* // //************************************************************************* { static char shutdown_reason[23]; char xbuf[20]; static char *beftab[] = { "CONNECT", "LOGIN", "CALL", "OSHELL", #ifdef __DOS16__ #ifdef _TNC "TNC", #endif "W2", "UWIN", "TWIN", #ifdef _AUTOTRCWIN "TRWIN", #endif #endif "RTEXT", "CAT", "RPRG", "WTEXT", "WPRG", "RBIN", "WBIN", "SLR", "CLOG", "REORG", "LIFETIME", "MKBOARD", "RMBOARD", "MVBOARD", "SHUTDOWN", "NEW", "KILL", "TEST", "IMPORT", "DISABLE", "ENABLE", #ifdef DIEBOX_UIMPORT "UIMPORT", #endif #ifdef OLDMAILIMPORT "OLDMAILIMPORT", #endif "SETUSER", "BEACON", "GREP", "TGREP", "TAIL", "BEGIN", "BATCH", "EXPORT", "PWGEN", "POSTFWD", "MONITOR", "NOTE", "MACRO", "CFGFLEX", "ORM", "OMV", "OCP", "OMD", "APPEND", #ifdef DF3VI_EXTRACT "EXTRACT", #endif "HOLD", "SETPW", #ifdef FEATURE_YAPP "WYAPP", "RYAPP", #endif #ifdef FEATURE_DIDADIT "WDIDADIT", "RDIDADIT", #endif #if defined FEATURE_SERIAL || defined _TELEPHONE "TTYINIT", #endif #ifdef _TELEPHONE // JJ "TTYCMD", "TTYDIAL", "TTYHANGUP", "TTYSTATUS", "TTYWIN", "TTYCOUNTERRESET", #endif #ifdef _AUTOFWD "AFWDLIST", #endif #ifdef FEATURE_MDPW "MD2SUM", "MD5SUM", #endif #ifdef FEATURE_EDITOR "EDIT", "FEDIT", "REDIT", #else #ifdef DF3VI_FWD_EDIT "FEDIT", "FWDEDIT", #endif #ifdef DF3VI_REJ_EDIT "REDIT", "REJECTEDIT", #endif #ifdef DF3VI_CONV_EDIT "CEDIT", "CONVEDIT", #endif #endif #ifdef _FILEFWD "FWDIMPORT", "FWDEXPORT", #endif "YMBTEST", "SCMDLIST", // Dies ist immer das letzte Kommando! NULL }; enum befnum { unsinn, connect_, login, call_, oshell_, #ifdef __DOS16__ #ifdef _TNC tnc, #endif w2, uwin, twin, #ifdef _AUTOTRCWIN trwin, #endif #endif rtext, rtext_, rprg, wtext, wprg, rbin, wbin, slr, clog, reorg, life_, mkb, rmb, mvb, shutdown_, new_, kill_, test, import, disable_, enable_, #ifdef DIEBOX_UIMPORT uimport_, #endif #ifdef OLDMAILIMPORT oldmailimport_, #endif setuser, beacon, grep_, tgrep, tail, begin, batch, export_, pwgen, postfwd_, monitor_, note, macro, cfgflex_, orm, omv, ocp, omd, _append, #ifdef DF3VI_EXTRACT extract_, #endif hold, setpw, #ifdef FEATURE_YAPP wyapp, ryapp, #endif #ifdef FEATURE_DIDADIT wdidadit, rdidadit, #endif #if defined FEATURE_SERIAL || defined _TELEPHONE ttyinit, #endif #ifdef _TELEPHONE // JJ ttycmd, ttydial, ttyhangup, ttystatus, ttywin_, ttycounterreset, #endif #ifdef _AUTOFWD afwdlist_, #endif #ifdef FEATURE_MDPW md2sum, md5sum, #endif #ifdef FEATURE_EDITOR edit, fedit, redit, #else #ifdef DF3VI_FWD_EDIT fedit, fwdedit, #endif #ifdef DF3VI_REJ_EDIT redit, rejectedit, #endif #ifdef DF3VI_CONV_EDIT cedit, convedit_, #endif #endif #ifdef _FILEFWD fwdimport, fwdexport, #endif ymbtest, scmdlist // Dies ist immer das letzte Kommando! } cmd = unsinn; befbuf += blkill(befbuf); cmd = (befnum) readcmd(beftab, &befbuf, 0); switch (cmd) { #ifdef FEATURE_YAPP case ryapp: #endif #ifdef FEATURE_DIDADIT case rdidadit: #endif #if defined(FEATURE_YAPP) || defined(FEATURE_DIDADIT) break; #endif default: if (u->lf != 6) putv(LF); leerzeile(); // Sends the number of CRs stored in "ALTER LF" } switch (cmd) { case unsinn: if ( mbinitbef(befbuf, 0) #ifdef _TELEPHONE // JJ || ttyinitbef(befbuf, 0) #endif ) { strcpy(xbuf, "^"); mbparsave(); #ifdef _TELEPHONE // JJ ttyparsave(); #endif strncpy(xbuf + 1, befbuf, 18); xbuf[19] = 0; subst1(xbuf, ' ', 0); subst1(xbuf, '=', 0); grep(MBINITNAME, xbuf, o_i); #ifdef _TELEPHONE // JJ grep(INITTTYNAME, xbuf, o_i); #endif return OK; } else return NO; case note: trace(replog, "note", "%s", befbuf); break; #ifdef DF3VI_EXTRACT case extract_: mbchange(befbuf, w_extract, 1); break; #endif case hold: mbchange(befbuf, w_hold, 1); break; case omv: { char f1[50], f2[50]; befbuf = nexttoken(befbuf, f1, 49); befbuf = nexttoken(befbuf, f2, 49); if (! *f1 || ! *f2 || xrename(f1, f2)) putf(ms(m_error)); else { putf(ms(m_moving)); putf(ms(m_nach), f1, f2); } break; } case ocp: { char f1[50], f2[50]; befbuf = nexttoken(befbuf, f1, 49); befbuf = nexttoken(befbuf, f2, 49); if (! *f1 || ! *f2 || filecopy(f1, f2)) putf(ms(m_error)); else { putf(ms(m_copying)); putf(ms(m_nach), f1, f2); } break; } case orm: { char f1[50]; befbuf = nexttoken(befbuf, f1, 49); if (! *f1 || xunlink(f1)) putf(ms(m_filecantdeleted), f1); else putf(ms(m_filedeleted), f1); break; } case omd: { char f1[50]; befbuf = nexttoken(befbuf, f1, 49); killbackslash(f1); if (! *f1 || xmkdir(f1)) putf(ms(m_directorycantcreated), f1); else putf(ms(m_directorycreated), f1); break; } case _append: { char textline[LINELEN+1]; befbuf = nexttoken(befbuf, textline, LINELEN); if (! *befbuf) { putf("Syntax: APPEND <textline> <filename>\n"); break; } FILE *f = s_fopen(befbuf, "sat"); if (f) { fprintf(f, "%s\n", textline); s_fclose(f); } else putf(ms(m_filenotfound), befbuf); } break; case macro: { mk_start(befbuf); } break; case setuser: { char call[CALLEN+1]; befbuf = nexttoken(befbuf, call, CALLEN+1); strupr(call); if (mbcallok(call) && *befbuf) { trace(report, "setuser", "%s", befbuf); { if (! mbalter(NULL, befbuf, call)) putf(ms(m_isunknown), call); b->msg_loadnum = 0; //reload msg loaduser(b->logincall, u, 1); } } else putf("Syntax: SETUSER <call> <option> <value>\n"); } break; case setpw: //automatisierte Passwort-Vergabe { char call[CALLEN+1]; char passwd[40]; int i, pwline = 0; FILE *upwf; befbuf = nexttoken(befbuf, call, CALLEN+1); strupr(call); pwline = atoi(befbuf); if (! mbcallok(call) || ! pwline) { putf("Syntax: SETPW <call> <number>\n"); break; } if (! loaduser(call, u, 0)) { putf(ms(m_isunknown), call); break; } upwf = s_fopen("userpw.bcm", "sr"); if (! upwf) { putf(ms(m_filenotfound), "userpw.bcm"); break; } for (i = 0; i < pwline && ! feof(upwf); i++) fgets(passwd, sizeof(passwd) - 1, upwf); s_fclose(upwf); if (i < pwline) { putf(ms(m_userpwlines), i - 1); break; } strcpy(u->password, passwd); saveuser(u); pwline = strlen(u->password); putf(ms(m_loginpw), pwtypestr(u->loginpwtype), pwtypestr(u->sfpwtype)); putf(" "); putf(ms(m_pwdlength), pwline); sprintf(passwd, "pw set to %i char", pwline); pwlog(call, b->logincall, passwd); b->msg_loadnum = 0; //reload msg loaduser(b->logincall, u, 1); } break; #ifdef DIEBOX_UIMPORT case uimport_: { putf(ms(m_dieboximport)); uimport(); } break; #endif #ifdef OLDMAILIMPORT case oldmailimport_: { scanoptions(befbuf); formoptions(); befbuf += blkill(befbuf); if (isdir(befbuf)) { putf(ms(m_omi_started), befbuf); putflush(); oldmailimport(befbuf); } else putf(ms(m_dirunknown), befbuf); } break; #endif case disable_: { putf(ms(m_boxdisabled)); m.disable = 1; mbparsave(); } break; case enable_: { putf(ms(m_boxenabled)); m.disable = 0; mbparsave(); } break; case test: { if (*befbuf == 'W') { while (1); } // for testing watchdog else if (*befbuf == 'S') { trace(fatal, "test", "abort"); } else if (*befbuf == 'V') { *(char *)0 = 1; } else mk_start(befbuf); } break; case batch: { runbatch(befbuf); } break; case rtext: case rtext_: { fileio_text fio; fio.usefile(befbuf); fio.tx(); putf("\032\n"); // CTRL-Z } break; case wtext: { fileio_text fio; fio.usefile(befbuf); fio.rx(); } break; case rbin: case rprg: { fileio_abin fio; fio.usefile(befbuf); fio.tx(); } break; case wbin: case wprg: { fileio_abin fio; fio.usefile(befbuf); fio.rx(); } break; #ifdef FEATURE_YAPP case ryapp: { fileio_yapp fio; fio.usefile(befbuf); fio.tx(); } break; case wyapp: { fileio_yapp fio; fio.usefile(befbuf); fio.rx(); } break; #endif // FEATURE_YAPP #ifdef FEATURE_DIDADIT case rdidadit: { fileio_dida fio; fio.usefile(befbuf); fio.tx(); } break; case wdidadit: { fileio_dida fio; if (! *befbuf) fio.usefile("dummy"); else { if (befbuf[strlen(befbuf) - 1] != '/') strcat(befbuf, "/"); strcat(befbuf, "dummy"); fio.usefile(befbuf); } fio.rx(); } break; #endif // FEATURE_DIDADIT case slr: { scanoptions(befbuf); putlog(TRACEPATH "/" SYSLOGRNAME, befbuf); } break; case clog: { scanoptions(befbuf); putlog(TRACEPATH "/" CMDLOGNAME, befbuf); } break; case tail: { scanoptions(befbuf); befbuf += blkill(befbuf); if (b->optplus&o_f && *befbuf) { int a; FILE *f = s_fopen(befbuf, "lrt"); if (f) { fseek(f, 0, SEEK_END); do { while ((a = fgetc(f)) != EOF) putv(a); wdelay(349); } while (! testabbruch()); s_fclose(f); } } else { fileio_text fio; fio.usefile(befbuf); fio.settail(-2000); fio.tx(); } } break; case begin: { fileio_text fio; fio.usefile(befbuf); fio.settail(2000); fio.tx(); } break; case monitor_: { if (*befbuf) { scanoptions(befbuf); b->continous = 1; monitor(atoi(befbuf), b->optplus); } else putf("Syntax: MONITOR [-iords] <task-id>\n"); } break; case tgrep: { char string[61]; char name[40]; scanoptions(befbuf); if (b->optminus & o_i) b->optplus |= o_i; //wenn nicht explizit "-i-", ist "-i" default b->usermail = 0; if (! *befbuf) { putf("Syntax: TGREP [pattern] <fwd-bbs>\n"); break; } befbuf = nexttoken(befbuf, string, 60); if (*befbuf) { sprintf(name, TRACEPATH "/t_%s.bcm", befbuf); grep(name, string, b->optplus); } else { sprintf(name, TRACEPATH "/t_%s.bcm", string); putlog(name, ""); } } break; case grep_: { char string[61]; scanoptions(befbuf); if (b->optminus & o_i) b->optplus |= o_i; //wenn nicht explizit "-i-", ist "-i" default b->usermail = 0; befbuf = nexttoken(befbuf, string, 60); grep(befbuf, string, b->optplus); } break; #ifdef _AUTOFWD case afwdlist_: { afwdlist(befbuf); } break; #endif case life_: { if (*befbuf) { strupr(befbuf); char *life = skip(befbuf); int board = finddir(befbuf, b->sysop); if (board > 0) { board -= 1; if (life && *life) { tree[board].lifetime_max = atoi(life); tree[board].lifetime_min = 1; if (tree[board].lifetime_max > 999) tree[board].lifetime_max = 999; if (tree[board].lifetime_max < 1) tree[board].lifetime_max = 1; char *life_min = skip(life); if (life_min && *life_min) { tree[board].lifetime_min = atoi(life_min); if (tree[board].lifetime_min > 999) tree[board].lifetime_min = 999; if (tree[board].lifetime_min < 1) tree[board].lifetime_min = 1; } mbtreesave(); } putf(ms(m_lifetimestat), b->boardfullname, tree[board].lifetime_max, tree[board].lifetime_min); } else putf(ms(m_notfound), befbuf); } else putf("Syntax: LIFETIME <board> <days_maximum> [<days_minimum>]\n" " (with 1 <= days_maximum/days_minimum <= 999)\n\n"); } break; #ifdef _TNC case tnc: { control_tnc(befbuf); } break; #endif case connect_: { termqso(befbuf); } break; case login: { if (mbcallok(befbuf)) { mblogin(befbuf, login_standard, b->uplink); cmdlog("login changed"); putf(ms(m_loginchanged)); } else putf("Syntax: LOGIN <new logincall>\n"); } break; case call_: { if (mbcallok(befbuf)) { mblogin(befbuf, login_silent, b->uplink); b->msg_loadnum--; //Sonst wird falsche Sprache benutzt cmdlog("call changed"); } else putf("Syntax: CALL <new logincall>\n"); } break; case oshell_: { if (t->input == io_file || t->output == io_file) oshell(befbuf, sh_noinput); else oshell(befbuf, m.dosinput ? sh_forceinput : sh_ifmultitask); } break; case reorg: { if (sema_test("purgereorg") == 1) putf(ms(m_purgeallstarted)); else { putf(ms(m_reorginvoked)); fork(P_BACK | P_MAIL, 0, mbreorg, befbuf); } } break; case postfwd_: { putf(ms(m_postfwdinvoked)); fork(P_BACK | P_MAIL, 0, postfwd, "Postfwd"); } break; #ifdef FEATURE_EDITOR case edit: { fork(P_WIND | P_KEYB, 0, editfile, befbuf); } break; case fedit: { fork(P_WIND | P_KEYB, 0, editfile, FWDLISTNAME); } break; case redit: { fork(P_WIND | P_KEYB, 0, editfile, REJECTNAME); } break; #else #ifdef DF3VI_FWD_EDIT case fedit: //wenn kein editor vorhanden remote-editor aufrufen case fwdedit: { fwdlistedit(befbuf); } break; #endif #ifdef DF3VI_REJ_EDIT case redit: case rejectedit: { rejectlistedit(befbuf); } break; #endif #ifdef DF3VI_CONV_EDIT case cedit: case convedit_: { convedit(befbuf); } break; #endif #endif case new_: { scanoptions(befbuf); mbinit(); initfwdlist(); #ifdef _AUTOFWD initafwdlist(); #endif if (! (b->optplus & o_q)) // skip statistics on "new -q" { b->optplus = o_s | o_f | o_c; putf(ms(m_hadrstat)); browse_hadr(""); } mbcvtload(); #ifdef RUNUTILS read_runfile(); #endif msg_dealloc(1); mk_read_jobs(); } break; case kill_: { if (atoi(befbuf)) { while (atoi(befbuf)) { if (! killtask(nextdez(&befbuf), 1)) putf(ms(m_cantkilltask)); } } else putf("Syntax: KILL <task-id>\n"); } break; #ifdef __DOS16__ case w2: { fork(P_WIND | P_KEYB|P_MAIL, 0, mbwin2, m.sysopcall); } break; case uwin: { fork(P_WIND | P_KEYB|P_MAIL, 0, userwin, "Users"); } break; case twin: { fork(P_WIND | P_MAIL, 0, taskwin, befbuf); } break; #ifdef _AUTOTRCWIN case trwin: { if (*befbuf) fork(P_WIND | P_MAIL, 0, trcwin, befbuf); else putf("Syntax: TRWIN [-iords] <task-id>\n"); } break; #endif #endif //__DOS16__ case mkb: { char mainboard[30]; char newboard[20]; char *slash; befbuf = nexttoken(befbuf, mainboard, 29); befbuf = nexttoken(befbuf, newboard, 19); slash = strchr(mainboard + 1, '/'); if (slash && (! *newboard)) { *slash = 0; strcpy(newboard, slash + 1); } if (! *newboard && *mainboard == '/') { strcpy(newboard, mainboard + 1); mainboard[1] = 0; } if (*mainboard && *newboard) { switch (mkboard(mainboard, newboard, 0)) { case 0: putf(ms(m_boardcreated)); break; case 1: putf(ms(m_mainboardnotfound)); break; case 2: putf(ms(m_toomanyboards)); break; case 3: putf(ms(m_boardnameexist)); break; case 4: putf(ms(m_invalidboardname)); break; } } else putf("Syntax: MKBOARD <mainboard> <subboard>\n"); } break; case rmb: { if (*befbuf) { subst1(befbuf, ' ', '/'); if (*befbuf == '/' && befbuf[1] == '/') befbuf++; switch (rmboard(befbuf)) { case 0: putf(ms(m_boardremoved)); break; case 1: putf(ms(m_boardnotfound)); break; case 2: putf(ms(m_boardnotempty)); break; } } else putf("Syntax: RMBOARD <mainboard> <subboard>\n"); } break; case mvb: { char oldboard[20]; char subboard[20]; char neuboard[20]; befbuf = nexttoken(befbuf, oldboard, 19); befbuf = nexttoken(befbuf, subboard, 19); befbuf = nexttoken(befbuf, neuboard, 19); if (*oldboard && *subboard && *neuboard) { switch (mvboard(oldboard, subboard, neuboard)) { case 0: putf(ms(m_boardmoved)); break; case 1: putf(ms(m_newboardnotfound)); break; case 2: putf(ms(m_toomanyboards)); break; case 4: putf(ms(m_oldboardnotfound)); break; } } else putf("Syntax: MVBOARD <oldboard> <subboard> <newboard>\n"); } break; case shutdown_: { scanoptions(befbuf); #ifdef __DOS16__ if (b->optplus & o_r) atexit((void(*)()) MK_FP(0xffff, 0x0000)); #endif runterfahren = 1; sprintf(shutdown_reason, "shutdown by %s", b->logincall); stopreason = shutdown_reason; } break; case cfgflex_: { if (*befbuf && file_isreg("cfgflex.bcm")) { putf(ms(m_flexstarted)); fork(P_BACK | P_MAIL, 0, cfgflex, befbuf); } else putf("Syntax: CFGFLEX <flexcall> (cfgflex.bcm must exist)\n"); } break; case import: { sysimport(befbuf); } break; case export_: { if (*befbuf) { if ((t->input != io_file || t->output == io_dummy) && t->output != io_file) { char fname[51]; scanoptions(befbuf); befbuf = nexttoken(befbuf, fname, 50); if (b->optplus & o_a) // neue Option -b fuer binaer { if (b->optplus & o_b) b->outputfile = s_fopen(fname, "sab"); else b->outputfile = s_fopen(fname, "sat"); } else { if (b->optplus & o_b) b->outputfile = s_fopen(fname, "swb"); else b->outputfile = s_fopen(fname, "swt"); } if (b->outputfile) { s_fsetopt(b->outputfile, 1); b->oldinput = t->input; b->oldoutput = t->output; t->input = io_dummy; t->output = io_file; b->continous = 1; if (b->optplus & o_u) b->sysop = 0; if (*befbuf) mailbef(befbuf, 0); b->sysop = 1; } else putf(ms(m_filenotopen), fname); } } else putf("Syntax: EXPORT <filename> <box-command>\n"); } break; case beacon: { if (*befbuf) { FILE *f = s_fopen(BEACONNAME, "srt"); unsigned int i = 0; char s[LINELEN+1]; if (f) { while (fgets(s, LINELEN, f)) { if (*s) { s[strlen(s) - 1] = 0; putbeacon_tnc(s, befbuf); i++; } } s_fclose(f); } putf(ms(m_beaconframes), i); } else { fork(P_BACK | P_MAIL, 0, sendmailbake, "Beacon"); putf(ms(m_beaconstarted)); } } break; case pwgen: { FILE *f; if (*befbuf && (f = s_fopen(befbuf, "swt")) != 0) { unsigned int i; int upw; upw = ! stricmp(befbuf, "userpw.bcm"); // file fuer setpw for (i = 0; i < 1620; i++) { char c = 0; while (! isalnum(c)) c = random_max('z'); fputc(c, f); //pw-file fuer setpw erzeugen (81 Zeilen mit je 20 Zeichen) if (upw && (i % 20) == 19) fputc(LF, f); } trace(report, "pwgen", "%s created", befbuf); s_fclose(f); } else //ohne Parameter immer userpw.bcm erzeugen if (! *befbuf && (f = s_fopen("userpw.bcm", "swt")) != 0) { unsigned int i; for (i = 0; i < 1620; i++) { char c = 0; while (! isalnum(c)) c = random_max('z'); fputc(c, f); //pw-file fuer setpw erzeugen (81 Zeilen mit je 20 Zeichen) if ((i % 20) == 19) fputc(LF, f); } trace(report, "pwgen", "userpw.bcm created"); s_fclose(f); } } break; case scmdlist: // DH3MB { unsigned int i = 0; while (beftab[i]) putf("(%02d) %s\n", ++i, beftab[i]); } break; #ifdef FEATURE_MDPW case md2sum: { if (! *befbuf) { putf("Syntax: MD2SUM <filename>\n"); break; } if (! file_isreg(befbuf)) putf(ms(m_filenotfound), befbuf); else { MD2 md2; md2.readfile(befbuf, 0L); md2.gethexdigest(b->line); putf("%s %s\n", b->line, befbuf); } } break; case md5sum: { if (! *befbuf) { putf("Syntax: MD5SUM <filename>\n"); break; } if (! file_isreg(befbuf)) putf(ms(m_filenotfound), befbuf); else { MD5 md5; md5.readfile(befbuf, 0L); md5.gethexdigest(b->line); putf("%s %s\n", b->line, befbuf); } } break; #endif #if defined FEATURE_SERIAL || defined _TELEPHONE case ttyinit: { if (eingelogt("getty", 0, 0)) putf(ms(m_ttyactive)); else init_tty(); } break; #endif #ifdef _TELEPHONE // JJ case ttycmd: { if (*befbuf) { if (m.ttydevice > 1) putf_tty("%s\r", befbuf); else putf(ms(m_nomodem)); } else putf("Syntax: TTYCMD <command>\n"); } break; case ttydial: { strupr(befbuf); char *nummer; char call[8]; nummer = nexttoken(befbuf, call, 8); if (*befbuf && mbcallok(call)) { if (m.ttydevice && (get_ufwd(call)[0] || isforwardpartner(call) >= 0)) { putf(ms(m_startphonefwd), call, nummer); sprintf(befbuf, "%s TTY %s", call, nummer); fork(P_BACK | P_MAIL, 0, fwdsend, befbuf); } else putf(ms(m_nottyactive)); } else putf("Syntax: TTYDIAL <call> <number>\n"); } break; case ttyhangup: { tty_hangup(); putf(ms(m_hangupmodem)); } break; case ttystatus: { tty_statustext(); putv(LF); } break; case ttywin_: { fork(P_WIND | P_MAIL, 0, tty_win, befbuf); } break; case ttycounterreset: { tty_counterreset(); putv(LF); } break; #endif #ifdef _FILEFWD case fwdimport: { if (*befbuf) fwd_import(befbuf); } break; case fwdexport: { if (*befbuf) fwd_export(befbuf); } break; #endif case ymbtest: { #ifdef _USERCOMP if (u->comp == 1) { /* char output[256] = { 0 }; char output2[256] = { 0 }; int i, il = 0; */ putf("//COMP 1\n\n"); putflush(); /* il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); // printf("il: %d strlen: %d\n",il,strlen(befbuf)); // printf("befbuf:\n-%s-\nOut:\n-%s-\n",befbuf,output); //putflush(); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); output[0] = '\0'; strcpy(befbuf, "dies ist noch ein laengerer text 2"); il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); output[0] = '\0'; strcpy(befbuf, "dies ist ein noch laengerer text 3"); il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); putf("\n"); il = decomp_sp_stat_huff(output, strlen(output), output2); printf("il: %d strlen: %d\n",il,strlen(output)); printf("Out2:\n-%s-\n",output2); */ /* #include "ahuf.h" // TOP-Huffman class AHUF; AHUF *ahuf; ahuf = new AHUF(); il = ahuf->Komprimieren(true, befbuf, output, strlen(befbuf) ); printf("il: %d strlen: %d\n",il,strlen(befbuf)); printf("befbuf:\n-%s-\nOut:\n-%s-\n",befbuf,output); putflush(); putf("%s",output); putflush(); putf("\n"); */ } #endif } break; } return OK;
void wx::savedata (char *rawdata, wxdata_t *wx) //************************************************************************* //file-format: wx-data: // //filename: directory: 'wx' // filename: 'wx251296.dat' 96..year,12..month,25..day // // 1 2 3 4 5 6 7 //1234567890123456789012345678901234567890123456789012345678901234567890 //007200!!00000271003C0000255F02B503E8----0167044800000000-000851548504Y // !!0000000F00DC05D7254202CA03AB----0164045D00000000 // 12345678901234567890123456789012345678901234567890 // 1 2 3 4 5 //vvvvvxwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww-ttttttttttttc //12345 123456789012 //v...Version of Software,5digits as defined in header, defining file-format // (numversion) //x...Type of line: '0': data // '1': comment // else: undefined //t...time of System (not WX-station) in Unix-Format //w...oneline-wx-data, as received from wx-station //c...simple check sum of string (mod 64)+32 //-...Error in privious versions, inserted "-" for compatibility // //************************************************************************* { #define DASH "-" #define DATA_TYPE "0" char name[20]; strcpy(name, "wx:savedata"); char wxfilen[FNAMELEN+1]; FILE *wxfile; char filestr[200]; int i; long csum; // create wxpath strcpy(wxfilen, time2wxfn(wx->t)); // open file if existing, else create it wxfile = s_fopen(wxfilen, "sat"); if (! wxfile) wxfile = s_fopen(wxfilen, "swt"); if (! wxfile) { trace(serious, name, "create %s", wxfile); return; } trace(report, name, "store to %s", wxfilen); sprintf(filestr, WXNUMVERSION""DATA_TYPE"%s"DASH"%012ld", rawdata, wx->t); csum = 0; for (i=0; filestr[i]; i++) { csum += filestr[i]; } csum = (csum%64)+32; //this check is stupid, but necassary for compatiblity sprintf(filestr+strlen(filestr), "%c\n", (int) csum); fputs(filestr, wxfile); s_fclose(wxfile); }
void extract (unsigned msgnr) //************************************************************************* // // EXTRACT-Utility by DF3VI, extrahiert Binaerteile einer Mail auf // die Mailbox-Festplatte ins Box-temp-Verzeichnis // //************************************************************************* { //is this re-entrant? if not, pse set semaphor FILE *f, *g; char name[FNAMELEN+1], s[BUFLEN], st[FNAMELEN+1], *ptr; unsigned long posi, bytes; int err; unsigned int w, r; char *puffer; strlwr(b->mailpath); if (! (f = s_fopen(b->mailpath, "sr"))) { putf(ms(m_extract_errorread), b->mailpath); return; } fgets(s, BUFLEN - 1, f); mbsend_parse(s, 0); do { waitfor(e_ticsfull); fgets(s, BUFLEN - 1, f); } while (! feof(f) && ! (strstr(s, " go_") == s) && ! (strstr(s, "#BIN#") == s)); if (feof(f)) // keine Markierung gefunden { putf(ms(m_extract_nostartline), b->boardname, msgnr); s_fclose(f); return; } do { if (strstr(s, "#BIN#") == s) { s_fclose(f); subst1(s, LF, 0); if (! sscanf(s, "#BIN#%lu", &bytes)) // Laenge lesen { putf(ms(m_extract_invalidheader), b->boardname, msgnr); return; } unsigned long bintime; sscanf(strchr(s, '$'), "$%lX#", &bintime); ptr = s + strlen(s); while (*ptr != '#' && ptr > s) ptr--; // Dateinamen suchen if (*(ptr - 1) != '#') ptr++; // # im Dateinamen ? if (! *ptr || *ptr == '$' || *ptr == '|' ) { putf(ms(m_extract_filenamemissing)); err = 0; do // Ersatzname RUBRIK.lfn erzeugen { waitfor(e_ticsfull); sprintf(s, TEMPPATH "/%s.%03i", b->boardname, ++err); strlwr(s); } while (! access(s, 0) && err <= 999); if (err > 999) { putf(ms(m_extract_filecantcreate)); return; } else putf(ms(m_extract_filecreate), s); } else { strcpy(name, ptr); ptr = name + strlen(name); while (ptr >= name && *ptr != ':' && *ptr != '\\' && *ptr != '/') ptr--; // LW/Pfad abtrennnen // putf("Dateiname: %s\n", ptr+1); sprintf(s, TEMPPATH "/%s", ptr + 1); strlwr(s); } if (! (g = s_fopen(s, "swb"))) { // Ziel-Datei oeffnen putf(ms(m_extract_errorwritebin), errno, s, strerror(errno)); // perror(""); return; } if (! (puffer = (char *) t_malloc(2048, "extr"))) { // 2 kb Puffer zum Daten-Kopieren putf(ms(m_nomem)); s_fclose(g); return; } f = s_fopen(b->mailpath, "srb"); // BIN-Datei oeffnen fseek(f, b->binstart + BINCMDLEN, SEEK_SET); // Position auf Anfang posi = r = 0; // Byte-Zaehler gesamt/gelesen do { r = fread(puffer, 1, 2048, f); posi += r; fwrite(puffer, 1, r, g); waitfor(e_ticsfull); } while (r == 2048); t_free(puffer); s_fclose(g); s_fclose(f); setfiletime(s, bintime); putf(ms(m_extract_extractbin), s, posi, bytes, b->boardname, msgnr); return; // BIN ist immer Fileende } // Ansonsten DG1BBQ-FFR-Markierung if ((strstr(s, " go_text. ") == s) || (strstr(s, " go_info. ") == s)) { sscanf(s + 10, "%s", st); // Text-Datei-Namen lesen sprintf(name, TEMPPATH "/%s", st); strlwr(name); if (! access(name, 0)) // Wenn vorhanden, Extension hochzaehlen { err = 1; switch (name + strlen(name) - strchr(name, '.')) { case 1: // "name." -> "name.__" case 2: strcat(name, "__" ); break; // "name.x" -> "name.x__" case 3: strcat(name, "_"); // "name.xx" -> "name.xx_" case 4: break; // "name.xxx" -> "name.xxx" default: strcat(name, ".__"); // "name" -> "name.__" } *(name + strlen(name) - 2) = 0; do // ZWEI-stellige laufenden Nummer { waitfor(e_ticsfull); sprintf(s, "%s%02x", name, err++); } while (! access(s, 0) && err < 255); if (err >= 255) { putf(ms(m_extract_filecantcreate)); *name = 0; } else { strcpy(st, s); strlwr(st); } } *s = 0; // Keine Startmarkierung schreiben } else if (strstr(s, " go_7+. ") == s) // 7PLUS-Datei-Kopf auswerten { // lfn, Bereich, File-Name if (sscanf(s + 8, "%u of %u %s", &w, &r, name) != 3) { putf(ms(m_extract_invalidstartline), b->boardname, msgnr); *name = 0; } else { subst1(name, '.', 0); // Extension abtrennen if (r == 1) sprintf(st, TEMPPATH "/%s.7pl", name); // Einteilig: Endung .7PL else sprintf(st, TEMPPATH "/%s.p%02x", name, w); // Mehrteilig: End. .PXX } } else { putf(ms(m_extract_invalidstartline), b->boardname, msgnr); *st = 0; } if (*st) { strlwr(st); if (! (g = s_fopen(st, "sw"))) // Ziel-Datei schreiben { putf(ms(m_extract_errorwrite), st); return; } do { fputs(s, g); *s = 0; waitfor(e_ticsfull); fgets(s, BUFLEN - 1, f); } // Bis File-Ende oder Stop-Markierung while (! feof(f) && ! (strstr(s, " stop_") == s)); if (strstr(s, " stop_7+")) fputs(s, g); //nur bei 7+ Endemarkierung schreiben s_fclose(g); putf(ms(m_extract_extract7p), st, b->boardname, msgnr); } do { waitfor(e_ticsfull); *s = 0; fgets(s, BUFLEN - 1, f); // Naechste Start-Markierung suchen } while (! feof(f) && ! (strstr(s, " go_") == s) && ! (strstr(s, "#BIN#") == s)); } while (! feof(f)); // solange 7+ folgt s_fclose(f); // oder File-Ende }
void initafwdlist () //************************************************************************* // // read afwd.bcm into memory // //************************************************************************* { FILE *f; char s[LINELEN+1]; char word[MAXPARSE]; char dstb[HADRESSLEN+1]; int boxindex = 0; int line = 0; int i; int destlen = 0; afwdpara_t *ff; char name[20]; strcpy(name, "initafwdlist"); if (! m.autofwdtime) return; if (afp) t_free(afp); afp = (afwdpara_t *) t_malloc(MAXFWD * sizeof(afwdpara_t), "*afp"); if (aboxdest) t_free(aboxdest); aboxdest = (char *) t_malloc(MAXDESTLEN * sizeof(char), "*ads"); if (! afp || ! aboxdest) { trace(fatal, name, "out of memory"); return; } memset(afp, 0, MAXFWD * sizeof(afwdpara_t)); ff = afp; if ((f = s_fopen(AFWDLISTNAME, "srt")) != NULL) { while (fgets(s, LINELEN, f)) { line++; subst1(s, ';', 0); if (strlen(s) > 3) { i = (*s == ' '); strupr(s); parseline(s, word); if (i) { if (! boxindex) goto error; // erster Eintrag: Boxcall fehlt else { char *dest = afp[boxindex - 1].dest; i = 0; while (word[i]) { strncpy(dstb, s + word[i++], HADRESSLEN); dstb[HADRESSLEN] = 0; //strip_hadr(dstb); if (*dstb && (destlen + strlen(dstb) + 1) < MAXDESTLEN) { strcat(dest, dstb); strcat(dest, " "); destlen += (strlen(dstb) + 1); } else { trace(serious, name, ms(m_fwd_toomanydest)); if (*b->logincall) putf(ms(m_fwd_toomanydest)); break; } } } } else { if (! boxindex) ff->dest = aboxdest; else { ff->dest = afp[boxindex - 1].dest + strlen(afp[boxindex - 1].dest) + 1; destlen += 1; } *ff->dest = 0; *ff->call = 0; if (strlen(s + *word) <= 6) strcpy(ff->call, s + *word); else goto error; // Boxcall zu lang if (++boxindex == MAXFWD) { trace(serious, name, ms(m_fwd_toomanycalls)); if (*b->logincall) putf(ms(m_fwd_toomanycalls)); break; } ff = &afp[boxindex]; } } } *ff->call = 0; s_fclose(f); #ifdef DEBUG_AFWD trace(report, name, "%d partners", boxindex); #endif if (*b->logincall) putf("%s: %d partners.\n", name, boxindex); afwdpartners = boxindex; if (! boxindex) { t_free(afp); t_free(aboxdest); afp = NULL; aboxdest = NULL; } return; } else { trace(serious, name, AFWDLISTNAME" not found"); if (*b->logincall) putf("%s: "AFWDLISTNAME" not found.\n", name); return; } error: //that should never happen #ifdef __DOS16__ sound(1000); wdelay(106); nosound(); #endif trace(serious, name, "line %d error", line); if (*b->logincall) putf("%s: line %d error.\n", name, line); s_fclose(f); }
void afwdlist (char *) //************************************************************************* // // afwd.bcm is generated here .. // //************************************************************************* { char name[20]; strcpy(name, "afwdlist"); if (! m.hadrstore || ! m.autofwdtime) return; //afwd disabled // Alle boxen durchsuchen // trace(report, "afwdlist", "scanning HADR"); unsigned int found = 0, i = 0; if (! (found = scan_hadr())) return; // Sort file by reversed short addr char linetmp[LINELEN+1]; char *xx; afwd_data *adrs = (afwd_data*) t_malloc(sizeof(afwd_data) * found, "hadr"); if (! adrs) { trace(serious, name, "out of memory"); putf("not enough memory"); return; } #ifdef DEBUG_AFWD trace(report, name, "reading entries in memory"); #endif FILE *f = s_fopen(AFWDTMP, "srt"); if (f) { while (fgets(linetmp, LINELEN, f)) { //fwdcall, shortheader xx = strchr(linetmp, ' '); *xx++ = 0; strcpy(adrs[i].partner, linetmp); strcpy(adrs[i].shortaddr, reverse_addr(xx)); i++; } s_fclose(f); } else { trace(serious, name, ms(m_filenotopen), AFWDTMP); putf(ms(m_filenotopen), AFWDTMP); t_free(adrs); return; } #ifdef DEBUG_AFWD trace(report, name, "read %u", i); trace(report, name, "sorting .."); #endif qsort(adrs, i, sizeof(afwd_data), data_cmp); found = process_afwd_data(adrs, found); #ifdef DEBUG_AFWD trace(report, name, "writing "AFWDLISTNAME); #endif f = s_fopen(AFWDLISTNAME, "lwt"); if (! f) { trace(serious, name, ms(m_filenotopen), AFWDLISTNAME); putf(ms(m_filenotopen), AFWDLISTNAME); t_free(adrs); return; } fprintf(f, "; OpenBCM AutoFwd File !!! DO NOT EDIT !!!\n"); fprintf(f, "; This file is generated automatically. (use %s for manual editing!)\n", FWDLISTNAME); write_afwd(f, adrs, found); s_fclose(f); t_free(adrs); initafwdlist(); }
static int scan_hadr () //************************************************************************* // // process HADR database, find entries newer than autofwdtime, // write afwd1.tmp // //************************************************************************* { hadr_t *ha; unsigned int count = 0, found = 0, i = 0; char boxcall[CALLEN+1]; char *header; char shortheader[HADRESSLEN+1]; char name[20]; int num; strcpy(name, "afwdlist"); FILE *f = s_fopen(HADRNAME, "lrb"); if (! f) { trace(serious, name, ms(m_filenotopen), HADRNAME); putf(ms(m_filenotopen), HADRNAME); return 0; } FILE *g = s_fopen(AFWDTMP, "lwt"); if (! g) { trace(serious, name, ms(m_filenotopen), AFWDTMP); putf(ms(m_filenotopen), AFWDTMP); s_fclose(f); return 0; } ha = (hadr_t*) t_malloc(sizeof (hadr_t), "hadr"); setvbuf(f, NULL, _IOFBF, 4096); // buffer for increasing performance fseek(f, sizeof (hadr_t), SEEK_SET); while (fread(ha, sizeof(hadr_t), 1, f)) { if (! *ha->adr) continue; if (! strcmp(ha->adr, m.boxadress)) continue; count++; if (! check_adr(ha->adr)) continue; if ((num = which_partner(NULL, ha)) == NOTFOUND) continue; // Forwardweg suchen //no hadr, only boxcall (corrupt R: lines etc.) //(should not pass through check_adr() anyway) if (! (header = strchr(ha->adr, '.'))) continue; i = header - ha->adr; strcpy(shortheader, ha->adr); strip_hadr(shortheader); if (i > CALLEN) i = CALLEN; strncpy(boxcall, ha->adr, i); boxcall[i] = 0; if (mbcallok(boxcall)) { found++; // putf("%i) %s%s -> %s to %s\n", count, boxcall, header, shortheader, fwdcall); // Routerfile schreiben fprintf(g, "%s %s \n", ha->adjacent[num], shortheader); } waitfor(e_ticsfull); if (testabbruch()) break; } t_free(ha); s_fclose(f); s_fclose(g); #ifdef DEBUG_AFWD trace(report, name, "%u searched, %u found", count, found); #endif putf("%u searched, %u found\n", count, found); return found; }
void cfgflex (char * befbuf) //************************************************************************* // // cfgflex // //************************************************************************* { int a, i; int promptz = 0; // Zaehler der Nodeprompts char fn[20]; // Dateiname des Configfiles char fo[20]; // Dateiname des Antwortfiles char ziel[30]; // Nodecall char line[255]; // Noderueckgabe strcpy(fn, "cfgflex.bcm"); strcpy(fo, "cfgflex.out"); strncpy(ziel, befbuf, 29); ziel[29] = 0; trace(report, "cfgflex", "connect %s", ziel); timeout(1); lastcmd("Connect"); if (makeconnect(m.mycall[1], ziel)) { setsession(); *b->logincall = 0; if (filetime(fn)) { trace(report, "cfgflex", "sending %s", fn); FILE *f = s_fopen(fn, "lrt"); lastcmd("TX cfg_file"); while ((a = fgetc(f)) != EOF) { getclear_tnc(); timeout(1); waitfor(e_ticsfull); putv(a); if (a == LF) promptz++; // zaehlt prompts vorwaerts } putv(LF); putv(LF); s_fclose(f); trace(report, "cfgflex", "receive %s", fo); // speichert Rueckgaben FILE *g = s_fopen(fo, "lwt"); lastcmd("RX cfg_result"); if (g) // JJ { while (promptz > 0) { getline(line, BUFLEN - 1, 1); if (! strncmp(line, "=>", 2)) promptz--; // zaehlt prompts rueckwaerts if (! strncmp(line, "***", 3)) promptz = 0; // link failure fprintf(g, "%s", line); fputc(LF, g); } } s_fclose(g); } lastcmd("Delay"); for (i = 0; i < 100; i++) { wdelay(226); getclear_tnc(); } mblogout(0); mbdisconnect(1); // wait for data to be sent } }