Exemplo n.º 1
0
/** 
 * Loads data from file to cache starting with data under current cache pointer.
 * i.e. seeks in file number of bytes between cache start and current cache pointer.
 * 
 * @param httpd_state with fd of file to read from
 * @return -1 if file is done
 */
static int
reload_cache(struct httpd_state *s)
{
  // calculate bytes to seek in file
  int toseek = file_cache_ptr - file_cache_array;
  httpd_fs_seek(s->fd, toseek, HTTPD_SEEK_CUR);

  return load_cache(s);
}
Exemplo n.º 2
0
		void load_database_t::refresh_cache(HWND wnd, ipod_device_ptr_ref_t p_ipod, bool b_CheckIfFilesChanged, threaded_process_v2_t & p_status, abort_callback & p_abort)
		{
			p_status.checkpoint();
			load_cache(wnd, p_ipod, b_CheckIfFilesChanged, p_status, p_abort);
			p_status.checkpoint();
			if (!m_writing)
				save_cache(wnd, p_ipod, p_status, p_abort);
			p_status.checkpoint();
		}
Exemplo n.º 3
0
static void get_cache(RECPOS r)
{
    if (find_cache(r) < 0)
    {
        load_cache(r);
    }

    block_ptr = &BUFBLOCK(cache_ptr);
} 
Exemplo n.º 4
0
static void async_callback(void *cookie)
{
    time_t last_mtime;
    file_provider *provider = (file_provider *)cookie;
    last_mtime = provider->last_mtime;
    if (load_cache(provider) == 0) {
        if (last_mtime != provider->last_mtime) {
            lcb_confmon_provider_success(&provider->base, provider->config);
            return;
        }
    }

    lcb_confmon_provider_failed(&provider->base, LCB_ERROR);
}
Exemplo n.º 5
0
SceUID vpbp_dopen(const char * dirname)
{
    SceUID result;

    lock();
    result = sceIoDopen(dirname);

    if (result >= 0 && strlen(dirname) > 4 && 0 == stricmp(dirname+4, "/ISO")) {
        load_cache();
    }

    unlock();

    return result;
}
Exemplo n.º 6
0
struct hash *get_cache(void)
{
    struct hash *graph;
    struct stat st;

    if (stat(cache_filename(), &st) == -1)
        graph = init_cache();
    else
        graph = load_cache(cache_filename());

    if (!graph)
        exit(EXIT_FAILURE);

