Example #1
0
static int lluv_file_create(lua_State *L, lluv_loop_t  *loop, uv_file h, unsigned char flags){
  lluv_file_t *f = lutil_newudatap(L, lluv_file_t, LLUV_FILE);
  f->handle = h;
  f->loop   = loop;
  f->flags  = flags | LLUV_FLAG_OPEN; 
  return 1;
}
Example #2
0
int lcurl_url_create(lua_State *L, int error_mode){
  lcurl_url_t *p;

  p = lutil_newudatap(L, lcurl_url_t, LCURL_URL);

  p->url = curl_url();
  if(!p->url) return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_URL, CURLUE_OUT_OF_MEMORY);

  p->err_mode = error_mode;

  if (lua_gettop(L) > 1) {
    const char *url = luaL_checkstring(L, 1);
    unsigned int flags = 0;
    CURLUcode code;

    if (lua_gettop(L) > 2) {
      flags = (unsigned int)lutil_optint64(L, 2, 0);
    }

    code = curl_url_set(p->url, CURLUPART_URL, url, flags);
    if (code != CURLUE_OK) {
      return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_URL, code);
    }
  }

  return 1;
}
Example #3
0
int lodbc_environment_create(lua_State *L, SQLHENV henv, uchar own){
  lodbc_env *env;
  uchar is_new = 0;
  if(henv == SQL_NULL_HANDLE){
    SQLRETURN ret = SQLAllocHandle(hENV, SQL_NULL_HANDLE, &henv);
    if (lodbc_iserror(ret))
      return lodbc_faildirect(L, "error creating environment.");
    own = 1;
    is_new = 1;
  }

  env = lutil_newudatap(L, lodbc_env, LODBC_ENV);
  memset(env, 0, sizeof(lodbc_env));
  if(!own)env->flags |= LODBC_FLAG_DONT_DESTROY;
  env->handle = henv;

  if(is_new){
    int top = lua_gettop(L);
    SQLRETURN ret = env_set_uint_attr_(L, env, SQL_ATTR_ODBC_VERSION, LODBC_ODBC3_C(SQL_OV_ODBC3, SQL_OV_ODBC2) );
    if(lodbc_is_fail(L,ret)){
      SQLFreeHandle (hENV, henv);
      env->flags &= ~LODBC_FLAG_DESTROYED;
      return ret;
    }
    lua_settop(L, top);
  }

  return 1;
}
Example #4
0
static int lcurl_url_dup(lua_State *L) {
  lcurl_url_t *r = lcurl_geturl(L);
  lcurl_url_t *p = lutil_newudatap(L, lcurl_url_t, LCURL_URL);

  p->url = curl_url_dup(r->url);
  if (!p->url) return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_URL, CURLUE_OUT_OF_MEMORY);

  p->err_mode = r->err_mode;

  return 1;
}
Example #5
0
int lcurl_error_create(lua_State *L, int error_type, int no){
  lcurl_error_t *err = lutil_newudatap(L, lcurl_error_t, LCURL_ERROR);

  assert(
    (error_type == LCURL_ERROR_EASY ) ||
    (error_type == LCURL_ERROR_MULTI) ||
    (error_type == LCURL_ERROR_SHARE) ||
    (error_type == LCURL_ERROR_FORM ) ||
    0
  );

  err->tp = error_type;
  err->no = no;
  return 1;
}
Example #6
0
int lcurl_mime_part_create(lua_State *L, int error_mode){
  //! @todo make this function as method of mime handle
  lcurl_mime_t *m = lcurl_getmime(L);

  lcurl_mime_part_t *p = lutil_newudatap(L, lcurl_mime_part_t, LCURL_MIME_PART);

  p->part = curl_mime_addpart(m->mime);

  //! @todo return more accurate error category/code
  if(!p->part) return lcurl_fail_ex(L, error_mode, LCURL_ERROR_EASY, CURLE_FAILED_INIT);

  p->rbuffer.ref = p->rd.cb_ref = p->rd.ud_ref = LUA_NOREF;
  p->err_mode = error_mode;
  p->subpart_ref = p->headers_ref = LUA_NOREF;
  p->parent = m;

  return 1;
}
Example #7
0
//{
int lcurl_share_create(lua_State *L, int error_mode){
  lcurl_share_t *p;

  lua_settop(L, 1);

  p = lutil_newudatap(L, lcurl_share_t, LCURL_SHARE);
  p->curl = curl_share_init();
  p->err_mode = error_mode;
  if(!p->curl) return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_NOMEM);

  if(lua_type(L, 1) == LUA_TTABLE){
    int ret = lcurl_utils_apply_options(L, 1, 2, 1, p->err_mode, LCURL_ERROR_SHARE, CURLSHE_BAD_OPTION);
    if(ret) return ret;
    assert(lua_gettop(L) == 2);
  }

  return 1;
}
Example #8
0
int lcurl_mime_create(lua_State *L, int error_mode){
  //! @todo make this function as method of easy handle
  lcurl_easy_t *e = lcurl_geteasy(L);

  lcurl_mime_t *p = lutil_newudatap(L, lcurl_mime_t, LCURL_MIME);

  p->mime = curl_mime_init(e->curl);

  //! @todo return more accurate error category/code
  if(!p->mime) return lcurl_fail_ex(L, error_mode, LCURL_ERROR_EASY, CURLE_FAILED_INIT);

  p->storage = lcurl_storage_init(L);
  p->err_mode = error_mode;
  p->parts = p->parent = NULL;

  /* weak reference from mime to easy handle */
  lua_pushvalue(L, 1);
  lua_rawsetp(L, LCURL_MIME_EASY, (void*)p);

  return 1;
}
Example #9
0
File: lenv.c Project: ld-test/odbc
int lodbc_environment_create(lua_State *L, SQLHENV henv, uchar own) {
    lodbc_env *env;
    uchar is_new = 0;
    if(henv == SQL_NULL_HANDLE) {
        SQLRETURN ret = SQLAllocHandle(hENV, SQL_NULL_HANDLE, &henv);
        if (lodbc_iserror(ret))
            return lodbc_faildirect(L, "error creating environment.");
        own = 1;
        is_new = 1;
    }

    env = lutil_newudatap(L, lodbc_env, LODBC_ENV);
    memset(env, 0, sizeof(lodbc_env));
    if(!own)env->flags |= LODBC_FLAG_DONT_DESTROY;
    env->handle = henv;

    env->conn_list_ref = LUA_NOREF;
    if(LODBC_OPT_INT(ENV_AUTOCLOSECNN)) {
        int top = lua_gettop(L);
        lua_pushvalue(L, -1);
        lua_pushboolean(L, 1);
        lodbc_pcall_method(L, "setautoclosecnn", 1, 0, 0);
        lua_settop(L, top);
    }

    if(is_new) {
        int top = lua_gettop(L);
        SQLRETURN ret = env_set_uint_attr_(L, env, SQL_ATTR_ODBC_VERSION, LODBC_ODBC3_C(SQL_OV_ODBC3, SQL_OV_ODBC2) );
        if(lodbc_is_fail(L,ret)) {
            SQLFreeHandle (hENV, henv);
            env->flags &= ~LODBC_FLAG_DESTROYED;
            return ret;
        }
        lua_settop(L, top);
    }

    return 1;
}
Example #10
0
File: luq.c Project: ld-test/luq
static int lluq_qvoid_new(lua_State *L, qvoid_t *q){
  lluq_qvoid_t *queue = lutil_newudatap(L, lluq_qvoid_t, LLUQ_QVOID_TYPE);
  queue->flags = LLUQ_FLAG_OPEN;
  queue->q = q;
  return 1;
}