static void ami_font_cache_cleanup(struct MinList *ami_font_cache_list) { struct nsObject *node; struct nsObject *nnode; struct ami_font_cache_node *fnode; struct TimeVal curtime; if(IsMinListEmpty(ami_font_cache_list)) return; node = (struct nsObject *)GetHead((struct List *)ami_font_cache_list); do { nnode=(struct nsObject *)GetSucc((struct Node *)node); fnode = node->objstruct; GetSysTime(&curtime); SubTime(&curtime, &fnode->lastused); if(curtime.Seconds > 300) { LOG("Freeing %s not used for %ld seconds", node->dtz_Node.ln_Name, curtime.Seconds); DelObject(node); } } while((node=nnode)); /* reschedule to run in five minutes */ ami_schedule(300000, (void *)ami_font_cache_cleanup, ami_font_cache_list); }
VOID RemoveDosPatches( VOID ) { ENTER(); DBG_ASSERT(G->MagicID == GLOBAL_MAGIC); if(G->MagicID == GLOBAL_MAGIC) { ULONG patches[] = { (ULONG) &(G->CreateNewProc_pch), (ULONG) &(G->CreateProc_pch), 0L }; sf_remove((ULONG **)patches); // could happens anyway.. DBG_ASSERT(IsMinListEmpty(G->CreateNewProcPatches)==TRUE); } LEAVE(); }
void *ami_find_gwin_by_id(struct Window *win, int type) { struct nsObject *node, *nnode; struct gui_window_2 *gwin; if(!IsMinListEmpty(window_list)) { node = (struct nsObject *)GetHead((struct List *)window_list); do { nnode=(struct nsObject *)GetSucc((struct Node *)node); if(node->Type == type) { gwin = node->objstruct; if(win == gwin->win) return gwin; } } while(node = nnode); } return NULL; }
struct browser_window *ami_find_tab(int window, int tab) { int windows = 0, tabs = 0; struct nsObject *node, *nnode; struct gui_window_2 *gwin; if(!IsMinListEmpty(window_list)) { node = (struct nsObject *)GetHead((struct List *)window_list); do { nnode=(struct nsObject *)GetSucc((struct Node *)node); if(node->Type == AMINS_WINDOW) { windows++; if(windows == window) return ami_find_tab_gwin(node->objstruct, tab); } } while(node = nnode); } return NULL; }
void ami_fetch_file_poll(const char *scheme_ignored) { struct nsObject *node; struct nsObject *nnode; struct ami_file_fetch_info *fetch; fetch_error_code errorcode; if(IsMinListEmpty(ami_file_fetcher_list)) return; node = (struct nsObject *)GetHead((struct List *)ami_file_fetcher_list); do { errorcode = FETCH_ERROR_NO_ERROR; nnode=(struct nsObject *)GetSucc((struct Node *)node); fetch = (struct ami_file_fetch_info *)node->objstruct; if(fetch->locked) continue; if(!fetch->aborted) { if(fetch->fh) { ULONG len; len = FRead(fetch->fh,ami_file_fetcher_buffer,1,1024); if (len == (ULONG)-1) errorcode = FETCH_ERROR_MISC; else if (len > 0) ami_fetch_file_send_callback( FETCH_DATA, fetch, ami_file_fetcher_buffer, len, errorcode); if((len<1024) && (!fetch->aborted)) { ami_fetch_file_send_callback(FETCH_FINISHED, fetch, NULL, 0, errorcode); fetch->aborted = true; } } else { fetch->fh = FOpen(fetch->path,MODE_OLDFILE,0); if(fetch->fh) { char header[64]; struct ExamineData *fib; if(fib = ExamineObjectTags(EX_FileHandleInput,fetch->fh,TAG_DONE)) { fetch->len = fib->FileSize; FreeDosObject(DOS_EXAMINEDATA,fib); } fetch_set_http_code(fetch->fetch_handle,200); fetch->mimetype = fetch_mimetype(fetch->path); LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len)); snprintf(header, sizeof header, "Content-Type: %s", fetch->mimetype); ami_fetch_file_send_callback(FETCH_HEADER, fetch, header, strlen(header), errorcode); snprintf(header, sizeof header, "Content-Length: %ld", fetch->len); ami_fetch_file_send_callback(FETCH_HEADER, fetch, header, strlen(header), errorcode); } else { STRPTR errorstring; errorstring = ASPrintf("%s %s",messages_get("FileError"),fetch->path); fetch_set_http_code(fetch->fetch_handle,404); errorcode = FETCH_ERROR_HTTP_NOT2; ami_fetch_file_send_callback(FETCH_ERROR, fetch, errorstring, 0, errorcode); fetch->aborted = true; FreeVec(errorstring); } } } if(fetch && fetch->aborted) { fetch_remove_from_queues(fetch->fetch_handle); fetch_free(fetch->fetch_handle); return; } }while(node=nnode); }
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); }