core/smn_keyvalues.cpp
changeset 1401 e3b761515c0a
parent 1330 ab94316bb52b
child 1707 05af94444cc8
child 1715 f9ecab642e25
     1.1 --- a/core/smn_keyvalues.cpp	Sun Sep 09 02:29:46 2007 +0000
     1.2 +++ b/core/smn_keyvalues.cpp	Mon Sep 10 18:03:06 2007 +0000
     1.3 @@ -831,6 +831,96 @@
     1.4  	return 1;
     1.5  }
     1.6  
     1.7 +static cell_t smn_CopySubkeys(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	Handle_t hndl_copied = static_cast<Handle_t>(params[1]);
    1.10 +	Handle_t hndl_parent = static_cast<Handle_t>(params[2]);
    1.11 +	HandleError herr;
    1.12 +	HandleSecurity sec;
    1.13 +	KeyValueStack *pStk_copied, *pStk_parent;
    1.14 +
    1.15 +	sec.pOwner = NULL;
    1.16 +	sec.pIdentity = g_pCoreIdent;
    1.17 +
    1.18 +	if ((herr=g_HandleSys.ReadHandle(hndl_copied, g_KeyValueType, &sec, (void **)&pStk_copied))
    1.19 +		!= HandleError_None)
    1.20 +	{
    1.21 +		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_copied, herr);
    1.22 +	}
    1.23 +	if ((herr=g_HandleSys.ReadHandle(hndl_parent, g_KeyValueType, &sec, (void **)&pStk_parent))
    1.24 +		!= HandleError_None)
    1.25 +	{
    1.26 +		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl_parent, herr);
    1.27 +	}
    1.28 +
    1.29 +	pStk_copied->pCurRoot.front()->CopySubkeys(pStk_parent->pCurRoot.front());
    1.30 +
    1.31 +	return 1;
    1.32 +}
    1.33 +
    1.34 +static cell_t smn_GetNameSymbol(IPluginContext *pContext, const cell_t *params)
    1.35 +{
    1.36 +	Handle_t hndl = static_cast<Handle_t>(params[1]);
    1.37 +	HandleError herr;
    1.38 +	HandleSecurity sec;
    1.39 +	KeyValueStack *pStk;
    1.40 +	cell_t *val;
    1.41 +	char *key;
    1.42 +
    1.43 +	sec.pOwner = NULL;
    1.44 +	sec.pIdentity = g_pCoreIdent;
    1.45 +
    1.46 +	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
    1.47 +		!= HandleError_None)
    1.48 +	{
    1.49 +		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
    1.50 +	}
    1.51 +
    1.52 +	if (pStk->pCurRoot.size() < 2)
    1.53 +	{
    1.54 +		return 0;
    1.55 +	}
    1.56 +
    1.57 +	pContext->LocalToString(params[2], &key);
    1.58 +
    1.59 +	KeyValues *pKv = pStk->pCurRoot.front()->FindKey(key);
    1.60 +	if (!pKv)
    1.61 +	{
    1.62 +		return 0;
    1.63 +	}
    1.64 +	pContext->LocalToPhysAddr(params[3], &val);
    1.65 +	*val = pKv->GetNameSymbol();
    1.66 +
    1.67 +	return 1;
    1.68 +}
    1.69 +
    1.70 +static cell_t smn_FindKeyById(IPluginContext *pContext, const cell_t *params)
    1.71 +{
    1.72 +	Handle_t hndl = static_cast<Handle_t>(params[1]);
    1.73 +	HandleError herr;
    1.74 +	HandleSecurity sec;
    1.75 +	KeyValueStack *pStk;
    1.76 +
    1.77 +	sec.pOwner = NULL;
    1.78 +	sec.pIdentity = g_pCoreIdent;
    1.79 +
    1.80 +	if ((herr=g_HandleSys.ReadHandle(hndl, g_KeyValueType, &sec, (void **)&pStk))
    1.81 +		!= HandleError_None)
    1.82 +	{
    1.83 +		return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
    1.84 +	}
    1.85 +
    1.86 +	KeyValues *pKv = pStk->pCurRoot.front()->FindKey(params[2]);
    1.87 +	if (!pKv)
    1.88 +	{
    1.89 +		return 0;
    1.90 +	}
    1.91 +
    1.92 +	pContext->StringToLocalUTF8(params[3], params[4], pKv->GetName(), NULL);
    1.93 +
    1.94 +	return 1;
    1.95 +}
    1.96 +
    1.97  static KeyValueNatives s_KeyValueNatives;
    1.98  
    1.99  REGISTER_NATIVES(keyvaluenatives)
   1.100 @@ -863,5 +953,8 @@
   1.101  	{"KvDeleteKey",				smn_KvDeleteKey},
   1.102  	{"KvNodesInStack",			smn_KvNodesInStack},
   1.103  	{"KvSavePosition",			smn_KvSavePosition},
   1.104 +	{"KvCopySubkeys",			smn_CopySubkeys},
   1.105 +	{"KvFindKeyById",			smn_FindKeyById},
   1.106 +	{"KvGetNameSymbol",			smn_GetNameSymbol},
   1.107  	{NULL,						NULL}
   1.108  };