int MakeMailFile(struct GroupFolder * folder, STRPTR outbuf, LONG outlen, ULONG MsgNum, BOOL makeDir ) { int rc = ERR_OVERFLOW; DBG_ASSERT(folder != NULL); *outbuf = 0; if(AddPart( outbuf, folder->folder, outlen )) { if(AddPart( outbuf, strf("%08ld", MsgNum), outlen)) { if(makeDir) { /* make sure the folder pointing to this file exists */ MakeDir( outbuf ); } rc = ERR_NOERROR; hexdump( outbuf, 0, strlen(outbuf)+4); } } DBG_STRING(outbuf); return(rc); }
int appInitEx(const char * const fnam) { DBG_ENTER("appInitEx", Suppl_appName); if(app_file) { DBG_STRING("SUPPL subsystem appName already initialized"); DBG_RETURN_I(ESUPPL_OK) } DBG_RETURN_BI( appInit(fnam)) }
int mcb_allParents(word mcb, MCB_WALKFUNC fct, void *arg) { word mcb1; DBG_ENTER("mcb_allParents", Suppl_mcb) DBG_ARGUMENTS( ("mcb=%u", mcb) ) assert(fct); if(mcb) { if(!isPSP(mcb)) { DBG_STRING("Invalid MCB") DBG_RETURN_I( -1) } } else mcb = _psp;
VOID IPC_Dispatch( struct MsgPort * mPort ) { struct IPCMsg * ipcmsg; ENTER(); DBG_POINTER(mPort); // get the next waiting message while((ipcmsg = (struct IPCMsg *)GetMsg( mPort ))) { DBG_VALUE(ipcmsg->ipc_ID); if(ipcmsg->ipc_ID == IPC_MAGIC) { switch( ipcmsg->ipc_action ) { case IPCA_INFOMSG: iListInsert((STRPTR) ipcmsg->ipc_data ); ipcmsg->ipc_result = IPCR_OK; break; case IPCA_NZBFILE: { STRPTR nzbfile = (STRPTR) ipcmsg->ipc_data; DBG_STRING(nzbfile); if(Analyzer( nzbfile )) ipcmsg->ipc_result = IPCR_OK; else ipcmsg->ipc_result = IPCR_FAIL; } break; case IPCA_DLSTATUS: dlStatusReportHandler((struct dlStatus *)ipcmsg->ipc_data); ipcmsg->ipc_result = IPCR_OK; break; default: break; } } ReplyMsg((APTR) ipcmsg ); } LEAVE(); }
STRPTR AslFile( STRPTR TitleText, STRPTR InitialPattern ) { struct Library * AslBase; STRPTR name = NULL; ENTER(); if((AslBase = OpenLibrary("asl.library", 0))) { struct FileRequester *freq; if((freq = AllocAslRequestTags(ASL_FileRequest, TAG_DONE))) { if(AslRequestTags(freq, ASLFR_TitleText, (ULONG)TitleText, ASLFR_InitialDrawer, (ULONG)GetString(AslFilePath,"PROGDIR:"), ASLFR_RejectIcons, TRUE, InitialPattern != NULL ? ASLFR_DoPatterns:TAG_IGNORE, TRUE, InitialPattern != NULL ? ASLFR_InitialPattern:TAG_IGNORE, (ULONG)InitialPattern, TAG_DONE)) { ULONG namelen; namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 32; if((name = AllocVec(namelen + 1, MEMF_PUBLIC | MEMF_CLEAR))) { AddPart(name, freq->fr_Drawer, namelen); AddPart(name, freq->fr_File, namelen); set( AslFilePath, MUIA_String_Contents,(ULONG)freq->fr_Drawer); } } FreeAslRequest(freq); } else ShowError("Cannot alloc AslRequest!"); CloseLibrary( AslBase ); } else ShowError("Cannot open %s","asl.library"); DBG_STRING(name); return name; }
int SaveMessage( struct ClassData * data, STRPTR Message, ULONG msgnum ) { struct YGRDBIndex * idx; int rc = ERR_NOMEM, x=0; UBYTE *msg=Message, file[1024]; BPTR fd; DBG("Saving message...\n"); DBG_ASSERT(Message && *Message); if(!(Message && *Message)) return ERR_INTERNAL; ObtainSemaphore(data->sem); if(!(idx = malloc(sizeof(struct YGRDBIndex)))) goto done; // bzero( idx, sizeof(struct YGRDBIndex)); DBG_ASSERT((strlen(Message) > 5) && !strncmp( Message, "From ", 5 )); #define cpln( src, dst ) \ memcpy(dst,src, MIN(FindPos(src,"\n"),(int)sizeof(dst)-1)) while(*msg && (x < 3)) { if(!Strnicmp( msg, "From:", 5)) {x++; cpln(&msg[6], idx->from);} else if(!Strnicmp( msg, "Subject:", 8)) {x++; cpln(&msg[9], idx->subj);} else if(!Strnicmp( msg, "Date:", 5)) {x++; cpln(&msg[6], idx->date);} msg++; } idx->msgnum = msgnum; idx->udata = data->subtask.folder; DBG_VALUE(msgnum); DBG_STRING(idx->from); DBG_STRING(idx->subj); DBG_STRING(idx->date); idx->next = data->subtask.folder->idx; data->subtask.folder->idx = idx; data->subtask.folder->Total++; data->subtask.folder->New++; if(SameGroupFolder( data, FALSE )) { PushMethod( data->appobj, data->rightlist, 3, MUIM_NList_InsertSingle, idx, MUIV_NList_Insert_Sorted); } rc = MakeMailFile( data->subtask.folder, file, sizeof(file)-1, msgnum, (data->subtask.folder->New == 1)); if(rc != ERR_NOERROR) goto done; if((fd = Open( file, MODE_NEWFILE))) { Write( fd, Message, strlen(Message)); #ifdef DEBUG Flush( fd ); #endif Close( fd ); } DBG_STRING(file); if((rc = IoErr()) == 0) rc = ERR_NOERROR; done: ReleaseSemaphore(data->sem); return(rc); }
int SaveIndexToDisk( struct ClassData * data, struct GroupFolder ** grp ) { BPTR fd; ULONG idxid = IDX_ID; struct YGRDBIndex * idx; unsigned char len; /* THIS FUNCTION CALLER *MUST* LOCK THE SEMAPHORE !(?).. */ InfoText("Saving index for group \"%s\" to disk, please wait...", (*grp)->YahooGroup ); if(!(fd = Open((*grp)->index, MODE_NEWFILE ))) goto done; WriteCheck( &idxid, sizeof(ULONG)); DBG_VALUE((*grp)->New); for( idx = (*grp)->idx ; idx ; idx = idx->next ) { len = 160; // chunk separator WriteCheck( &len, sizeof(unsigned char)); WriteCheck( &(idx->msgnum), sizeof(ULONG)); DBG_STRING(idx->from); len = (unsigned char) strlen(idx->from); WriteCheck( &len, sizeof(unsigned char)); WriteCheck( idx->from, len ); DBG_STRING(idx->subj); len = (unsigned char) strlen(idx->subj); WriteCheck( &len, sizeof(unsigned char)); WriteCheck( idx->subj, len ); DBG_STRING(idx->date); len = (unsigned char) strlen(idx->date); WriteCheck( &len, sizeof(unsigned char)); WriteCheck( idx->date, len ); (*grp)->New--; } len = 159; // EOF bit mark WriteCheck( &len, sizeof(unsigned char)); #ifdef DEBUG if(((long)((*grp)->New)) < 0) { DBG(" \a +++++++++++++++ (*grp)->New < 0 !!!!! (%ld)\n", (long) (*grp)->New); (*grp)->New = 0; } #endif Close( fd ); done: if((data->LastError = IoErr()) == 0) data->LastError = ERR_NOERROR; return data->LastError; }
int LoadIndex(struct ClassData * data) { STRPTR fdata = NULL, f; ULONG flen; /* Carga el index (si existe) y lo copia en la structura provada */ DBG("Cargando el fichero indice para el grupo %s\n", data->ActiveGroup->YahooGroup ); if(data->ActiveGroup->Total != 0) { DBG("data->ActiveGroup->Total = %ld\n", data->ActiveGroup->Total); return data->LastError = ERR_INTERNAL; } data->LastError = FileToMem(data,data->ActiveGroup->index,&fdata,&flen); if(data->LastError != ERR_NOERROR) { if(data->LastError == ERROR_OBJECT_NOT_FOUND) { /* el fichero no existe, asi pues no lo consideres * como un error! */ data->LastError = ERR_NOERROR; } goto done; } if(*((ULONG *) fdata ) != IDX_ID) { DBG("\a El ID del index no coincide !?\n"); data->LastError = ERR_INDEX; goto done; } f = &fdata[sizeof(ULONG)]; do { unsigned int slen; struct YGRDBIndex * idx; /** * El formato del index es el siguiente (cada chunk): * * [ ULONG | UBYTE | STRPTR | UBYTE | STRPTR | UBYTE | STRPTR ] * msgnum from subject date * * Cada UBYTE contiene la longitud de la cadena STRPTR, y cada * chunk esta separado por el bit 160, siendo 159 el bit EOF */ if(*((UBYTE *) f ) != 160 ) { if(*((UBYTE *) f ) == 159 ) break; data->LastError = ERR_INDEX; goto done; } f += sizeof(UBYTE); if(!(idx = malloc(sizeof(struct YGRDBIndex)))) goto done; idx->msgnum = *((ULONG *) f ); f += sizeof(ULONG); DBG_VALUE(idx->msgnum); slen = (unsigned int) *((UBYTE *) f ); f += sizeof(UBYTE); memcpy( idx->from, f, MIN(slen,sizeof(idx->from)-1)); f += slen; DBG_STRING(idx->from); slen = (unsigned int) *((UBYTE *) f ); f += sizeof(UBYTE); memcpy( idx->subj, f, MIN(slen,sizeof(idx->subj)-1)); f += slen; DBG_STRING(idx->subj); slen = (unsigned int) *((UBYTE *) f ); f += sizeof(UBYTE); memcpy( idx->date, f, MIN(slen,sizeof(idx->date)-1)); f += slen; DBG_STRING(idx->date); idx->next = data->ActiveGroup->idx; data->ActiveGroup->idx = idx; data->ActiveGroup->Total++; } while(1); DBG_VALUE(data->ActiveGroup->Total); data->LastError = ERR_NOERROR; done: free( fdata ); return data->LastError; }
int SetActiveGroup(struct ClassData * data, STRPTR YahooGroup ) { UBYTE buf[2048]; /* crea los nombres de fichero done luego se guardaran los mensages * y el index ( group.idx y group.db ) */ DBG_STRING(data->MailsFolder); DBG_STRING(YahooGroup); // this must be called with the semaphore locked ! if(data->subtask.task == NULL) { /* Si la subtask esta activa debe tener el control de * data->ActiveGroup, si no tiene que ser liberado */ ExpungeIndex(data, &(data->ActiveGroup)); } if(!(data->ActiveGroup = malloc(sizeof(struct GroupFolder)))) goto done; if(!(data->ActiveGroup->YahooGroup = strdup( YahooGroup ))) goto done; *buf = 0; data->LastError = ERR_OVERFLOW; if(AddPart( buf, data->MailsFolder, sizeof(buf)-1)) { if(AddPart( buf, data->ActiveGroup->YahooGroup, sizeof(buf)-1)) { STRPTR gfolder = NULL, db = NULL, idx = NULL; long buflen = strlen(buf) + MAX(strlen(IDX_EXT),strlen(DB_EXT)) + 2; data->LastError = ERR_NOMEM; if((gfolder = strdup( buf ))) { if((db = malloc( buflen ))) { if((idx = malloc( buflen ))) { free( data->ActiveGroup->index ); free( data->ActiveGroup->unixf ); free( data->ActiveGroup->folder); data->ActiveGroup->index = idx; data->ActiveGroup->unixf = db; data->ActiveGroup->folder = gfolder; SNPrintf(data->ActiveGroup->unixf, buflen-1, "%s%s", gfolder, DB_EXT ); SNPrintf(data->ActiveGroup->index, buflen-1, "%s%s", gfolder, IDX_EXT ); data->LastError = ERR_NOERROR; ClearReaderMail( data ); DBG_STRING(data->ActiveGroup->index); DBG_STRING(data->ActiveGroup->unixf); DBG_STRING(data->ActiveGroup->folder); } } } if( data->LastError != ERR_NOERROR ) { free( gfolder ); free( db ); free( idx ); } } } done: if( data->LastError != ERR_NOERROR ) { if( data->ActiveGroup ) { free( data->ActiveGroup->YahooGroup ); free( data->ActiveGroup ); data->ActiveGroup = NULL; } } return(data->LastError); }
STATIC VOID ProgressWindow_SubTask( STRPTR message ) { struct Library * MUIMasterBase; ENTER(); DBG_STRING(message); if((MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN))) { Object * app, * window; app = ApplicationObject, MUIA_Application_Title , "AmiNZB.WNDP", MUIA_Application_Base , "AmiNZB.WNDP", MUIA_Application_Version , ProgramVersionTag(), MUIA_Application_Description, ProgramDescription(), SubWindow, window = WindowObject, MUIA_Window_Borderless , TRUE, MUIA_Window_CloseGadget, FALSE, MUIA_Window_SizeGadget , FALSE, MUIA_Window_DepthGadget, FALSE, MUIA_Window_DragBar , FALSE, MUIA_Window_ScreenTitle, ProgramDescription(), WindowContents, VGroup, GroupFrameT(NULL), InnerSpacing(2,4), Child, TextObject, MUIA_Text_Contents, (ULONG)message, MUIA_Text_PreParse, "\033b\033c", MUIA_Font, MUIV_Font_Big, End, Child, BusyObject, End, End, End, End; if( app ) { DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE, app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit); set(window,MUIA_Window_Open,TRUE); if(xget( window, MUIA_Window_Open)) { ULONG sigs = 0; BOOL running = TRUE; struct Window * iWindow; if((iWindow = (struct Window *) xget( window, MUIA_Window_Window))) { ((struct Process *)FindTask(0))->pr_WindowPtr = iWindow; //SetWindowTitles( iWindow, NULL, ProgramDescription()); } do { switch(DoMethod(app,MUIM_Application_NewInput,&sigs)) { case MUIV_Application_ReturnID_Quit: //running = FALSE; DisplayBeep(NULL); break; default: break; } if(running && sigs) { sigs = Wait(sigs | SIGBREAKF_CTRL_C); if (sigs & SIGBREAKF_CTRL_C) break; } } while(running); set(window,MUIA_Window_Open,FALSE); } MUI_DisposeObject(app); } CloseLibrary(MUIMasterBase); } LEAVE(); }
BOOL SafeToExit( VOID ) { STATIC CONST UBYTE __reallyquitmsg[] = "Do you really want to quit?"; BOOL rc = TRUE, imle; ZoneAlarmTask * zat; int len=0; UBYTE buf[4096]; ENTER(); Forbid(); if(!uSemaLockAttempt ( )) { struct Task * t = uSemaOwner ( ) ; rc = FALSE; ADD("Cannot try to exit right now, Process $%lx (%s) is actively using me!", t, t->tc_Node.ln_Name ); Permit(); RA_Requester(tell_gadgets,buf); } else if(IsMinListEmpty(G->ZoneAlarmTasks)) { /** * There is no tasks using me, pop a single confirmation */ Permit(); if(RA_Requester(ask_gadgets,(STRPTR)__reallyquitmsg)!=1) { rc = FALSE; } } else { /** * There are some programs using me, ask for confirmation * telling the user which tasks are running */ ADD("The following applications are\nstill using %s:\n\n",ProgramName()); ITERATE_LIST( G->ZoneAlarmTasks, ZoneAlarmTask *, zat ) { ADD(" %s ($%lx)\n", zat->task_name, zat->task ); } ADD("\n\033b%s", __reallyquitmsg); DBG_STRING(buf); Permit(); if(RA_Requester("_Quit|_Cancel", buf) == 1) { /** * user really want to quit, break the tasks using me.. */ Forbid(); ITERATE_LIST( G->ZoneAlarmTasks, ZoneAlarmTask *, zat ) { DBG(".........Breaking $%lx (%s)\n", zat->task, zat->task_name); Signal( zat->task, SIGBREAKF_CTRL_C ); } Permit(); /** * do a little delay to let the tasks exit */ Delay( 4 * TICKS_PER_SECOND ); Forbid();//ObtainSemaphore(G->Semaphore); imle = IsMinListEmpty(G->ZoneAlarmTasks) ? TRUE:FALSE; Permit();//ReleaseSemaphore(G->Semaphore); if(imle==FALSE) { /** * uh-oh... some task refused to quit, let the * user know which */ Forbid(); len = 0; ADD("\033b%s is unable to exit, the following\napplications refuse to quit:\033n\n\n", ProgramName()); ITERATE_LIST( G->ZoneAlarmTasks, ZoneAlarmTask *, zat ) { ADD(" %s ($%lx)\n", zat->task_name, zat->task ); } //ADD("\n\033b...try again right now"); ADD("\n\033b...do you want to quit anyway? your\nsystem MAY becomes unstable though\n"); DBG_STRING(buf); Permit(); if(RA_Requester(ask_gadgets,buf)==0) rc = FALSE; } }
BOOL TaskRegSave( VOID ) { STRPTR data; ULONG data_len = 0; int items = 0; BOOL rc = FALSE; TaskReg *entry; struct DupsLog *d; ENTER(); // this is executed uSemaLock()'ed or Forbid()'ed DBG_ASSERT(G && G->MagicID == GLOBAL_MAGIC); if(!G || G->MagicID != GLOBAL_MAGIC) { SetIoErr(ERROR_OBJECT_WRONG_TYPE); return FALSE; } if(IsMinListEmpty(G->TaskRegList)) { DBG("The list is empty!\n"); return TRUE; } NewList((struct List *) &tr_dups ); ITERATE_LIST( G->TaskRegList, TaskReg *, entry) { if(IsDup(entry->TaskName,entry->AlertFlags,entry->ServerPort)) continue; if((d = Malloc(sizeof(struct DupsLog)))) { d->TaskName = entry->TaskName; d->AlertFlags = entry->AlertFlags; d->ServerPort = entry->ServerPort; AddTail((struct List *)&tr_dups, (struct Node *)d); } items++; data_len += entry->TaskNameLength; #if DATABASE_RESERVED data_len += DATABASE_RESERVED; #endif } data_len += (sizeof(TaskReg) * items) + (sizeof(ULONG)*3); DBG_VALUE(data_len); if((data = Malloc(data_len))) { STRPTR ptr=data; BPTR fd; PutV( ptr, ULONG, DATABASE_ID); PutV( ptr, ULONG, DATABASE_VERSION); ITERATE_LIST( G->TaskRegList, TaskReg *, entry) { DBG_STRING(entry->TaskName); if(IsDup(entry->TaskName,entry->AlertFlags,entry->ServerPort)) continue; PutV( ptr, UWORD, entry->TaskNameLength ); PutX( ptr, entry->TaskNameLength, entry->TaskName ); PutV( ptr, BYTE, entry->allow ); PutV( ptr, BYTE, entry->remember ); PutV( ptr, ULONG, entry->RegTime.ds_Days ); PutV( ptr, ULONG, entry->RegTime.ds_Minute ); PutV( ptr, ULONG, entry->RegTime.ds_Tick ); PutV( ptr, ULONG, entry->ModTime.ds_Days ); PutV( ptr, ULONG, entry->ModTime.ds_Minute ); PutV( ptr, ULONG, entry->ModTime.ds_Tick ); PutV( ptr, ULONG, entry->accesses ); PutV( ptr, ULONG, entry->FileCRC ); PutV( ptr, UWORD, entry->CRCMods ); PutV( ptr, UWORD, entry->AlertFlags ); PutV( ptr, UWORD, entry->ServerPort ); #if DATABASE_RESERVED ptr += DATABASE_RESERVED; #endif } PutV( ptr, ULONG, DATABASE_EOFID ); if((fd = Open( DATABASE_FILE, MODE_NEWFILE ))) { LONG len = (LONG)(ptr-data); DBG_VALUE(len); transcode( data, len ); rc = (Write( fd, data, len ) == len); Close(fd); } Free(data); }