예제 #1
0
파일: httpd.c 프로젝트: jaseg/avr-uip
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  PT_BEGIN(&s->outputpt);
 
  char *ptr;

  if(!httpd_fs_open(s->filename, &s->file)) {
    httpd_fs_open(http_404_html, &s->file);
    strcpy_P(s->filename, http_404_html);
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404));
    PT_WAIT_THREAD(&s->outputpt, send_file(s));
  } else {
    snprintf(s->tmp_str, sizeof(s->tmp_str) -1, "%d", s->file.len);
    //snprintf(s->str_tmp, 8, "%d", s->len);
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200));
    ptr = strchr(s->filename, ISO_period);
    if(ptr != NULL && strncmp_P(ptr, http_shtml, 6) == 0) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_script(s));
    } else {
      PT_WAIT_THREAD(&s->outputpt, send_file(s));
    }
  }

  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
예제 #2
0
파일: httpd.c 프로젝트: EDAyele/ptunes
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  char *ptr;
  
  PT_BEGIN(&s->outputpt);
 
  if(!httpd_fs_open(s->filename, &s->file)) {
    httpd_fs_open(http_404_html, &s->file);
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s,
		   http_header_404));
    PT_WAIT_THREAD(&s->outputpt,
		   send_file(s));
  } else {
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s,
		   http_header_200));
    ptr = strchr(s->filename, ISO_period);
#if HTTPD_CONF_SCRIPT
    if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_script(s));
    } else {
      PT_WAIT_THREAD(&s->outputpt,
		     send_file(s));
    }
#else /* HTTPD_CONF_SCRIPT */
    PT_WAIT_THREAD(&s->outputpt,
		   send_file(s));
#endif /* HTTPD_CONF_SCRIPT */
  }
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
예제 #3
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
	char *ptr;		  
	PT_BEGIN(&s->outputpt);		  
	if(!httpd_fs_open(s->filename,&s->file))//打开HTML文件不成功 
	{
		httpd_fs_open(http_404_html, &s->file);
		strcpy(s->filename, http_404_html);
		PT_WAIT_THREAD(&s->outputpt,
		send_headers(s,http_header_404));	//发送404失败页面
		PT_WAIT_THREAD(&s->outputpt,send_file(s));
	}else //打开HTML文件成功
	{
		PT_WAIT_THREAD(&s->outputpt,send_headers(s,http_header_200));
		ptr=strchr(s->filename, ISO_period);
		if(ptr != NULL && strncmp(ptr,http_shtml,6) == 0)//判断文件后缀是否为.SHTML 
		{
			PT_INIT(&s->scriptpt);
			PT_WAIT_THREAD(&s->outputpt, handle_script(s));
		}else
		{
			PT_WAIT_THREAD(&s->outputpt,send_file(s));
		}
	}
	PSOCK_CLOSE(&s->sout);
	PT_END(&s->outputpt);
}
예제 #4
0
파일: main.c 프로젝트: bncastle/Lake.exe
static int pmain(lua_State *L)
{
	//int argc = (int)lua_tointeger(L, 1);
	char **argv = (char **)lua_touserdata(L, 2);

	luaL_checkversion(L);

	//Stop collector during initialization
	lua_gc(L, LUA_GCSTOP, 0);

	//Open standard libraries
	luaL_openlibs(L);

	//TODO: Open Other libs here:

	//We use the require function here instead of opening the
	//library directly as this will register the return value
	//from the luaopen_lfs call with require's internal database of loaded modules.
	//Thus subsequent calls to require from a script will return this table
	luaL_requiref(L, "lfs", luaopen_lfs, 0);

	//Restart the GC
	lua_gc(L, LUA_GCRESTART, 0);

	//This script gets ALL the args, so we set the num passed to the C program to 0
	if (handle_script(L, argv, 0) != LUA_OK) return 0;

	//Signal no errors
	lua_pushboolean(L, 1);
	return 1;
}
예제 #5
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
static PT_THREAD(handle_output (struct httpd_state *s))
{
	/*~~~~~~~~~*/
	char	*ptr;
	/*~~~~~~~~~*/

	PT_BEGIN(&s->outputpt);

	if(!httpd_fs_open(s->filename, &s->file))
	{
		httpd_fs_open(http_404_html, &s->file);
		strcpy(s->filename, http_404_html);
		PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404));
		PT_WAIT_THREAD(&s->outputpt, send_file(s));
	}
	else
	{
		PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200));
		ptr = strchr(s->filename, ISO_period);
		if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0)
		{
			vProcessInput( s->filename );
			PT_INIT(&s->scriptpt);
			PT_WAIT_THREAD(&s->outputpt, handle_script(s));
		}
		else
		{
			PT_WAIT_THREAD(&s->outputpt, send_file(s));
		}
	}

	PSOCK_CLOSE(&s->sout);
	PT_END(&s->outputpt);
}
예제 #6
0
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  char *ptr;
  
  PT_BEGIN(&s->outputpt);
#if DEBUGLOGIC
   httpd_strcpy(s->filename,httpd_indexfn);