    return graph;
}
Exemplo n.º 7
0
static GeglRectangle
get_bounding_box (GeglOperation *operation)
{
  GeglRectangle result = {0,0,0,0};
  GeglProperties   *o = GEGL_PROPERTIES (operation);
  gint width, height;

  load_cache (o);

  g_object_get (o->user_data, "width", &width,
                               "height", &height, NULL);
  result.width  = width;
  result.height = height;
  return result;
}
Exemplo n.º 8
0
static void async_callback(lcb_timer_t timer,
                           lcb_t notused,
                           const void *cookie)
{
    file_provider *provider = (file_provider *)cookie;
    lcb_async_destroy(NULL, timer);
    provider->async = NULL;

    LOG(provider, TRACE, "Got async callback. Will load");

    if (load_cache(provider) == 0) {
        lcb_confmon_provider_success(&provider->base, provider->config);
    } else {
        lcb_confmon_provider_failed(&provider->base, LCB_ERROR);
    }

    (void)notused;
}
Exemplo n.º 9
0
void CaseInModel::removeRow(int i)
{
	QString rowid = m_cache[0][i].toString();

	QSqlQuery query( SqlConnectionController::qSqlDb() );

	query.exec("DELETE FROM sprawy_wejscie WHERE rowid = " + rowid );

	rowsDeleteBeganNotify(i,i);

	for ( int j = 0; j < m_cache_size; ++j )
	{
		m_cache[j].remove(i);
	}

	rowsDeleteFinishedNotify();

	updatePageCount();
	load_cache();
}
Exemplo n.º 10
0
static ff_cache_t *
prep_cache(int cat, ff_cache_t *cache)
{
	u_int32_t status, check;
	char *s;
	ff_cache_t *c;

	if (cache == NULL) return NULL;

	if (cache->notify_token == -1)
	{
		s = NULL;
		asprintf(&s, "%s.%s", NOTIFY_PREFIX, categoryFilename[cat]);
		status = notify_register_check(s, &(cache->notify_token));
		free(s);
		if (status != NOTIFY_STATUS_OK) return NULL;

		s = NULL;
		asprintf(&s, "%s/%s", DEFAULT_FF_DIR, categoryFilename[cat]);
		status = notify_monitor_file(cache->notify_token, s, 0);
		free(s);
		if (status != NOTIFY_STATUS_OK) return NULL;
	}

	pthread_mutex_lock(&(cache->lock));
	check = 1;
	if (cache->modtime != 0) 
	{
		status = notify_check(cache->notify_token, &check);
		if ((status == NOTIFY_STATUS_OK) && (check == 0))
		{
			pthread_mutex_unlock(&(cache->lock));
			return cache;
		}
	}

	c = load_cache(cat, cache);
	pthread_mutex_unlock(&(cache->lock));
	return c;
}
Exemplo n.º 11
0
Arquivo: jzip.c Projeto: dschwen/jszip
int spinupJS( char *fname ) 
{
   open_story( fname );

   configure( V1, V8 );
#else
int main( int argc, char *argv[] )
{
   process_arguments( argc, argv );

   configure( V1, V8 );

   initialize_screen(  );
#endif

   load_cache(  );

   z_restart(  );

#ifdef EMSCRIPTEN
   interpreter_status = 1;
   return 0;
}
Exemplo n.º 12
0
//*****************************************************************************
//
// Play the Colossal Cave Adventure game using either an Ethernet telnet
// connection or a USB CDC serial connection.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run from the PLL at 80 MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Enable the UART.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioInit(0);

    //
    // Print out a greeting.
    //
    UARTprintf("\033[2JColossal Cave Adventure\n");
    UARTprintf("-----------------------\n");
    UARTprintf("Connect to either the USB virtual COM port or\n");
    UARTprintf("telnet into the Ethernet port in order to play.\n\n");

    //
    // Enable the GPIO that is used for the on-board push button.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);

    //
    // Enable the GPIO that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

    //
    // Configure SysTick for a periodic interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKHZ);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Initialize the Ethernet and USB interfaces.
    //
    EnetIFInit();
    USBIFInit();

    //
    // Provide a working area to the memory allocator.
    //
    bpool(g_pucPool, sizeof(g_pucPool));

    //
    // Configure the Z-machine interpreter.
    //
    configure(V1, V5);

    //
    // Initialize the Z-machine screen interface.
    //
    initialize_screen();

    //
    // Pre-fill the Z-machine interpreter's cache.
    //
    load_cache();

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Wait until a connection has been made via either the Ethernet or USB
        // interfaces.
        //
        while(g_ulGameIF == GAME_IF_NONE)
        {
        }

        //
        // Turn on the LED to indicate that the game is in progress.
        //
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, GPIO_PIN_0);

        //
        // Loop until the game has been exited.  Repeat this loop if the game
        // exited because the restart button was pressed.
        //
        do
        {
            //
            // Take the Z-machine interpreter out of the halt state.
            //
            halt = 0;

            //
            // Set the restart flag to zero.
            //
            g_ulRestart = 0;

            //
            // Restart the Z-machine interpreter.
            //
            restart();

            //
            // Run the Z-machine interpreter until it halts.
            //
            interpret();
        }
        while(g_ulRestart);

        //
        // Turn off the LED to indicate that the game has finished.
        //
        ROM_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0);

        //
        // Close down the Ethernet connection if it was being used to play the
        // game.
        //
        if(g_ulGameIF == GAME_IF_ENET)
        {
            EnetIFClose();
        }

        //
        // Forget the interface used to play the game so that the selection
        // process will be repeated.
        //
        g_ulGameIF = GAME_IF_NONE;
    }
}
Exemplo n.º 13
0
int main(int argc, char **argv)
{
	unsigned char buf[256];
	int size, s, cntrl_s, cntrl_fd;
	socklen_t cntrl_len;
	struct sockaddr_un cntrl_addr;
	fd_set read_fds, write_fds;
	int fd_max;

	if (ax25_config_load_ports() == 0) {
		fprintf(stderr, "ax25rtd: no AX.25 port configured\n");
		return 1;
	}

	load_config();
	load_cache();

	if (fork())
		return 0;

	if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) {
		perror("AX.25 socket");
		return 1;
	}

	if ((cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
		perror("Control socket");
		return 1;
	}

	unlink(DATA_AX25ROUTED_CTL_SOCK);

	cntrl_addr.sun_family = AF_UNIX;
	strcpy(cntrl_addr.sun_path, DATA_AX25ROUTED_CTL_SOCK);
	cntrl_len =
	    sizeof(cntrl_addr.sun_family) +
	    strlen(DATA_AX25ROUTED_CTL_SOCK);

	if (bind(cntrl_s, (struct sockaddr *) &cntrl_addr, cntrl_len) < 0) {
		perror("bind Control socket");
		daemon_shutdown(1);
	}

	chmod(DATA_AX25ROUTED_CTL_SOCK, 0600);
	listen(cntrl_s, 1);

	signal(SIGUSR1, sig_debug);
	signal(SIGHUP, sig_reload);
	signal(SIGTERM, sig_term);

	cntrl_fd = -1;

	for (;;) {
		fd_max = 0;
		FD_ZERO(&read_fds);
		FD_ZERO(&write_fds);
		FD_MAX(s);
		if (cntrl_fd > 0) {
			FD_MAX(cntrl_fd);
			FD_SET(cntrl_fd, &write_fds);
		} else {
			FD_MAX(cntrl_s);
		}

		if (select(fd_max + 1, &read_fds, NULL, &write_fds, NULL) < 0) {
			if (errno == EINTR)	/* woops! */
				continue;

			if (!FD_ISSET(cntrl_fd, &write_fds)) {
				perror("select");
				save_cache();
				daemon_shutdown(1);
			} else {
				close(cntrl_fd);
				cntrl_fd = -1;
				continue;
			}
		}

		if (cntrl_fd > 0) {
			if (FD_ISSET(cntrl_fd, &read_fds)) {
				size = read(cntrl_fd, buf, sizeof(buf));
				if (size > 0) {
					buf[size] = '\0';
					interpret_command(cntrl_fd, buf);
				} else {
					close(cntrl_fd);
					cntrl_fd = -1;
				}
			}
		} else if (FD_ISSET(cntrl_s, &read_fds)) {
			if ((cntrl_fd =
			     accept(cntrl_s,
				    (struct sockaddr *) &cntrl_addr,
				    &cntrl_len)) < 0) {
				perror("accept Control");
				save_cache();
				daemon_shutdown(1);
			}
		}

		if (reload)
			reload_config();

		if (FD_ISSET(s, &read_fds))
			ax25_receive(s);
	}

	return 0;		/* what ?! */
}
Exemplo n.º 14
0
void main_loop(int argc, char *argv[], int max_hosts)
{
	int i;
	int host;
	int *targeted_host;
	FileData local_file_data;
	FileData remote_file_data;
	Order *order;
	Direction direction;
	bool use_cache;
	char *top_dir;

	FtpInit();

	targeted_host = get_targeted_host(argc, argv, max_hosts);

	for (i = 0;; i++) {
		host = targeted_host[i];
		if (host == -1) {
			break;
		}

		message(PROCESS, cfgSectionNumberToName(host), 0, host);

		direction = get_direction(host);

		get_local_file_data(&local_file_data, host);

		if (command_line_option.rebuild_cache) { /* -r | --rebuild-cache */
			rebuild_cache(host);
			free_file_data(&local_file_data);
			continue;
		}
		if (command_line_option.catch_up) { /* -R | --catch-up */
			catch_up(&local_file_data, host);
			free_file_data(&local_file_data);
			continue;
		}

		if (direction == DOWNLOAD || !does_cache_exist(host)) {
			if (direction == DOWNLOAD) {
				printf(_("Rebuilding cache for downloading...\n"));
			} else {
				printf(_("Cache file is not found.\nCreating a new one...\n"));
			}
			if (connect_to_remote_host(host) != 0) {
				free_file_data(&local_file_data);
				continue;
			}
			get_remote_file_data(&remote_file_data, host);
			use_cache = FALSE;
		} else {
			load_cache(&remote_file_data, host);
			use_cache = TRUE;
		}

		order = compare_both_hosts_and_generate_order(&local_file_data, &remote_file_data, config.local_top_dir[host], config.remote_top_dir[host], direction, host);

		if (!does_need_update(order)) {
			disconnect_from_remote_host(host);
			if (direction == UPLOAD) {
				printf(_("The remote host doesn't need updating.\n"));
			} else {
				printf(_("The local host doesn't need updating.\n"));
			}
			if (!use_cache) {
				save_cache(&remote_file_data, host);
			}
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if(command_line_option.list) {
			disconnect_from_remote_host(host);
			put_listing_of_updated_file(order, direction);
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if(command_line_option.nlist) {
			disconnect_from_remote_host(host);
			put_the_number_of_updated_file(order, direction);
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if (!use_cache) {
			printf("\n");
		}
		put_num_updated_file(order, direction);

		if (connect_to_remote_host(host) != 0) {
			free_file_data(&remote_file_data);
			free_file_data(&local_file_data);
			continue;
		}

		if (direction == UPLOAD) {
			top_dir = str_concat(config.remote_top_dir[host], "/", NULL);
		} else {
			top_dir = str_concat(config.local_top_dir[host], "/", NULL);
		}

		message(ENTER, top_dir, 0, host);
		execute_order(order, &remote_file_data, direction, host);
		message(LEAVE, top_dir, 0, host);

		free(top_dir);
		free_order(order);

		disconnect_from_remote_host(host);

		save_cache(&remote_file_data, host);

		free_file_data(&remote_file_data);
		free_file_data(&local_file_data);
	}
	free(targeted_host);
}
Exemplo n.º 15
0
/**
 * Parses shtml document for possible script includes.
 * Accepts includes of the form '%! scriptname'.
 * 
 * If scriptname starts with ':' it is assumed to be an SSI,
 * otherwise it will be handled as CGI call.
 */
static
PT_THREAD(handle_scripts(struct httpd_state *s))
{
  /* Note script includes will attach a leading : to the filename and a trailing zero */
  static char scriptname[MAX_SCRIPT_NAME_LENGTH + 1], *pptr;
  //  static uint16_t filelength;
  static int done, eof, eoc;

  PT_BEGIN(&s->scriptpt);
  eoc = eof = done = 0;

  /* Init cache (null-terminated)*/
  load_cache(s);

  while (!done) {
    
    /* Assure we can read at least a '%!' sequence. */
//    if (cache_size() < 2) {
//      reload_cache(s);
//    }

    /* Check if we should start executing a script, flagged by %! */
    if (file_cache_ptr[0] == ISO_percent &&
            file_cache_ptr[1] == ISO_bang) {
      
      /* Test if a whole line is in cache, otherwise reload cache. */
      if (strchr(&file_cache_ptr[2], ISO_nl) == NULL) {
        reload_cache(s);
      }

      /* Extract name, if starts with colon include file else call cgi */
      s->scriptptr = get_scriptname(scriptname, &file_cache_ptr[2]);
      //      s->scriptlen = files[s->fd].len - (s->scriptptr - file_cache_ptr[0]);
      PRINTD("httpd: Handle script named %s\n", scriptname);

      /* Include scripts prefixed with ':' are SSI else CGI scripts */
      if (scriptname[0] == ISO_colon) {

#if WEBSERVER_CONF_INCLUDE
        PRINTD("IS SSI\n");
        s->scriptfd = httpd_fs_open(&scriptname[1], HTTPD_FS_READ);
        /* Send script if open succeeded. */
        if (s->scriptfd != -1) {
          s->sendfd = s->scriptfd;
          PT_WAIT_THREAD(&s->scriptpt, send_file(s));
        } else {
          PRINTD("failed opening %s\n", scriptname);
        }

        httpd_fs_close(s->scriptfd);
        /*TODO dont print anything if file not found */
#endif
        /* Execute unprefixed scripts. */
      } else {
        PRINTD("IS CGI\n");
#if WEBSERVER_CONF_CGI
        PT_WAIT_THREAD(&s->scriptpt, httpd_cgi(scriptname)(s, s->scriptptr));
#endif
      }

      skip_scriptline(s);

      file_cache_ptr = s->scriptptr;

      if (cache_size() < 2) {
        reload_cache(s);
      }
      if (cache_size() == 0) {
        done = 1;
      }

    } else { // no script

      /* get position of next percent character */
      if (file_cache_ptr[0] == ISO_percent) {
        pptr = (char *) strchr(&file_cache_ptr[1], ISO_percent);
      } else {
        pptr = (char *) strchr(&file_cache_ptr[0], ISO_percent);
      }

      /* calc new length to send */
      if (pptr == NULL) {
        /* no further percent sign found in cache. */

        /* Send to end of cache */
        s->sendlen = cache_len - (&file_cache_ptr[0] - &file_cache_array[0]);
        eoc = 1;// inidcates thate we need new cache

      } else {
        s->sendlen = (int) ((int) pptr - (int) &file_cache_ptr[0]);
      }

      if (s->sendlen > 0) {
        PRINTD("httpd: Sending %u bytes from 0x%04x\n", s->sendlen, (unsigned int) pptr);
        s->sendfd = s->fd;
        PT_WAIT_THREAD(&s->scriptpt, send_part_of_cache(s));
      }

      /* Reload cache if it was marked as empty. */
      if (eoc) {
        reload_cache(s);
      }
      /* If (reloaded) cache empty, stop sending */
      if (cache_size() == 0) {
        done = 1;
      }

    }
  }

  PT_END(&s->scriptpt);
}