Giter Club home page Giter Club logo

Comments (11)

daurnimator avatar daurnimator commented on July 24, 2024

Can you provide any assurance on the layout of t_context?

At least that the SSL_CTX* will remain the first element of the struct?

from luasec.

brunoos avatar brunoos commented on July 24, 2024

I think it is possible keep it as first field.
But I want to be clear that I see t_context, t_ssl, etc., as internal structures.
If we need some kind of access to these structures, it would be saver to think in a standard C API to retrieve OpenSSL objects from LuaSec.

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

If we need some kind of access to these structures, it would be saver to think in a standard C API to retrieve OpenSSL objects from LuaSec.

Ahha. I just noticed lsec_checkcontext exists.

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

Could you add a lsec_testcontext to go along with that?

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

@brunoos ?

from luasec.

brunoos avatar brunoos commented on July 24, 2024

sorry, what is lsec_testcontext ?

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

sorry, what is lsec_testcontext ?

Analogous to luaL_testudata vs luaL_checkudata.
It would test the argument to see if it's a valid context; if so, return a pointer to the SSL_CTX. if not, return NULL.

from luasec.

brunoos avatar brunoos commented on July 24, 2024

ok... the easy way is use luaL_testudata, but there is no such function in Lua 5.1.

It should be re-implemented (or imported from 5.2 or 5.3).

Do you think another way?

/*-- Compat - Lua 5.1 --------------------------------------------------------*/

#if (LUA_VERSION_NUM == 501)

#define luaL_testudata(L, ud, tname)  testudata(L, ud, tname)

static void *testudata (lua_State *L, int ud, const char *tname) {
  void *p = lua_touserdata(L, ud);
  if (p != NULL) {  /* value is a userdata? */
    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */
      luaL_getmetatable(L, tname);  /* get correct metatable */
      if (!lua_rawequal(L, -1, -2))  /* not the same? */
        p = NULL;  /* value is a userdata with wrong metatable */
      lua_pop(L, 2);  /* remove both metatables */
      return p;
    }
  }
  return NULL;  /* value is not a userdata with a metatable */
}

#endif

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

the easy way is use luaL_testudata, but there is no such function in Lua 5.1.

It should be re-implemented (or imported from 5.2 or 5.3).

Ah, I didn't realise it was new in 5.2/5.3.

Your implementation looks fine, alternatively you could copy the implementation from: https://github.com/keplerproject/lua-compat-5.3/blob/master/c-api/compat-5.3.c#L219

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

@brunoos do you need anything from me for this one?

from luasec.

daurnimator avatar daurnimator commented on July 24, 2024

Added in 96401bd

awesome!

from luasec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.