#endif
  if(!httpd_fs_open(s->filename, &s->file)) {
    httpd_strcpy(s->filename, httpd_404fn);
    httpd_fs_open(s->filename, &s->file);
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_404notf));
    PT_WAIT_THREAD(&s->outputpt, send_file(s));
  } else {
    PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_200ok));
    ptr = strchr(s->filename, ISO_period);
    if((ptr != NULL && httpd_strncmp(ptr, httpd_shtml, 6) == 0) || httpd_strcmp(s->filename,httpd_indexfn)==0) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_script(s));
    } else {
      PT_WAIT_THREAD(&s->outputpt, send_file(s));
    }
  }
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
예제 #7
0
파일: lua.c 프로젝트: andyvand/UltraDefrag
static int pmain (lua_State *L) {
  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
  char **argv = s->argv;
  int script;
  int has_i = 0, has_v = 0, has_e = 0;
  globalL = L;
  if (argv[0] && argv[0][0]) progname = argv[0];
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);
  s->status = handle_luainit(L);
  if (s->status != 0) return 0;
  script = collectargs(argv, &has_i, &has_v, &has_e);
  if (script < 0) {  /* invalid args? */
    print_usage();
    s->status = 1;
    return 0;
  }
  if (has_v) print_version();
  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
  if (s->status != 0) return 0;
  if (script)
    s->status = handle_script(L, argv, script);
  if (s->status != 0) return 0;
  if (has_i)
    dotty(L);
  else if (script == 0 && !has_e && !has_v) {
    if (lua_stdin_is_tty()) {
      print_version();
      dotty(L);
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
  return 0;
}
예제 #8
0
파일: lua.c 프로젝트: mabako/iv-modlua
static int pmain (lua_State *L) {
  int argc = (int)lua_tointeger(L, 1);
  char **argv = (char **)lua_touserdata(L, 2);
  int script;
  int has_i = 0, has_v = 0, has_e = 0;
  if (argv[0] && argv[0][0]) progname = argv[0];
  script = collectargs(argv, &has_i, &has_v, &has_e);
  if (script < 0) {  /* invalid arg? */
    print_usage(argv[-script]);
    return 0;
  }
  if (has_v) print_version();
  /* open standard libraries */
  luaL_checkversion(L);
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, 0);
  /* run LUA_INIT */
  if (handle_luainit(L) != LUA_OK) return 0;
  /* execute arguments -e and -l */
  if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
  /* execute main script (if there is one) */
  if (script && handle_script(L, argv, script) != LUA_OK) return 0;
  if (has_i)  /* -i option? */
    dotty(L);
  else if (script == 0 && !has_e && !has_v) {  /* no arguments? */
    if (lua_stdin_is_tty()) {
      print_version();
      dotty(L);
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
예제 #9
0
파일: httpd.c 프로젝트: ADVANSEE/mist
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  char *ptr;
  
  PT_BEGIN(&s->outputpt);
 
  if(!httpd_fs_open(s->filename, &s->file)) {
    strcpy(s->filename, ip64_webserver_http_404_html);
    httpd_fs_open(s->filename, &s->file);
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s,
		   ip64_webserver_http_header_404));
    PT_WAIT_THREAD(&s->outputpt,
		   send_file(s));
  } else {
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s,
		   ip64_webserver_http_header_200));
    ptr = strrchr(s->filename, ISO_period);
    if(ptr != NULL && strncmp(ptr, ip64_webserver_http_shtml, 6) == 0) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_script(s));
    } else {
      PT_WAIT_THREAD(&s->outputpt,
		     send_file(s));
    }
  }
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
예제 #10
0
static int pmain(lua_State *L)
{
    int  argc   = (int)lua_tointeger(L, 1);
    char **argv = (char**)lua_touserdata(L, 2);
    int  script;
    int  args[num_has];

    args[has_i] = args[has_v] = args[has_e] = args[has_E] = 0;
    if (argv[0] && argv[0][0])
        progname = argv[0];

    script = collectargs(argv, args);
    if (script < 0)  /* invalid arg? */
    {
        print_usage(argv[-script]);
        return 0;
    }

    if (args[has_v])
        print_version();

    if (args[has_E])  /* option '-E'? */
    {
        lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
        lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
    }

    /* open standard libraries */
    luaL_checkversion(L);
    lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
    luaL_openlibs(L); /* open libraries */
    lua_gc(L, LUA_GCRESTART, 0);
    if (!args[has_E] && handle_luainit(L) != LUA_OK)
        return 0; /* error running LUA_INIT */

    /* execute arguments -e and -l */
    if (!runargs(L, argv, (script > 0) ? script : argc))
        return 0;

    /* execute main script (if there is one) */
    if (script && handle_script(L, argv, script) != LUA_OK)
        return 0;

    if (args[has_i]) /* -i option? */
        dotty(L);
    else if (script == 0 && !args[has_e] && !args[has_v])  /* no arguments? */
    {
        if (lua_stdin_is_tty())
        {
            print_version();
            dotty(L);
        }
        else
            dofile(L, NULL); /* executes stdin as a file */
    }

    lua_pushboolean(L, 1); /* signal no errors */
    return 1;
}
예제 #11
0
static int pmain (lua_State *L) {
    struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
    char *script = s->script;
    globalL = L;

    s->status = handle_script(L, script);

    return s->status;
}
예제 #12
0
static int pmain(lua_State *L)
{
  struct Smain *s = &smain;
  char **argv = s->argv;
  int script;
  int flags = 0;
  globalL = L;
  if (argv[0] && argv[0][0]) progname = argv[0];
  LUAJIT_VERSION_SYM();  /* linker-enforced version check */
  script = collectargs(argv, &flags);
  if (script < 0) {  /* invalid args? */
    print_usage();
    s->status = 1;
    return 0;
  }
  if ((flags & FLAGS_NOENV)) {
    lua_pushboolean(L, 1);
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  s->status = tvm_loadbufferx(L, luaJIT_BC_op, luaJIT_BC_op_SIZE, "op", "b")
           || docall(L, 0, 1);
  if (s->status != 0) return 0;
  s->status = tvm_loadbufferx(L, luaJIT_BC_parse, luaJIT_BC_parse_SIZE, "parse", "b")
           || docall(L, 0, 1);
  if (s->status != 0) return 0;
  s->status = tvm_loadbufferx(L, luaJIT_BC_lunokhod, luaJIT_BC_lunokhod_SIZE, "lunokhod", "b")
           || docall(L, 0, 1);
  if (s->status != 0) return 0;
  lua_gc(L, LUA_GCRESTART, -1);
  if (!(flags & FLAGS_NOENV)) {
    s->status = handle_luainit(L);
    if (s->status != 0) return 0;
  }
  if ((flags & FLAGS_VERSION)) print_version();
  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
  if (s->status != 0) return 0;
  if (script) {
    s->status = handle_script(L, argv, script);
    if (s->status != 0) return 0;
  }
  if ((flags & FLAGS_INTERACTIVE)) {
    print_jit_status(L);
    dotty(L);
  } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
    if (lua_stdin_is_tty()) {
      print_version();
      print_jit_status(L);
      dotty(L);
    } else {
      dofile(L, NULL);  /* executes stdin as a file */
    }
  }
  return 0;
}
예제 #13
0
파일: jive.c 프로젝트: presslab-us/jivelite
/* pmain
** our main, called in lua protected mode by main
*/
static int pmain (lua_State *L) {

    // fetch *Smain from the stack
    struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
    int script = 0;
    char **argv = s->argv;

    // set our global state
    globalL = L;

    // stop collector during initialization
    lua_gc(L, LUA_GCSTOP, 0);

    // open lua libraries
    luaL_openlibs(L);

    // configure paths
    paths_setup(L, argv[0]);

    // init system and platform information
    jive_system_init(L);

    // init logging
    jive_log_init(L);

    // open jive libraries
    jive_openlibs(L);

    // restart collector
    lua_gc(L, LUA_GCRESTART, 0);

#ifdef NO_STDIO_REDIRECT
    /* SDL not redirecting. Instead, put console output in user writable directory - used for Vista, for instance which disallows writing to app dir */
    redirect_stdio();
#endif

    /*
    // do we have an argument? - disabled as we do not want to run alternative scripts, but want to see the arguments
    if (argv[1] != NULL) {
    	script = 1;
    }
    */

    // do a script
    s->status = handle_script(L, argv, script);
    if (s->status != 0) {
        return 0;
    }

    return 0;
}
예제 #14
0
static int lua_include(lua_State *L)
{
    char filepath[512];
    const char *script = lua_tostring(L, 1);

    if(strstr(script, "..") || strstr(script, ":") || strstr(script, "%") || script[0] == '\\' || script[0] == '/')
    {
        CAdminOP::ColorMsg(CONCOLOR_LUA_ERR, "invalid include path `%s'\n", script);
        return 0;
    }

    Q_snprintf(filepath, sizeof(filepath), "%s/%s", lastscriptpath, script);
    V_FixSlashes(filepath);

    return handle_script(L, filepath);
}
예제 #15
0
static
PT_THREAD(handle_output(struct httpd_state *s))
{
	char *ptr;

	PT_BEGIN(&s->outputpt);
#if DEBUGLOGIC
	httpd_strcpy(s->filename,httpd_indexfn);
#endif
	if(!httpd_fs_open(s->filename, &s->file)) {
		httpd_strcpy(s->filename, httpd_404fn);
		httpd_fs_open(s->filename, &s->file);
		PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_404notf));
		PT_WAIT_THREAD(&s->outputpt, send_file(s));
	} else {

    PRINTF("s->state: %d\r\n", s->state);

    if(s->state == STATE_OUTPUT)
    {
      PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_200ok));

      ptr = strchr(s->filename, ISO_period);
      if((ptr != NULL && httpd_strncmp(ptr, httpd_shtml, 6) == 0) || httpd_strcmp(s->filename,httpd_indexfn)==0) {
        PT_INIT(&s->scriptpt);
        PT_WAIT_THREAD(&s->outputpt, handle_script(s));
      } else {
        PT_WAIT_THREAD(&s->outputpt, send_file(s));
      }
    } else { // state == STATE_OUTPUT_ERROR
      if(s->error_number == 413)
      {
        // Send the error message file instead.
        httpd_strcpy(s->filename, httpd_413fn);
        httpd_fs_open(s->filename, &s->file);

        PT_WAIT_THREAD(&s->outputpt, send_headers(s, httpd_413error));
        PT_WAIT_THREAD(&s->outputpt, send_file(s));
      }
      // other error messages can be added here.
    }
	}
	PSOCK_CLOSE(&s->sout);
	PT_END(&s->outputpt);
}
예제 #16
0
/*
** Main body of stand-alone interpreter (to be called in protected mode).
** Reads the options and handles them all.
*/
static int pmain (lua_State *L) {
  int argc = (int)lua_tointeger(L, 1);
  char **argv = (char **)lua_touserdata(L, 2);
  int script;
  int args = collectargs(argv, &script);
  luaL_checkversion(L);  /* check that interpreter has correct version */
  if (argv[0] && argv[0][0]) progname = argv[0];
#if 0
  if (args == has_error) {  /* bad arg? */
    print_usage(argv[script]);  /* 'script' has index of bad arg. */
    return 0;
  }
#endif
  if (args & has_v)  /* option '-v'? */
    print_version();
  if (args & has_E) {  /* option '-E'? */
    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  luaL_openlibs(L);  /* open standard libraries */
  createargtable(L, argv, argc, script);  /* create table 'arg' */
  if (!(args & has_E)) {  /* no option '-E'? */
    if (handle_luainit(L) != LUA_OK)  /* run LUA_INIT */
      return 0;  /* error running LUA_INIT */
  }
  if (!runargs(L, argv, script))  /* execute arguments -e and -l */
    return 0;  /* something failed */
  if (script < argc &&  /* execute main script (if there is one) */
      handle_script(L, argv + script) != LUA_OK)
    return 0;
#if 0
  if (args & has_i)  /* -i option? */
    doREPL(L);  /* do read-eval-print loop */
  else if (script == argc && !(args & (has_e | has_v))) {  /* no arguments? */
    if (lua_stdin_is_tty()) {  /* running in interactive mode? */
      print_version();
      doREPL(L);  /* do read-eval-print loop */
    }
    else dofile(L, NULL);  /* executes stdin as a file */
  }
#endif
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
예제 #17
0
파일: lua.c 프로젝트: liangxiegame/lua
/*
** 独立主函数的解释器(在保护模式下被调用)
** 读取选项参数并且处理他们
*/
static int pmain (lua_State *L) {
  int argc = (int)lua_tointeger(L, 1);
  char **argv = (char **)lua_touserdata(L, 2);
  int script;
  int args = collectargs(argv, &script);
  luaL_checkversion(L);  /* 检查解释器的版本*/
  if (argv[0] && argv[0][0]) progname = argv[0];
  if (args == has_error) {  /* 坏变量? */
    print_usage(argv[script]);  /* '脚本'存在坏的变量 */
    return 0;
  }
  if (args & has_v)  /* 带有选项参数 '-v'? */
    print_version();
  if (args & has_E) {  /* 带有选项参数 '-E'? */
    lua_pushboolean(L, 1);  /* signal for libraries to ignore env. vars. */
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  luaL_openlibs(L);  /* 打开标准库 */
  createargtable(L, argv, argc, script);  /* 创建表 'arg' */
  if (!(args & has_E)) {  /* 没有选项'-E'? */
    if (handle_luainit(L) != LUA_OK)  /* 执行LUA_INIT */
      return 0;  /* error running LUA_INIT */
  }
  if (!runargs(L, argv, script))  /* 执行选项参数 -e and -l */
    return 0;  /* something failed */
  if (script < argc &&  /**************************************** 执行主脚本 (如果有一个),这里是重点 *************************************/
      handle_script(L, argv + script) != LUA_OK)
    return 0;
  if (args & has_i)  /* -i 选项参数? */
    doREPL(L);  /* do read-eval-print loop 交互模式,即读取->运算->输出循环 */
  else if (script == argc && !(args & (has_e | has_v))) {  /* 没有参数? */
    if (lua_stdin_is_tty()) {  /* 交互模式运行? */
      print_version();
      doREPL(L);  /* do read-eval-print loop   交互模式,即读取->运算->输出循环*/
    }
    else dofile(L, NULL);  /* 执行stdin as a file */
  }
  lua_pushboolean(L, 1);  /* signal no errors */
  return 1;
}
예제 #18
0
파일: luajit.c 프로젝트: loveshell/ironbee
static int pmain(lua_State *L)
{
  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
  char **argv = s->argv;
  int script;
  int flags = 0;
  globalL = L;
  if (argv[0] && argv[0][0]) progname = argv[0];
  LUAJIT_VERSION_SYM();  /* linker-enforced version check */
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */
  lua_gc(L, LUA_GCRESTART, -1);
  s->status = handle_luainit(L);
  if (s->status != 0) return 0;
  script = collectargs(argv, &flags);
  if (script < 0) {  /* invalid args? */
    print_usage();
    s->status = 1;
    return 0;
  }
  if ((flags & FLAGS_VERSION)) print_version();
  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
  if (s->status != 0) return 0;
  if (script)
    s->status = handle_script(L, argv, script);
  if (s->status != 0) return 0;
  if ((flags & FLAGS_INTERACTIVE)) {
    print_jit_status(L);
    dotty(L);
  } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
    if (lua_stdin_is_tty()) {
      print_version();
      print_jit_status(L);
      dotty(L);
    } else {
      dofile(L, NULL);  /* executes stdin as a file */
    }
  }
  return 0;
}
예제 #19
0
파일: httpd.c 프로젝트: Carrotman42/cs4534
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  char *ptr;
  
  PT_BEGIN(&s->outputpt);
 
  if(!httpd_fs_open(s->filename, &s->file)) {
    httpd_fs_open(http_404_html, &s->file);
    strcpy(s->filename, http_404_html);
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s,
		   http_header_404));
    PT_WAIT_THREAD(&s->outputpt,
		   send_file(s));
  } else {
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s,
		   http_header_200));
    ptr = strchr(s->filename, ISO_period);
    if(ptr != NULL && (strncmp(ptr, http_shtml, 6) == 0 || strncmp(ptr, ".bin", 4) == 0)) {
      PT_INIT(&s->scriptpt);
      PT_WAIT_THREAD(&s->outputpt, handle_script(s));
    } else {
      PT_WAIT_THREAD(&s->outputpt,
		     send_file(s));
    }
  }
  if (s->emumode) {
	// Just switched to emulator mode! Fix the state
	s->state = STATE_WAITING;
  } else {
	PSOCK_CLOSE(&s->sout);
  }
  PT_END(&s->outputpt);
}
예제 #20
0
파일: httpd.c 프로젝트: hericz/atinom_banyu
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
	char *ptr;
  
	PT_BEGIN(&s->outputpt);
 
	if(!httpd_fs_open(s->filename, &s->file)) {
		//printf(" HTTP file %s tidak ada\n", s->filename);
		httpd_fs_open(http_404_html, &s->file);
    	strcpy(s->filename, http_404_html);
    	PT_WAIT_THREAD(&s->outputpt,
			   send_headers(s,
			   http_header_404));
	    PT_WAIT_THREAD(&s->outputpt,
			   send_file(s));

	} else {
//*		
		#ifdef PAKAI_HTTP
		if (strncmp(s->filename, "/about", 6) == 0) {
			//printf(" Buat file about\r\n");
			
			buat_file_about();
			
			s->file.len = strlen(tot_buf);
			
			portENTER_CRITICAL();
			s->file.data = tot_buf;
			portEXIT_CRITICAL();
		}

		else if (strncmp(s->filename, "/setting", 8) == 0) {
			//printf(" Buat file setting: %s\r\n", s->filename);
			if (strncmp(s->filename,"/setting.html?u=1",17)==0) {
				ganti_setting(s->filename);
				buat_file_setting(1, s->filename);
			} else if (strncmp(s->filename,"/setting.html?smb=1",19)==0) {
				buat_file_setting(2, s->filename);
			} else if (strncmp(s->filename,"/setting.html?smb=3",19)==0) 
			{
				buat_file_setting(3, s->filename);
				printf("buat_file_setting: OK\r\n");
			} 
			else if (strncmp(s->filename,"/setting.html?smb=4",19)==0) {
				buat_file_setting(4, s->filename);
			#ifdef TES_GET_WEB
			} else if (strncmp(s->filename,"/setting.html?smb=5",19)==0) {
				buat_file_setting(5, s->filename);
			#endif
			} else {
				buat_file_setting(0,"");
			}

			s->file.len = strlen(tot_buf);
			printf("Kirim file ke client. len: %d\n",s->file.len);		
			portENTER_CRITICAL();
			s->file.data = tot_buf;
			portEXIT_CRITICAL();

		} 
		#ifdef PAKAI_PM
		else if (strncmp(s->filename, "/index.html?sbr=1", 17) == 0) {
			buat_file_index(1, s->filename);
			s->file.len = strlen(tot_buf);
			portENTER_CRITICAL();
			s->file.data = tot_buf;
			portEXIT_CRITICAL();

		} 
		#endif
		else {
			//printf(" Buat file index\r\n");
			buat_file_index(0, "");
			s->file.len = strlen(tot_buf);
			portENTER_CRITICAL();
			s->file.data = tot_buf;
			portEXIT_CRITICAL();
		}
		#endif
	
		PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_200));
		ptr = strchr(s->filename, ISO_period);
		
		if(ptr != NULL && strncmp(ptr, http_shtml, 6) == 0) {
			//printf(" script !\n");
			PT_INIT(&s->scriptpt);
			PT_WAIT_THREAD(&s->outputpt, handle_script(s));
		} else {
			//printf(" biasa !\n");
			PT_WAIT_THREAD(&s->outputpt, send_file(s));
		}
	}
	PSOCK_CLOSE(&s->sout);
	PT_END(&s->outputpt);
}
예제 #21
0
int main( void )
{    
    _delay_ms(100);
    // set clock speed
    CLKPR = _BV( CLKPCE );                 // enable clock prescale change
    CLKPR = 0;                             // full speed (8MHz);

#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || \
      defined(__AVR_ATtiny85__)

    // set up periodic timer for state machine ('script_tick')
    TCCR0B = _BV( CS02 ) | _BV(CS00); // start timer, prescale CLK/1024
    TIFR   = _BV( TOV0 );          // clear interrupt flag
    TIMSK  = _BV( TOIE0 );         // enable overflow interrupt

    // set up output pins   
    PORTB = INPI2C_MASK;          // turn on pullups 
    DDRB  = LED_MASK;             // set LED port pins to output

#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || \
      defined(__AVR_ATtiny84__)

    // set up periodic timer for state machine ('script_tick')
    //TCCR0B = _BV( CS02 ) | _BV(CS00); // start timer, prescale CLK/1024
    //TIFR0  = _BV( TOV0 );          // clear interrupt flag
    //TIMSK0 = _BV( TOIE0 );         // enable overflow interrupt
    // set up output pins   
    PORTA = INPI2C_MASK;          // turn on pullups 
    DDRA  = 0xFF; //LEDA_MASK;            // set LED port pins to output
    DDRB  = 0xFF; //LEDB_MASK;            // set LED port pins to output
    
#endif
    
    fanfare( 3, 300 );

#if 0
    // test for ATtiny44/84 MaxM
    fanfare( 3, 300 );

    IRsend_enableIROut();

    while( 1 ) {
        _delay_ms(10);
        IRsend_iroff();
        _delay_ms(10);
        IRsend_iron();
    }

    /*
    uint8_t f = OCR1B;
    while( 1 ) {
        _delay_ms(10);
        f++; 
        if( f== OCR1A ) f=0;  // OCR1A == period
        OCR1B = f;            // OCR1B == duty cycle (0-OCR1A)
    }
    */
#endif

#if 0
    // test timing of script_tick
    _delay_ms(2000);
    sei();
    _delay_ms(500);  // this should cause script_tick to equal 15
    uint8_t j = script_tick;
    for( int i=0; i<j; i++ ) {
        led_flash();
        _delay_ms(300);
    }
#endif

    //////  begin normal startup

    uint8_t boot_mode      = eeprom_read_byte( &ee_boot_mode );
    uint8_t boot_script_id = eeprom_read_byte( &ee_boot_script_id );
    uint8_t boot_reps      = eeprom_read_byte( &ee_boot_reps );
    //uint8_t boot_fadespeed = eeprom_read_byte( &ee_boot_fadespeed );
    uint8_t boot_timeadj   = eeprom_read_byte( &ee_boot_timeadj );

    // initialize i2c interface
    uint8_t i2c_addr = eeprom_read_byte( &ee_i2c_addr );
    if( i2c_addr==0 || i2c_addr>0x7f) i2c_addr = I2C_ADDR;  // just in case

    i2c_addrs[0] = i2c_addr;
    for( uint8_t i = 1; i<slaveAddressesCount; i++ ) {
        i2c_addrs[i] = i2c_addrs[0] + i;
    }
    usiTwiSlaveInit( i2c_addrs );

    timeadj    = boot_timeadj;
    if( boot_mode == BOOT_PLAY_SCRIPT ) {
        play_script( boot_script_id, boot_reps, 0 );
    }

    sei();                      // enable interrupts

#if 0
    basic_tests();
#endif

    RB_Init();
    // This loop runs forever. 
    // If the TWI Transceiver is busy the execution will just 
    // continue doing other operations.
    for(;;) {
        handle_i2c();
        handle_inputs();
        handle_script();
        handle_ir_queue();
    }
    
} // end
예제 #22
0
파일: luajit.c 프로젝트: c---/MultiWiiCL
static int pmain(lua_State *L)
{
  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
  char **argv = s->argv;
  int script;
  int flags = 0;
  globalL = L;
  if (argv[0] && argv[0][0]) progname = argv[0];
  LUAJIT_VERSION_SYM();  /* linker-enforced version check */
  script = collectargs(argv, &flags);
  if (script < 0) {  /* invalid args? */
    print_usage();
    s->status = 1;
    return 0;
  }
  if ((flags & FLAGS_NOENV)) {
    lua_pushboolean(L, 1);
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */

  /**************/
  lua_pushstring(L, MULTIWIICL_VERSION);
  lua_setglobal(L, "MULTIWIICL_VERSION");

  extern int luaopen_lpeg(lua_State*);
  lua_pushcfunction(L, luaopen_lpeg);
  lua_call(L, 0, 0);

  extern int luaopen_luaserial(lua_State*);
  lua_pushcfunction(L, luaopen_luaserial);
  lua_call(L, 0, 0);

  extern int luaopen_linenoise(lua_State*);
  lua_pushcfunction(L, luaopen_linenoise);
  lua_call(L, 0, 1);

# include "Config.h"
  if (dostring(L, (const char*)Config, "@Config")) {
    printf("%s\n", lua_tostring(L, -1));
    lua_pop(L, 1);
  }

# include "MultiWii.h"
  if (dostring(L, (const char*)MultiWii, "@MultiWii")) {
    printf("%s\n", lua_tostring(L, -1));
    lua_pop(L, 1);
  }

  /**************/

  lua_gc(L, LUA_GCRESTART, -1);
  if (!(flags & FLAGS_NOENV)) {
    s->status = handle_luainit(L);
    if (s->status != 0) return 0;
  }

  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
  if (s->status != 0) return 0;
  if (script) {
    s->status = handle_script(L, argv, script);
    if (s->status != 0) return 0;
  }

  if ((flags & FLAGS_INTERACTIVE) || (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION)))) {
#   include "Prompt.h"
    if (dostring(L, (const char*)Prompt, "@Prompt")) {
      printf("%s\n", lua_tostring(L, -1));
      lua_pop(L, 1);
    }
  }

