Exemplo n.º 1
0
STDMETHODIMP PyGDocHostUIHandler::GetHostInfo(
		/* [out][in] */ DOCHOSTUIINFO * pInfo)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetHostInfo", &result, "");
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	PyObject *obhostcss, *obhostns;
	if (!PyArg_ParseTuple(result, "iiOO", &pInfo->dwFlags, &pInfo->dwDoubleClick, &obhostcss, &obhostns) ||
	    !PyWinObject_AsTaskAllocatedWCHAR(obhostcss, &pInfo->pchHostCss, TRUE, NULL) ||
	    !PyWinObject_AsTaskAllocatedWCHAR(obhostns, &pInfo->pchHostNS, TRUE, NULL))
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetHostInfo");
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 2
0
//////////////////////////////////////////////////////////////
//
// BINDINFO support
//
BOOL PyObject_AsBINDINFO(PyObject *ob, BINDINFO *pPD)
{
	BOOL ok = FALSE;
	memset(pPD, 0, sizeof(BINDINFO));
	pPD->cbSize = sizeof(BINDINFO);
	PyObject *obExtra = Py_None;
	PyObject *obSTGM = Py_None;
	PyObject *obCustomVerb = Py_None;
	PyObject *obSA = Py_None;
	PyObject *obIID = Py_None;
	PyObject *obUnk = Py_None;
	if (!PyArg_ParseTuple(ob, "|OOllOlllOOOl",
		&obExtra,
		&obSTGM,
		&pPD->grfBindInfoF,
		&pPD->dwBindVerb,
		&obCustomVerb,
		&pPD->dwOptions,
		&pPD->dwOptionsFlags,
		&pPD->dwCodePage,
		&obSA,
		&obIID,
		&obUnk,
		&pPD->dwReserved))
		goto done;
	if (!PyWinObject_AsTaskAllocatedWCHAR(obExtra, &pPD->szExtraInfo, /*bNoneOK=*/TRUE, NULL))
		goto done;
	if (obSTGM != Py_None) {
		PyErr_SetString(PyExc_TypeError, "Sorry - dont support STGMEDIUM yet - must be None");
		goto done;
	}
	if (!PyWinObject_AsTaskAllocatedWCHAR(obCustomVerb, &pPD->szCustomVerb, /*bNoneOK=*/TRUE, NULL))
		goto done;
	SECURITY_ATTRIBUTES *pSA;
	if (!PyWinObject_AsSECURITY_ATTRIBUTES(obSA, &pSA, TRUE))
		goto done;
	pPD->securityAttributes = *pSA;
	if (obIID != Py_None && !PyWinObject_AsIID(obIID, &pPD->iid))
		goto done;
	if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, pPD->iid, (void **)&pPD->pUnk, TRUE))
		goto done;

	ok = TRUE;
