Change module command parameter types

This commit introduces safe session references that can be handled without
holding locks. This allows the safe searching of sessions with the unique
ID of the session.

Remove the use of raw pointers passed as strings. Change the comments of
the argument types and add more details to the parsing function
documentation.
This commit is contained in:
Markus Makela
2016-11-30 19:32:12 +02:00
parent 994299b4f1
commit adbd666991
5 changed files with 90 additions and 47 deletions

View File

@ -277,25 +277,15 @@ static bool process_argument(modulecmd_arg_type_t *type, const void* value,
break;
case MODULECMD_ARG_SESSION:
arg->type.type = MODULECMD_ARG_SESSION;
arg->value.session = (SESSION*)strtol((char*)value, NULL, 0);
rval = true;
break;
case MODULECMD_ARG_SESSION_PTR:
arg->type.type = MODULECMD_ARG_SESSION_PTR;
arg->value.session = (SESSION*)value;
if ((arg->value.session = session_get_ref(atoi(value))))
{
arg->type.type = MODULECMD_ARG_SESSION;
}
rval = true;
break;
case MODULECMD_ARG_DCB:
arg->type.type = MODULECMD_ARG_DCB;
arg->value.dcb = (DCB*)strtol((char*)value, NULL, 0);
rval = true;
break;
case MODULECMD_ARG_DCB_PTR:
arg->type.type = MODULECMD_ARG_DCB_PTR;
arg->value.dcb = (DCB*)value;
rval = true;
break;
@ -373,6 +363,10 @@ static void free_argument(struct arg_node *arg)
MXS_FREE(arg->value.string);
break;
case MODULECMD_ARG_SESSION:
session_put_ref(arg->value.session);
break;
default:
break;
}
@ -625,18 +619,10 @@ char* modulecmd_argtype_to_str(modulecmd_arg_type_t *type)
strtype = "SESSION";
break;
case MODULECMD_ARG_SESSION_PTR:
strtype = "SESSION_PTR";
break;
case MODULECMD_ARG_DCB:
strtype = "DCB";
break;
case MODULECMD_ARG_DCB_PTR:
strtype = "DCB_PTR";
break;
case MODULECMD_ARG_MONITOR:
strtype = "MONITOR";
break;