BOOL PyObject_AsVARDESC(PyObject *ob, VARDESC *v, void *pMore) { if (ob->ob_type != &PyVARDESC::Type) { PyErr_SetString(PyExc_TypeError, "Object is not a VARDESC."); return FALSE; } PyVARDESC *pyv = (PyVARDESC *)ob; v->memid = pyv->memid; v->wVarFlags = pyv->wVarFlags; v->varkind = (VARKIND)pyv->varkind; if (!PyObject_AsELEMDESC(pyv->elemdescVar, &v->elemdescVar, pMore)) return FALSE; if (v->varkind == VAR_PERINSTANCE) { if (!PyInt_Check(pyv->value)) { PyErr_SetString(PyExc_TypeError, "If varkind==VAR_PERINSTANCE, value attribute must be an integer"); return FALSE; } v->oInst = PyInt_AsLong(pyv->value); } else if (v->varkind == VAR_CONST) { VARIANT *pVar = (VARIANT *)AllocMore(pMore, sizeof(VARIANT), TRUE); if (pVar==NULL) return NULL; VariantInit(pVar); if (!PyCom_VariantFromPyObject(pyv->value, pVar)) return NULL; v->lpvarValue = pVar; } else if (v->varkind == VAR_DISPATCH) { // nothing to do - memid is all that is needed by the caller. ; } else { PyCom_LoggerWarning(NULL, "PyObject_AsVARDESC has unknown varkind (%d) - None will be used", v->varkind); } // else ignore value. return TRUE; }
PyVARDESC::PyVARDESC(const VARDESC *pVD) { ob_type = &PyVARDESC::Type; _Py_NewReference(this); memid = pVD->memid; wVarFlags = pVD->wVarFlags; varkind = pVD->varkind; if (varkind == VAR_PERINSTANCE) value = PyInt_FromLong(pVD->oInst); else if (varkind == VAR_CONST) { VARIANT varValue; // Cast the variant type here to the correct value for this constant // so that the correct Python type will be created below. // The problem seems to exist for unsigned types (the variant has // a signed type, but the typelib has an unsigned one). However, // doing this unconditionally has side-effects, as the typelib // has VT_LPWSTR for the type of strings - and VariantChangeType // returns a VT_EMPTY variant in that case. // So we only perform this conversion for types known to be a problem: switch (pVD->elemdescVar.tdesc.vt) { case VT_UI1: case VT_UI2: case VT_UI4: case VT_UI8: case VT_UINT: case VT_UINT_PTR: VariantInit(&varValue); VariantChangeType(&varValue, pVD->lpvarValue, 0, pVD->elemdescVar.tdesc.vt); value = PyCom_PyObjectFromVariant(&varValue); VariantClear(&varValue); break; default: value = PyCom_PyObjectFromVariant(pVD->lpvarValue); break; } } else if (varkind == VAR_DISPATCH) { // all caller needs is memid, which is already setup. value = Py_None; Py_INCREF(Py_None); } else { PyCom_LoggerWarning(NULL, "PyVARDESC ctor has unknown varkind (%d) - returning None", varkind); value = Py_None; Py_INCREF(Py_None); } elemdescVar = PyObject_FromELEMDESC(&pVD->elemdescVar); }
STDMETHODIMP PyGInternetSecurityManager::ProcessUrlAction( /* [in] */ LPCWSTR pwszUrl, /* [in] */ DWORD dwAction, /* [size_is][out] */ BYTE * pPolicy, /* [in] */ DWORD cbPolicy, /* [in] */ BYTE * pContext, /* [in] */ DWORD cbContext, /* [in] */ DWORD dwFlags, /* [in] */ DWORD dwReserved) { PY_GATEWAY_METHOD; PyObject *obpwszUrl; PyObject *obContext; obpwszUrl = MakeOLECHARToObj(pwszUrl); // pContext is documented as being a GUID - but markh has seen IE // call this with 78 and 54 bytes in some unusual cases. So // just use 'bytes' and the Python code must use magic to get a GUID. if (pContext==NULL) { obContext = Py_None; Py_INCREF(Py_None); } else obContext = PyString_FromStringAndSize((char *)pContext, cbContext); PyObject *result; HRESULT hr=InvokeViaPolicy("ProcessUrlAction", &result, "OlOll", obpwszUrl, dwAction, obContext, dwFlags, dwReserved); Py_XDECREF(obpwszUrl); Py_XDECREF(obContext); if (FAILED(hr)) return hr; // Process the Python results, and convert back to the real params if (cbPolicy==sizeof(DWORD)) { *((DWORD *)pPolicy) = PyInt_AsLong(result); if (*((DWORD *)pPolicy)==-1) hr = MAKE_PYCOM_GATEWAY_FAILURE_CODE("ProcessUrlAction"); } else { PyCom_LoggerWarning(NULL, "PyGInternetSecurityManager::ProcessUrlAction has %d bytes for policy - what is that?", cbPolicy); hr = E_UNEXPECTED; } return hr; }
// @doc - This file contains autoduck documentation // --------------------------------------------------- // PyObject *PyObject_FromNOTIFICATION(NOTIFICATION *n) { PyObject *ret = NULL; switch (n->ulEventType) { case fnevCriticalError: { ERROR_NOTIFICATION &err = n->info.err; ret = Py_BuildValue("k(s#iiN)", n->ulEventType, err.lpEntryID, err.cbEntryID, err.scode, err.ulFlags, PyObject_FromMAPIERROR(err.lpMAPIError, err.ulFlags&MAPI_UNICODE, FALSE)); break; } case fnevExtended: { EXTENDED_NOTIFICATION &ext = n->info.ext; ret = Py_BuildValue("k(ks#)", n->ulEventType, ext.ulEvent, ext.pbEventParameters, ext.cb); break; } case fnevNewMail: { NEWMAIL_NOTIFICATION &newmail = n->info.newmail; PyObject *msg_class = newmail.ulFlags&MAPI_UNICODE? PyWinObject_FromWCHAR((const WCHAR *)newmail.lpszMessageClass) : PyString_FromString((const char *)newmail.lpszMessageClass); if (!msg_class) return NULL; ret = Py_BuildValue("k(s#s#kNk)", n->ulEventType, newmail.lpEntryID, newmail.cbEntryID, newmail.lpParentID, newmail.cbParentID, newmail.ulFlags, msg_class, newmail.ulMessageFlags); break; } case fnevObjectCopied: case fnevObjectCreated: case fnevObjectDeleted: case fnevObjectModified: case fnevObjectMoved: case fnevSearchComplete: { OBJECT_NOTIFICATION &obj = n->info.obj; PyObject *obArray = PyMAPIObject_FromSPropTagArray(obj.lpPropTagArray); if (!obArray) return NULL; ret = Py_BuildValue("k(s#is#s#s#N)", n->ulEventType, obj.lpEntryID, obj.cbEntryID, obj.ulObjType, obj.lpParentID, obj.cbParentID, obj.lpOldID, obj.cbOldID, obj.lpOldParentID, obj.cbOldParentID, obArray); break; } case fnevTableModified: { TABLE_NOTIFICATION &tab = n->info.tab; ret = Py_BuildValue("k(kiNNN)", n->ulEventType, tab.ulTableEvent, tab.hResult, PyMAPIObject_FromSPropValue(&tab.propIndex), PyMAPIObject_FromSPropValue(&tab.propPrior), PyMAPIObject_FromSRow(&tab.row)); break; } case fnevStatusObjectModified: { STATUS_OBJECT_NOTIFICATION &statobj = n->info.statobj; ret = Py_BuildValue("k(s#N)", n->ulEventType, statobj.lpEntryID, statobj.cbEntryID, PyMAPIObject_FromSPropValueArray(statobj.lpPropVals, statobj.cValues)); break; } default: { PyCom_LoggerWarning(NULL, "unknown MAPI notification type %x", n->ulEventType); ret = Py_BuildValue("k(O)", n->ulEventType, Py_None); break; } } return ret; }