done:
	// todo: cleanup if !ok
	return ok;
}
Exemplo n.º 3
0
STDMETHODIMP PyGDocHostUIHandler::GetOptionKeyPath(
		/* [out] */ LPOLESTR * pchKey,
		/* [in] */ DWORD dw)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetOptionKeyPath", &result, "l", dw);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	if (!PyWinObject_AsTaskAllocatedWCHAR(result, pchKey, FALSE, NULL))
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetOptionKeyPath");
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 4
0
// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGEnumSTATPROPSTG::Next( 
            /* [in] */ ULONG celt,
            /* [length_is][size_is][out] */ STATPROPSTG __RPC_FAR *rgVar,
            /* [out] */ ULONG __RPC_FAR *pCeltFetched)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr = InvokeViaPolicy("Next", &result, "i", celt);
	if ( FAILED(hr) )
		return hr;

	if ( !PySequence_Check(result) )
		goto error;
	int len;
	len = PyObject_Length(result);
	if ( len == -1 )
		goto error;
	if ( len > (int)celt)
		len = celt;

	if ( pCeltFetched )
		*pCeltFetched = len;

	int i;
	PyObject *obname;
	for ( i = 0; i < len; ++i )
	{
		TmpPyObject ob = PySequence_GetItem(result, i);
		if ( ob == NULL )
			goto error;

		if (!PyArg_ParseTuple(ob, "OkH", &obname, &rgVar[i].propid, &rgVar[i].vt)
			||!PyWinObject_AsTaskAllocatedWCHAR(obname, &rgVar[i].lpwstrName, TRUE))
		{
			Py_DECREF(result);
			for (; i--; )
				CoTaskMemFree(rgVar[i].lpwstrName);
			return PyCom_SetCOMErrorFromPyException(IID_IEnumSTATPROPSTG);
		}
	}

	Py_DECREF(result);

	return len < (int)celt ? S_FALSE : S_OK;

  error:
	PyErr_Clear();	// just in case
	Py_DECREF(result);
	return PyCom_SetCOMErrorFromSimple(E_FAIL, IID_IEnumSTATPROPSTG, "Next() did not return a sequence of objects");
}
Exemplo n.º 5
0
STDMETHODIMP PyGShellItem::GetDisplayName(
		/* [in] */ SIGDN sigdnName,
		/* [string][out] */ LPWSTR * ppszName)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetDisplayName", &result, "k", sigdnName);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	if (!PyWinObject_AsTaskAllocatedWCHAR(result, ppszName))
		hr = PyCom_SetAndLogCOMErrorFromPyException("GetDisplayName", IID_IShellItem);
	Py_DECREF(result);
	return hr;

}
Exemplo n.º 6
0
STDMETHODIMP PyGPersistFile::GetCurFile(
		/* [out] */ LPOLESTR __RPC_FAR * ppszFileName)
{
	PY_GATEWAY_METHOD;
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetCurFile", &result);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	PyObject *obppszFileName;
	if (!PyArg_Parse(result, "O" , &obppszFileName))
		hr = PyCom_HandlePythonFailureToCOM(/*pexcepinfo*/);
	else if (!PyWinObject_AsTaskAllocatedWCHAR(obppszFileName, ppszFileName))
		hr = PyCom_HandlePythonFailureToCOM(/*pexcepinfo*/);
	Py_DECREF(result);
	return hr;
}
STDMETHODIMP PyGShellItemResources::GetResourceDescription(
		/* [in] */ const SHELL_ITEM_RESOURCE * pcsir,
		/* [out] */ LPWSTR * ppszDescription)
{
	PY_GATEWAY_METHOD;
	PyObject *obpcsir = PyWinObject_FromSHELL_ITEM_RESOURCE(pcsir);
	if (obpcsir==NULL) return MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetResourceDescription");
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetResourceDescription", &result, "O", obpcsir);
	Py_DECREF(obpcsir);
	if (FAILED(hr)) return hr;
	// ??? Docs do not specify memory semantics, but this seems to work ... ???
	if (!PyWinObject_AsTaskAllocatedWCHAR(result, ppszDescription, FALSE))
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetResourceDescription");
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 8
0
STDMETHODIMP PyGDocHostUIHandler::TranslateUrl(
		/* [in] */ DWORD dwTranslate,
		/* [in] */ OLECHAR * pchURLIn,
		/* [out] */ OLECHAR ** ppchURLOut)
{
	PY_GATEWAY_METHOD;
	if (ppchURLOut==NULL) return E_POINTER;
	PyObject *obpchURLIn;
	obpchURLIn = MakeOLECHARToObj(pchURLIn);
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("TranslateUrl", &result, "lO", dwTranslate, obpchURLIn);
	Py_XDECREF(obpchURLIn);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	if (!PyWinObject_AsTaskAllocatedWCHAR(result, ppchURLOut, FALSE, NULL))
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("TranslateUrl");
	Py_DECREF(result);
	return hr;
}
STDMETHODIMP PyGTransferSource::GetDefaultDestinationName(
		/* [in] */ IShellItem * psiSource,
		/* [in] */ IShellItem * psiParentDest,
		/* [out] */ LPWSTR * ppszDestinationName)
{
	PY_GATEWAY_METHOD;
	PyObject *obpsiSource;
	PyObject *obpsiParentDest;
	obpsiSource = PyCom_PyObjectFromIUnknown(psiSource, IID_IShellItem, FALSE);
	obpsiParentDest = PyCom_PyObjectFromIUnknown(psiParentDest, IID_IShellItem, FALSE);
	PyObject *result;
	HRESULT hr=InvokeViaPolicy("GetDefaultDestinationName", &result, "OO", obpsiSource, obpsiParentDest);
	Py_XDECREF(obpsiSource);
	Py_XDECREF(obpsiParentDest);
	if (FAILED(hr)) return hr;
	// Process the Python results, and convert back to the real params
	if (!PyWinObject_AsTaskAllocatedWCHAR(result, ppszDestinationName))
		hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("GetDefaultDestinationName");
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 10
0
// ---------------------------------------------------
//
// Gateway Implementation
STDMETHODIMP PyGServerSecurity::QueryBlanket(
		/* [out] */ DWORD * pAuthnSvc,
		/* [out] */ DWORD * pAuthzSvc,
		/* [out] */ OLECHAR ** pServerPrincName,
		/* [out] */ DWORD * pAuthnLevel,
		/* [out] */ DWORD * pImpLevel,
		/* [out] */ void ** pPrivs, // not handled yet, may be a variety of different structs
		/* [out][in] */ DWORD * pCapabilities)
{
	// ??? All parameters may be NULL if the caller does not want them.  How should this be communicated
	//	to the python server method ???
	DWORD AuthnSvc, AuthzSvc, AuthnLevel, ImpLevel, Capabilities = 0;
	PY_GATEWAY_METHOD;
	PyObject *result;
	if (pCapabilities)
		Capabilities = *pCapabilities;
	HRESULT hr=InvokeViaPolicy("QueryBlanket", &result, "k", Capabilities);
	if (FAILED(hr)) return hr;

	PyObject *obpServerPrincName;
	if (!PyArg_ParseTuple(result, "kkOkkk" , &AuthnSvc, &AuthzSvc, &obpServerPrincName, &AuthnLevel, &ImpLevel, &Capabilities))
		return MAKE_PYCOM_GATEWAY_FAILURE_CODE("QueryBlanket");
	if (pServerPrincName)
		if (!PyWinObject_AsTaskAllocatedWCHAR(obpServerPrincName, pServerPrincName))
			hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("QueryBlanket");
	if (pAuthnSvc)
		*pAuthnSvc = AuthnSvc;
	if (pAuthzSvc)
		*pAuthzSvc = AuthzSvc;
	if (pAuthnLevel)
		*pAuthnLevel = AuthnLevel;
	if (pImpLevel)
		*pImpLevel = ImpLevel;
	if (pCapabilities)
		*pCapabilities = Capabilities;
	// pPriv may be SEC_WINNT_AUTH_IDENTITY, SEC_WINNT_AUTH_IDENTITY_EX, or CERT_CONTEXT
	// SEC_WINNT_AUTH_IDENTITY is in win32security.i, CERT_CONTEXT in cryptoapi\PyCERT_CONTEXT.cpp
	Py_DECREF(result);
	return hr;
}
Exemplo n.º 11
0
BOOL PyWinObject_AsKNOWNFOLDER_DEFINITION(PyObject *obdef, KNOWNFOLDER_DEFINITION& def)
{
	static char *keywords[] = {"Category", "Name", "Description", "Parent",
		"RelativePath", "ParsingName", "Tooltip", "LocalizedName", "Icon",
		"Security", "Attributes", "Flags", "Type", NULL};
	ZeroMemory(&def, sizeof(def));
	if (!PyDict_Check(obdef)){
		PyErr_SetString(PyExc_TypeError, "KNOWNFOLDER_DEFINITION requires a dict");
		return FALSE;
		}
	TmpPyObject obdummy = PyTuple_New(0);
	if (obdummy == NULL)
		return FALSE;
	PyObject *obName, *obDescription, *obRelativePath,
		*obParsingName, *obTooltip, *obLocalizedName, *obIcon, *obSecurity;
	if (!PyArg_ParseTupleAndKeywords(obdummy, obdef, "iOOO&OOOOOOkiO&", keywords,
		&def.category,
		&obName,
		&obDescription,
		PyWinObject_AsIID, &def.fidParent,
		&obRelativePath, &obParsingName, &obTooltip,
		&obLocalizedName, &obIcon, &obSecurity,
		&def.dwAttributes, &def.kfdFlags,
		PyWinObject_AsIID, &def.ftidType))
		return FALSE;
	BOOL ret = PyWinObject_AsTaskAllocatedWCHAR(obName, &def.pszName, FALSE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obDescription, &def.pszDescription, FALSE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obRelativePath, &def.pszRelativePath, TRUE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obParsingName, &def.pszParsingName, TRUE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obTooltip, &def.pszTooltip, TRUE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obLocalizedName, &def.pszLocalizedName, TRUE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obIcon, &def.pszIcon, TRUE)
			&& PyWinObject_AsTaskAllocatedWCHAR(obSecurity, &def.pszSecurity, TRUE);
	if (!ret)
		FreeKnownFolderDefinitionFields(&def);
	return ret;
}
Exemplo n.º 12
0
// Converts a sequence of strings into a caller-allocated array of WCHAR pointers,
// each of which is allocated using CoTaskMemAlloc
BOOL PyWinObject_AsTaskAllocatedWCHARArray(PyObject *str_seq, LPWSTR *wchars, ULONG str_cnt)
{
	TmpPyObject str_tuple;
	ULONG seq_size, tuple_index;
	ZeroMemory(wchars, str_cnt * sizeof(WCHAR *));
	if ((str_tuple=PyWinSequence_Tuple(str_seq, &seq_size))==NULL)
		return FALSE;
	if (seq_size != str_cnt){
		PyErr_SetString(PyExc_ValueError, "Sequence not of required length");
		return FALSE;
		}
	for (tuple_index=0; tuple_index<str_cnt; tuple_index++){
		PyObject *tuple_item=PyTuple_GET_ITEM((PyObject *)str_tuple, tuple_index);
		if (!PyWinObject_AsTaskAllocatedWCHAR(tuple_item, &wchars[tuple_index], FALSE)){
			for (tuple_index=0; tuple_index<str_cnt; tuple_index++)
				if (wchars[tuple_index])
					CoTaskMemFree(wchars[tuple_index]);
			return FALSE;
			}
		}
	return TRUE;
}
Exemplo n.º 13
0
// @pymethod |PySTGMEDIUM|set|Sets the type and data of the object.
PyObject *PySet(PyObject *self, PyObject *args)
{
	int tymed;
	PyObject *ob;
	// @pyparm int|tymed||The type of the data
	// @pyparm object|data||
	if (!PyArg_ParseTuple(args, "iO:set", &tymed, &ob))
		return NULL;

	PySTGMEDIUM *ps = (PySTGMEDIUM *)self;
	ps->Close(); // ensure any old data clean
	switch (tymed) {
		case TYMED_GDI:{
			HBITMAP htmp;
			if (!PyWinObject_AsHANDLE(ob, (HANDLE *)&htmp))
				return NULL;
			ps->medium.hBitmap = htmp;
			break;
			}
		case TYMED_MFPICT:{
			HMETAFILEPICT htmp;
			if (!PyWinObject_AsHANDLE(ob, (HANDLE *)&htmp))
				return NULL;
			ps->medium.hMetaFilePict = htmp;
			break;
			}
		case TYMED_ENHMF:{
			HENHMETAFILE htmp;
			if (!PyWinObject_AsHANDLE(ob, (HANDLE *)&htmp))
				return NULL;
			ps->medium.hEnhMetaFile = htmp;
			break;
			}
		case TYMED_HGLOBAL: {
			const void * buf = NULL;
			Py_ssize_t cb = 0;
			// In py3k, unicode objects don't support the buffer
			// protocol, so explicitly check string types first.
			// We need to include the NULL for strings and unicode, as the
			// Windows clipboard functions will assume it is there for
			// text related formats (eg, CF_TEXT).
			if (PyString_Check(ob)) {
				cb = PyString_GET_SIZE(ob) + 1; // for the NULL
				buf = (void *)PyString_AS_STRING(ob);
			} else if (PyUnicode_Check(ob)) {
				cb = PyUnicode_GET_DATA_SIZE(ob) + sizeof(Py_UNICODE);
				buf = (void *)PyUnicode_AS_UNICODE(ob);
			} else {
				if (PyObject_AsReadBuffer(ob,&buf,&cb)==-1) 
					return PyErr_Format(PyExc_TypeError, "tymed value of %d requires a string/unicode/buffer", tymed);
				// no extra nulls etc needed here.
			}
			ps->medium.hGlobal = GlobalAlloc(GMEM_FIXED, cb);
			if (!ps->medium.hGlobal)
				return PyErr_NoMemory();
			memcpy( (void *)ps->medium.hGlobal, buf, cb);
			break;
		}
		case TYMED_FILE: 
			if (!PyWinObject_AsTaskAllocatedWCHAR(ob, &ps->medium.lpszFileName, FALSE, NULL))
				return FALSE;
			break;
		case TYMED_ISTREAM:
			if (!PyCom_InterfaceFromPyInstanceOrObject(ob, IID_IStream, (void **)&ps->medium.pstm, FALSE/* bNoneOK */))
				return FALSE;
			break;
		case TYMED_ISTORAGE:
			if (!PyCom_InterfaceFromPyInstanceOrObject(ob, IID_IStorage, (void **)&ps->medium.pstg, FALSE/* bNoneOK */))
				return FALSE;
			break;
		default:
			PyErr_Format(PyExc_ValueError, "Unknown tymed value '%d'", tymed);
			return NULL;
	}
	ps->medium.tymed = tymed;
	Py_INCREF(Py_None);
	return Py_None;
}