//  if ((flags & FLAGS_VERSION)) print_version();
//  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
//  if (s->status != 0) return 0;
//  if (script) {
//    s->status = handle_script(L, argv, script);
//    if (s->status != 0) return 0;
//  }
//  if ((flags & FLAGS_INTERACTIVE)) {
//    print_jit_status(L);
//    dotty(L);
//  } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
//    if (lua_stdin_is_tty()) {
//      print_version();
//      print_jit_status(L);
//      dotty(L);
//    } else {
//      dofile(L, NULL);  /* executes stdin as a file */
//    }
//  }
  return 0;
}
int httpd_handle_file(httpd_request_t *req_p, struct fs *fs)
{
	const char *anchor = "/";
	char tmp[HTTPD_MAX_URI_LENGTH+1];
	const char *encoding = NULL;
	char *msg_in, *ptr, *type = NULL;
	int err, msg_in_len = HTTPD_MAX_MESSAGE - 1, conn = req_p->sock;
	int ret;

	msg_in = os_mem_alloc(HTTPD_MAX_MESSAGE + 2);
	if (!msg_in) {
		httpd_e("Failed to allocate memory for file handling");
		/* Check what needs to be returned */
		return -WM_FAIL;
	}
	memset(msg_in, 0, HTTPD_MAX_MESSAGE + 2);

	SYS_FILE_DECL;

	if (!fs) {
		/* The filesystem wasn't mounted properly */
		httpd_send_hdr_from_str(conn, http_header_404,
					CONTENT_TYPE_PLAIN, encoding,
					NO_CACHE_HEADERS, UNUSED_PARAM);
		httpd_send_default_headers(conn,
				req_p->wsgi->hdr_fields);
		httpd_send_crlf(conn);
		httpd_send(conn, FILE_NOT_FOUND, sizeof(FILE_NOT_FOUND));
		ret = WM_SUCCESS;
		goto out;
	}
	struct ftfs_super *f_super = fs_to_ftfs_sb(fs);

	/* Ensure that the anchor is the first part of the filename */
	ptr = strstr(req_p->filename, anchor);
	if (ptr == NULL ||
	    ptr != req_p->filename) {
		httpd_d("No anchor in filename\r\n");
		ret = httpd_send_error(conn, HTTP_500);
		goto out;
	}

	/* Zap the anchor from the filename */
	ptr = req_p->filename + strlen(anchor);
	err = 0;
	/* anchors are only across directory boundaries */
	if (*ptr != '/')
		req_p->filename[err++] = '/';

	while (*ptr && (*ptr != '?')) {
		req_p->filename[err] = *ptr;
		ptr++;
		err++;
	}
	req_p->filename[err] = '\0';

	/* "/" implies a request for index.html */
	if (strncmp(req_p->filename, "/", 2) == 0) {
		strncpy(req_p->filename, http_index_html,
			sizeof(http_index_html));
	}

	/* Find if .gz version exists for file, if it is then serve that */
	type = strrchr(req_p->filename, ISO_period);
	if (type) {
		strncpy(tmp, req_p->filename, sizeof(tmp));
		strncat(tmp, ".gz", 3);
		httpd_d("Look for gz file if it exists: %s\r\n", tmp);
		if (htsys_file_open(fs, tmp, sys_filep) == WM_SUCCESS) {
			/* Gzipped version exists, serve that */
			httpd_d("Serve gzipped file\r\n");
			strncpy(req_p->filename, tmp, HTTPD_MAX_URI_LENGTH + 1);
			encoding = ".gz";
			htsys_close(fs, sys_filep);
		}
	}

	ret = httpd_parse_hdr_tags(req_p, conn, msg_in, msg_in_len);
	if (ret < 0) {
		httpd_d("Parsing headers failed \r\n");
		ret = httpd_send_error(conn, HTTP_500);
		goto out;
	}

	/* It is not a WSGI, check to see if the file exists */
	if (htsys_file_open(fs, req_p->filename, sys_filep) == -WM_FAIL) {
		httpd_w("file not found: %s\r\n", req_p->filename);

		ret = httpd_send_hdr_from_str(conn, http_header_404,
					      type, encoding, NO_CACHE_HEADERS,
					      UNUSED_PARAM);
		httpd_send_default_headers(conn,
				req_p->wsgi->hdr_fields);
		httpd_send_crlf(conn);
		if (ret != WM_SUCCESS)
			goto out;

		ret = htsys_file_open(fs, http_404_html, sys_filep);
		if (ret == WM_SUCCESS) {
			ret = httpd_send_file(fs, conn, sys_filep);
			goto out;
		} else
			httpd_w("No local 404 file.  Sending empty 404"
			      " response.\r\n");
	} else {
		/* Ok, the file exists, is it a script html or just html */
		g_wm_stats.wm_hd_file++;
		if (req_p->if_none_match &&
		    (f_super->fs_crc32 == req_p->etag_val)) {
			/* We do not need the file handle now */
			htsys_close(fs, sys_filep);

			/* Send Not Modified header */

			/* Send header prologue */
			ret = httpd_send(conn, http_header_304_prologue,
					 strlen(http_header_304_prologue));
			if (ret != WM_SUCCESS)
				goto out;
			httpd_send_header(conn, "Server", "Marvell-WM");
			httpd_send_header(conn, "Connection", "Close");

			/* Send ETag */
			int len;
			const char *h = httpd_get_etag_hdr(req_p->etag_val,
							   &len);
			ret = httpd_send(conn, h, len);
			if (ret != WM_SUCCESS)
				goto out;
			/* Close the header */
			ret = httpd_send_crlf(conn);
			goto out;
		} else  {
			ret = httpd_send_hdr_from_str(conn, http_header_200,
						      type, encoding,
						      SEND_CACHE_HEADERS,
						      f_super->fs_crc32);
			httpd_send_default_headers(conn,
					req_p->wsgi->hdr_fields);
			httpd_send_crlf(conn);

			if (ret != WM_SUCCESS)
				goto out;
			ptr = strchr(req_p->filename, ISO_period);
			if (ptr != NULL && strncmp(ptr, http_shtml,
						   sizeof(http_shtml)
						   - 1) == 0) {
				httpd_d("Handling script: %s", req_p->filename);
				ret = handle_script(fs, req_p, conn,
						    sys_filep, msg_in);
				htsys_close(fs, sys_filep);
				if (ret != WM_SUCCESS) {
					httpd_d("Script failed\r\n");
					goto out;
				}
			} else {
				ret = httpd_send_file(fs, conn, sys_filep);
				if (ret != WM_SUCCESS)
					goto out;
			}
		}
	}
	ret = httpd_send_last_chunk(conn);
out:
	os_mem_free(msg_in);
	return ret;
}
예제 #24
0
static int pmain(lua_State *L)
{
	struct Smain *s = &smain;
	char **argv = s->argv;
	int argn;
	int flags = 0;
	globalL = L;
	if (argv[0] && argv[0][0]) progname = argv[0];

	LUAJIT_VERSION_SYM();  /* Linker-enforced version check. */

	argn = collectargs(argv, &flags);
  if (argn < 0) {  /* Invalid args? */
		print_usage();
		s->status = 1;
		return 0;
	}

	if ((flags & FLAGS_NOENV)) {
		lua_pushboolean(L, 1);
		lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
	}

	/* Set MAD env _before_ libraries are open. */
	mad_setenv(L, flags & FLAGS_NOENV);

	/* Stop collector during library initialization. */
	lua_gc(L, LUA_GCSTOP, 0);
	luaL_openlibs(L);
	mad_openlibs(L);
	lua_gc(L, LUA_GCRESTART, -1);

	createargtable(L, argv, s->argc, argn);

	if (!(flags & FLAGS_NOENV)) {
		s->status = handle_luainit(L);
		if (s->status != LUA_OK) return 0;
	}

	/* MAD section. */
	mad_setsig();
	mad_regfunc();

	if ((flags & FLAGS_MADENV))
		dolibrary(L, "madl_main");
	if (!(flags & FLAGS_NOENV)) {
		s->status = handle_madinit(L);
		if (s->status != LUA_OK) return 0;
	}

	if ((flags & FLAGS_VERSION)) print_version();

	s->status = runargs(L, argv, argn);
	if (s->status != LUA_OK) return 0;

	if (s->argc > argn) {
    s->status = handle_script(L, argv + argn);
		if (s->status != LUA_OK) return 0;
	}

	if ((flags & FLAGS_INTERACTIVE)) {
		(void)print_jit_status;
		dotty(L);
	} else if (s->argc == argn && !(flags & FLAGS_EXEC)) {
		if (lua_stdin_is_tty()) {
			(void)print_version;
			(void)print_jit_status;
			dotty(L);
		} else {
			dofile(L, NULL);  /* Executes stdin as a file. */
		}
	}
	return 0;
}