ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

umon.c
Go to the documentation of this file.
00001 /*
00002  * UrlMon
00003  *
00004  * Copyright 1999 Ulrich Czekalla for Corel Corporation
00005  * Copyright 2002 Huw D M Davies for CodeWeavers
00006  * Copyright 2005 Jacek Caban for CodeWeavers
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00021  */
00022 
00023 #include "urlmon_main.h"
00024 
00025 #include "winreg.h"
00026 #include "shlwapi.h"
00027 #include "hlink.h"
00028 #include "shellapi.h"
00029 
00030 #include "wine/debug.h"
00031 
00032 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
00033 
00034 typedef struct {
00035     IMoniker      IMoniker_iface;
00036     IUriContainer IUriContainer_iface;
00037 
00038     LONG ref;
00039 
00040     LPOLESTR URLName; /* URL string identified by this URLmoniker */
00041 } URLMoniker;
00042 
00043 static inline URLMoniker *impl_from_IMoniker(IMoniker *iface)
00044 {
00045     return CONTAINING_RECORD(iface, URLMoniker, IMoniker_iface);
00046 }
00047 
00048 static HRESULT WINAPI URLMoniker_QueryInterface(IMoniker *iface, REFIID riid, void **ppv)
00049 {
00050     URLMoniker *This = impl_from_IMoniker(iface);
00051 
00052     if(!ppv)
00053     return E_INVALIDARG;
00054 
00055     if(IsEqualIID(&IID_IUnknown, riid)) {
00056         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
00057         *ppv = iface;
00058     }else if(IsEqualIID(&IID_IPersist, riid)) {
00059         TRACE("(%p)->(IID_IPersist %p)\n", This, ppv);
00060         *ppv = iface;
00061     }else if(IsEqualIID(&IID_IPersistStream,riid)) {
00062         TRACE("(%p)->(IID_IPersistStream %p)\n", This, ppv);
00063         *ppv = iface;
00064     }else if(IsEqualIID(&IID_IMoniker, riid)) {
00065         TRACE("(%p)->(IID_IMoniker %p)\n", This, ppv);
00066         *ppv = iface;
00067     }else if(IsEqualIID(&IID_IAsyncMoniker, riid)) {
00068         TRACE("(%p)->(IID_IAsyncMoniker %p)\n", This, ppv);
00069         *ppv = iface;
00070     }else if(IsEqualIID(&IID_IUriContainer, riid)) {
00071         TRACE("(%p)->(IID_IUriContainer %p)\n", This, ppv);
00072         *ppv = &This->IUriContainer_iface;
00073     }else {
00074         WARN("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppv);
00075         *ppv = NULL;
00076         return E_NOINTERFACE;
00077     }
00078 
00079     IMoniker_AddRef((IUnknown*)*ppv);
00080     return S_OK;
00081 }
00082 
00083 static ULONG WINAPI URLMoniker_AddRef(IMoniker *iface)
00084 {
00085     URLMoniker *This = impl_from_IMoniker(iface);
00086     ULONG refCount = InterlockedIncrement(&This->ref);
00087 
00088     TRACE("(%p) ref=%u\n",This, refCount);
00089 
00090     return refCount;
00091 }
00092 
00093 static ULONG WINAPI URLMoniker_Release(IMoniker *iface)
00094 {
00095     URLMoniker *This = impl_from_IMoniker(iface);
00096     ULONG refCount = InterlockedDecrement(&This->ref);
00097 
00098     TRACE("(%p) ref=%u\n",This, refCount);
00099 
00100     if (!refCount) {
00101         heap_free(This->URLName);
00102         heap_free(This);
00103 
00104         URLMON_UnlockModule();
00105     }
00106 
00107     return refCount;
00108 }
00109 
00110 static HRESULT WINAPI URLMoniker_GetClassID(IMoniker *iface, CLSID *pClassID)
00111 {
00112     URLMoniker *This = impl_from_IMoniker(iface);
00113 
00114     TRACE("(%p,%p)\n", This, pClassID);
00115 
00116     if(!pClassID)
00117         return E_POINTER;
00118 
00119     /* Windows always returns CLSID_StdURLMoniker */
00120     *pClassID = CLSID_StdURLMoniker;
00121     return S_OK;
00122 }
00123 
00124 static HRESULT WINAPI URLMoniker_IsDirty(IMoniker *iface)
00125 {
00126     URLMoniker *This = impl_from_IMoniker(iface);
00127 
00128     TRACE("(%p)\n",This);
00129 
00130     /* Note that the OLE-provided implementations of the IPersistStream::IsDirty
00131        method in the OLE-provided moniker interfaces always return S_FALSE because
00132        their internal state never changes. */
00133     return S_FALSE;
00134 }
00135 
00136 static HRESULT WINAPI URLMoniker_Load(IMoniker* iface,IStream* pStm)
00137 {
00138     URLMoniker *This = impl_from_IMoniker(iface);
00139     HRESULT res;
00140     ULONG size;
00141     ULONG got;
00142 
00143     TRACE("(%p,%p)\n",This,pStm);
00144 
00145     if(!pStm)
00146         return E_INVALIDARG;
00147 
00148     /*
00149      * NOTE
00150      *  Writes a ULONG containing length of unicode string, followed
00151      *  by that many unicode characters
00152      */
00153     res = IStream_Read(pStm, &size, sizeof(ULONG), &got);
00154     if(SUCCEEDED(res)) {
00155         if(got == sizeof(ULONG)) {
00156             heap_free(This->URLName);
00157             This->URLName = heap_alloc(size);
00158             if(!This->URLName)
00159                 res = E_OUTOFMEMORY;
00160             else {
00161                 res = IStream_Read(pStm, This->URLName, size, NULL);
00162                 This->URLName[size/sizeof(WCHAR) - 1] = 0;
00163             }
00164         }
00165         else
00166             res = E_FAIL;
00167     }
00168 
00169     return res;
00170 }
00171 
00172 static HRESULT WINAPI URLMoniker_Save(IMoniker *iface, IStream* pStm, BOOL fClearDirty)
00173 {
00174     URLMoniker *This = impl_from_IMoniker(iface);
00175     HRESULT res;
00176     ULONG size;
00177 
00178     TRACE("(%p,%p,%d)\n", This, pStm, fClearDirty);
00179 
00180     if(!pStm)
00181         return E_INVALIDARG;
00182 
00183     size = (strlenW(This->URLName) + 1)*sizeof(WCHAR);
00184     res=IStream_Write(pStm,&size,sizeof(ULONG),NULL);
00185     if(SUCCEEDED(res))
00186         res=IStream_Write(pStm,This->URLName,size,NULL);
00187 
00188     return res;
00189 
00190 }
00191 
00192 static HRESULT WINAPI URLMoniker_GetSizeMax(IMoniker* iface, ULARGE_INTEGER *pcbSize)
00193 {
00194     URLMoniker *This = impl_from_IMoniker(iface);
00195 
00196     TRACE("(%p,%p)\n",This,pcbSize);
00197 
00198     if(!pcbSize)
00199         return E_INVALIDARG;
00200 
00201     pcbSize->QuadPart = sizeof(ULONG) + ((strlenW(This->URLName)+1) * sizeof(WCHAR));
00202     return S_OK;
00203 }
00204 
00205 static HRESULT WINAPI URLMoniker_BindToObject(IMoniker *iface, IBindCtx* pbc, IMoniker *pmkToLeft,
00206         REFIID riid, void **ppv)
00207 {
00208     URLMoniker *This = impl_from_IMoniker(iface);
00209     IRunningObjectTable *obj_tbl;
00210     IUri *uri;
00211     HRESULT hres;
00212 
00213     TRACE("(%p)->(%p,%p,%s,%p): stub\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppv);
00214 
00215     hres = IBindCtx_GetRunningObjectTable(pbc, &obj_tbl);
00216     if(SUCCEEDED(hres)) {
00217         FIXME("use running object table\n");
00218         IRunningObjectTable_Release(obj_tbl);
00219     }
00220 
00221     hres = CreateUri(This->URLName, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
00222     if(FAILED(hres))
00223         return hres;
00224 
00225     hres = bind_to_object(iface, uri, pbc, riid, ppv);
00226 
00227     IUri_Release(uri);
00228     return hres;
00229 }
00230 
00231 static HRESULT WINAPI URLMoniker_BindToStorage(IMoniker* iface, IBindCtx* pbc,
00232         IMoniker* pmkToLeft, REFIID riid, void **ppvObject)
00233 {
00234     URLMoniker *This = impl_from_IMoniker(iface);
00235     IUri *uri;
00236     HRESULT hres;
00237 
00238     TRACE("(%p)->(%p %p %s %p)\n", This, pbc, pmkToLeft, debugstr_guid(riid), ppvObject);
00239 
00240     if(ppvObject) *ppvObject = NULL;
00241 
00242     if(!pbc || !ppvObject) return E_INVALIDARG;
00243 
00244     if(pmkToLeft)
00245         FIXME("Unsupported pmkToLeft\n");
00246 
00247     hres = CreateUri(This->URLName, Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
00248     if(FAILED(hres))
00249         return hres;
00250 
00251     hres = bind_to_storage(uri, pbc, riid, ppvObject);
00252 
00253     IUri_Release(uri);
00254     return hres;
00255 }
00256 
00257 static HRESULT WINAPI URLMoniker_Reduce(IMoniker *iface, IBindCtx *pbc,
00258         DWORD dwReduceHowFar, IMoniker **ppmkToLeft, IMoniker **ppmkReduced)
00259 {
00260     URLMoniker *This = impl_from_IMoniker(iface);
00261 
00262     TRACE("(%p,%p,%d,%p,%p)\n", This, pbc, dwReduceHowFar, ppmkToLeft, ppmkReduced);
00263 
00264     if(!ppmkReduced)
00265         return E_INVALIDARG;
00266 
00267     IMoniker_AddRef(iface);
00268     *ppmkReduced = iface;
00269     return MK_S_REDUCED_TO_SELF;
00270 }
00271 
00272 static HRESULT WINAPI URLMoniker_ComposeWith(IMoniker *iface, IMoniker *pmkRight,
00273         BOOL fOnlyIfNotGeneric, IMoniker **ppmkComposite)
00274 {
00275     URLMoniker *This = impl_from_IMoniker(iface);
00276     FIXME("(%p)->(%p,%d,%p): stub\n",This,pmkRight,fOnlyIfNotGeneric,ppmkComposite);
00277     return E_NOTIMPL;
00278 }
00279 
00280 static HRESULT WINAPI URLMoniker_Enum(IMoniker *iface, BOOL fForward, IEnumMoniker **ppenumMoniker)
00281 {
00282     URLMoniker *This = impl_from_IMoniker(iface);
00283 
00284     TRACE("(%p,%d,%p)\n", This, fForward, ppenumMoniker);
00285 
00286     if(!ppenumMoniker)
00287         return E_INVALIDARG;
00288 
00289     /* Does not support sub-monikers */
00290     *ppenumMoniker = NULL;
00291     return S_OK;
00292 }
00293 
00294 static HRESULT WINAPI URLMoniker_IsEqual(IMoniker *iface, IMoniker *pmkOtherMoniker)
00295 {
00296     URLMoniker *This = impl_from_IMoniker(iface);
00297     CLSID clsid;
00298     LPOLESTR urlPath;
00299     IBindCtx* bind;
00300     HRESULT res;
00301 
00302     TRACE("(%p,%p)\n",This, pmkOtherMoniker);
00303 
00304     if(pmkOtherMoniker==NULL)
00305         return E_INVALIDARG;
00306 
00307     IMoniker_GetClassID(pmkOtherMoniker,&clsid);
00308 
00309     if(!IsEqualCLSID(&clsid,&CLSID_StdURLMoniker))
00310         return S_FALSE;
00311 
00312     res = CreateBindCtx(0,&bind);
00313     if(FAILED(res))
00314         return res;
00315 
00316     res = S_FALSE;
00317     if(SUCCEEDED(IMoniker_GetDisplayName(pmkOtherMoniker,bind,NULL,&urlPath))) {
00318         int result = lstrcmpiW(urlPath, This->URLName);
00319         CoTaskMemFree(urlPath);
00320         if(result == 0)
00321             res = S_OK;
00322     }
00323     IUnknown_Release(bind);
00324     return res;
00325 }
00326 
00327 
00328 static HRESULT WINAPI URLMoniker_Hash(IMoniker *iface, DWORD *pdwHash)
00329 {
00330     URLMoniker *This = impl_from_IMoniker(iface);
00331     int  h = 0,i,skip,len;
00332     int  off = 0;
00333     LPOLESTR val;
00334 
00335     TRACE("(%p,%p)\n",This,pdwHash);
00336 
00337     if(!pdwHash)
00338         return E_INVALIDARG;
00339 
00340     val = This->URLName;
00341     len = lstrlenW(val);
00342 
00343     if(len < 16) {
00344         for(i = len ; i > 0; i--) {
00345             h = (h * 37) + val[off++];
00346         }
00347     }else {
00348         /* only sample some characters */
00349         skip = len / 8;
00350         for(i = len; i > 0; i -= skip, off += skip) {
00351             h = (h * 39) + val[off];
00352         }
00353     }
00354     *pdwHash = h;
00355     return S_OK;
00356 }
00357 
00358 static HRESULT WINAPI URLMoniker_IsRunning(IMoniker* iface, IBindCtx* pbc,
00359         IMoniker *pmkToLeft, IMoniker *pmkNewlyRunning)
00360 {
00361     URLMoniker *This = impl_from_IMoniker(iface);
00362     FIXME("(%p)->(%p,%p,%p): stub\n",This,pbc,pmkToLeft,pmkNewlyRunning);
00363     return E_NOTIMPL;
00364 }
00365 
00366 static HRESULT WINAPI URLMoniker_GetTimeOfLastChange(IMoniker *iface,
00367         IBindCtx *pbc, IMoniker *pmkToLeft, FILETIME *pFileTime)
00368 {
00369     URLMoniker *This = impl_from_IMoniker(iface);
00370     FIXME("(%p)->(%p,%p,%p): stub\n", This, pbc, pmkToLeft, pFileTime);
00371     return E_NOTIMPL;
00372 }
00373 
00374 static HRESULT WINAPI URLMoniker_Inverse(IMoniker *iface, IMoniker **ppmk)
00375 {
00376     URLMoniker *This = impl_from_IMoniker(iface);
00377     TRACE("(%p,%p)\n",This,ppmk);
00378     return MK_E_NOINVERSE;
00379 }
00380 
00381 static HRESULT WINAPI URLMoniker_CommonPrefixWith(IMoniker *iface, IMoniker *pmkOther, IMoniker **ppmkPrefix)
00382 {
00383     URLMoniker *This = impl_from_IMoniker(iface);
00384     FIXME("(%p)->(%p,%p): stub\n",This,pmkOther,ppmkPrefix);
00385     return E_NOTIMPL;
00386 }
00387 
00388 static HRESULT WINAPI URLMoniker_RelativePathTo(IMoniker *iface, IMoniker *pmOther, IMoniker **ppmkRelPath)
00389 {
00390     URLMoniker *This = impl_from_IMoniker(iface);
00391     FIXME("(%p)->(%p,%p): stub\n",This,pmOther,ppmkRelPath);
00392     return E_NOTIMPL;
00393 }
00394 
00395 static HRESULT WINAPI URLMoniker_GetDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
00396         LPOLESTR *ppszDisplayName)
00397 {
00398     URLMoniker *This = impl_from_IMoniker(iface);
00399     int len;
00400     
00401     TRACE("(%p,%p,%p,%p)\n", This, pbc, pmkToLeft, ppszDisplayName);
00402     
00403     if(!ppszDisplayName)
00404         return E_INVALIDARG;
00405 
00406     if(!This->URLName)
00407         return E_OUTOFMEMORY;
00408 
00409     /* FIXME: If this is a partial URL, try and get a URL moniker from SZ_URLCONTEXT in the bind context,
00410         then look at pmkToLeft to try and complete the URL
00411     */
00412     len = lstrlenW(This->URLName)+1;
00413     *ppszDisplayName = CoTaskMemAlloc(len*sizeof(WCHAR));
00414     if(!*ppszDisplayName)
00415         return E_OUTOFMEMORY;
00416     lstrcpyW(*ppszDisplayName, This->URLName);
00417     return S_OK;
00418 }
00419 
00420 static HRESULT WINAPI URLMoniker_ParseDisplayName(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
00421         LPOLESTR pszDisplayName, ULONG *pchEaten, IMoniker **ppmkOut)
00422 {
00423     URLMoniker *This = impl_from_IMoniker(iface);
00424     FIXME("(%p)->(%p,%p,%p,%p,%p): stub\n",This,pbc,pmkToLeft,pszDisplayName,pchEaten,ppmkOut);
00425     return E_NOTIMPL;
00426 }
00427 
00428 static HRESULT WINAPI URLMoniker_IsSystemMoniker(IMoniker *iface, DWORD *pwdMksys)
00429 {
00430     URLMoniker *This = impl_from_IMoniker(iface);
00431 
00432     TRACE("(%p,%p)\n",This,pwdMksys);
00433 
00434     if(!pwdMksys)
00435         return E_INVALIDARG;
00436 
00437     *pwdMksys = MKSYS_URLMONIKER;
00438     return S_OK;
00439 }
00440 
00441 static const IMonikerVtbl URLMonikerVtbl =
00442 {
00443     URLMoniker_QueryInterface,
00444     URLMoniker_AddRef,
00445     URLMoniker_Release,
00446     URLMoniker_GetClassID,
00447     URLMoniker_IsDirty,
00448     URLMoniker_Load,
00449     URLMoniker_Save,
00450     URLMoniker_GetSizeMax,
00451     URLMoniker_BindToObject,
00452     URLMoniker_BindToStorage,
00453     URLMoniker_Reduce,
00454     URLMoniker_ComposeWith,
00455     URLMoniker_Enum,
00456     URLMoniker_IsEqual,
00457     URLMoniker_Hash,
00458     URLMoniker_IsRunning,
00459     URLMoniker_GetTimeOfLastChange,
00460     URLMoniker_Inverse,
00461     URLMoniker_CommonPrefixWith,
00462     URLMoniker_RelativePathTo,
00463     URLMoniker_GetDisplayName,
00464     URLMoniker_ParseDisplayName,
00465     URLMoniker_IsSystemMoniker
00466 };
00467 
00468 static inline URLMoniker *impl_from_IUriContainer(IUriContainer *iface)
00469 {
00470     return CONTAINING_RECORD(iface, URLMoniker, IUriContainer_iface);
00471 }
00472 
00473 static HRESULT WINAPI UriContainer_QueryInterface(IUriContainer *iface, REFIID riid, void **ppv)
00474 {
00475     URLMoniker *This = impl_from_IUriContainer(iface);
00476     return IMoniker_QueryInterface(&This->IMoniker_iface, riid, ppv);
00477 }
00478 
00479 static ULONG WINAPI UriContainer_AddRef(IUriContainer *iface)
00480 {
00481     URLMoniker *This = impl_from_IUriContainer(iface);
00482     return IMoniker_AddRef(&This->IMoniker_iface);
00483 }
00484 
00485 static ULONG WINAPI UriContainer_Release(IUriContainer *iface)
00486 {
00487     URLMoniker *This = impl_from_IUriContainer(iface);
00488     return IMoniker_Release(&This->IMoniker_iface);
00489 }
00490 
00491 static HRESULT WINAPI UriContainer_GetIUri(IUriContainer *iface, IUri **ppIUri)
00492 {
00493     URLMoniker *This = impl_from_IUriContainer(iface);
00494 
00495     FIXME("(%p)->(%p)\n", This, ppIUri);
00496 
00497     *ppIUri = NULL;
00498     return S_FALSE;
00499 }
00500 
00501 static const IUriContainerVtbl UriContainerVtbl = {
00502     UriContainer_QueryInterface,
00503     UriContainer_AddRef,
00504     UriContainer_Release,
00505     UriContainer_GetIUri
00506 };
00507 
00508 static URLMoniker *alloc_moniker(void)
00509 {
00510     URLMoniker *ret;
00511 
00512     ret = heap_alloc(sizeof(URLMoniker));
00513     if(!ret)
00514         return NULL;
00515 
00516     ret->IMoniker_iface.lpVtbl = &URLMonikerVtbl;
00517     ret->IUriContainer_iface.lpVtbl = &UriContainerVtbl;
00518     ret->ref = 1;
00519     ret->URLName = NULL;
00520 
00521     return ret;
00522 }
00523 
00524 static HRESULT URLMoniker_Init(URLMoniker *This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
00525 {
00526     HRESULT hres;
00527     DWORD sizeStr = 0;
00528 
00529     TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
00530 
00531     This->URLName = heap_alloc(INTERNET_MAX_URL_LENGTH*sizeof(WCHAR));
00532 
00533     if(lpszLeftURLName)
00534         hres = CoInternetCombineUrl(lpszLeftURLName, lpszURLName, URL_FILE_USE_PATHURL,
00535                 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
00536     else
00537         hres = CoInternetParseUrl(lpszURLName, PARSE_CANONICALIZE, URL_FILE_USE_PATHURL,
00538                 This->URLName, INTERNET_MAX_URL_LENGTH, &sizeStr, 0);
00539 
00540     if(FAILED(hres)) {
00541         heap_free(This->URLName);
00542         return hres;
00543     }
00544 
00545     URLMON_LockModule();
00546 
00547     if(sizeStr != INTERNET_MAX_URL_LENGTH)
00548         This->URLName = heap_realloc(This->URLName, (sizeStr+1)*sizeof(WCHAR));
00549 
00550     TRACE("URLName = %s\n", debugstr_w(This->URLName));
00551 
00552     return S_OK;
00553 }
00554 
00555 HRESULT StdURLMoniker_Construct(IUnknown *outer, void **ppv)
00556 {
00557     TRACE("(%p %p)\n", outer, ppv);
00558 
00559     *ppv = alloc_moniker();
00560     return *ppv ? S_OK : E_OUTOFMEMORY;
00561 }
00562 
00563 /***********************************************************************
00564  *           CreateURLMonikerEx (URLMON.@)
00565  *
00566  * Create a url moniker.
00567  *
00568  * PARAMS
00569  *    pmkContext [I] Context
00570  *    szURL      [I] Url to create the moniker for
00571  *    ppmk       [O] Destination for created moniker.
00572  *    dwFlags    [I] Flags.
00573  *
00574  * RETURNS
00575  *    Success: S_OK. ppmk contains the created IMoniker object.
00576  *    Failure: MK_E_SYNTAX if szURL is not a valid url, or
00577  *             E_OUTOFMEMORY if memory allocation fails.
00578  */
00579 HRESULT WINAPI CreateURLMonikerEx(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk, DWORD dwFlags)
00580 {
00581     URLMoniker *obj;
00582     HRESULT hres;
00583     LPOLESTR lefturl = NULL;
00584 
00585     TRACE("(%p, %s, %p, %08x)\n", pmkContext, debugstr_w(szURL), ppmk, dwFlags);
00586 
00587     if (ppmk)
00588         *ppmk = NULL;
00589 
00590     if (!szURL || !ppmk)
00591         return E_INVALIDARG;
00592 
00593     if (dwFlags & URL_MK_UNIFORM) FIXME("ignoring flag URL_MK_UNIFORM\n");
00594 
00595     if(!(obj = alloc_moniker()))
00596     return E_OUTOFMEMORY;
00597 
00598     if(pmkContext) {
00599         IBindCtx* bind;
00600         DWORD dwMksys = 0;
00601         IMoniker_IsSystemMoniker(pmkContext, &dwMksys);
00602         if(dwMksys == MKSYS_URLMONIKER && SUCCEEDED(CreateBindCtx(0, &bind))) {
00603             IMoniker_GetDisplayName(pmkContext, bind, NULL, &lefturl);
00604             TRACE("lefturl = %s\n", debugstr_w(lefturl));
00605             IBindCtx_Release(bind);
00606         }
00607     }
00608         
00609     hres = URLMoniker_Init(obj, lefturl, szURL);
00610     CoTaskMemFree(lefturl);
00611     if(SUCCEEDED(hres))
00612         hres = URLMoniker_QueryInterface(&obj->IMoniker_iface, &IID_IMoniker, (void**)ppmk);
00613     IMoniker_Release(&obj->IMoniker_iface);
00614     return hres;
00615 }
00616 
00617 /**********************************************************************
00618  *           CreateURLMoniker (URLMON.@)
00619  *
00620  * Create a url moniker.
00621  *
00622  * PARAMS
00623  *    pmkContext [I] Context
00624  *    szURL      [I] Url to create the moniker for
00625  *    ppmk       [O] Destination for created moniker.
00626  *
00627  * RETURNS
00628  *    Success: S_OK. ppmk contains the created IMoniker object.
00629  *    Failure: MK_E_SYNTAX if szURL is not a valid url, or
00630  *             E_OUTOFMEMORY if memory allocation fails.
00631  */
00632 HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **ppmk)
00633 {
00634     return CreateURLMonikerEx(pmkContext, szURL, ppmk, URL_MK_LEGACY);
00635 }
00636 
00637 /***********************************************************************
00638  *           IsAsyncMoniker (URLMON.@)
00639  */
00640 HRESULT WINAPI IsAsyncMoniker(IMoniker *pmk)
00641 {
00642     IUnknown *am;
00643     
00644     TRACE("(%p)\n", pmk);
00645     if(!pmk)
00646         return E_INVALIDARG;
00647     if(SUCCEEDED(IMoniker_QueryInterface(pmk, &IID_IAsyncMoniker, (void**)&am))) {
00648         IUnknown_Release(am);
00649         return S_OK;
00650     }
00651     return S_FALSE;
00652 }
00653 
00654 /***********************************************************************
00655  *           BindAsyncMoniker (URLMON.@)
00656  *
00657  * Bind a bind status callback to an asynchronous URL Moniker.
00658  *
00659  * PARAMS
00660  *  pmk           [I] Moniker object to bind status callback to
00661  *  grfOpt        [I] Options, seems not used
00662  *  pbsc          [I] Status callback to bind
00663  *  iidResult     [I] Interface to return
00664  *  ppvResult     [O] Resulting asynchronous moniker object
00665  *
00666  * RETURNS
00667  *    Success: S_OK.
00668  *    Failure: E_INVALIDARG, if any argument is invalid, or
00669  *             E_OUTOFMEMORY if memory allocation fails.
00670  */
00671 HRESULT WINAPI BindAsyncMoniker(IMoniker *pmk, DWORD grfOpt, IBindStatusCallback *pbsc, REFIID iidResult, LPVOID *ppvResult)
00672 {
00673     LPBC pbc = NULL;
00674     HRESULT hr = E_INVALIDARG;
00675 
00676     TRACE("(%p %08x %p %s %p)\n", pmk, grfOpt, pbsc, debugstr_guid(iidResult), ppvResult);
00677 
00678     if (pmk && ppvResult)
00679     {
00680         *ppvResult = NULL;
00681 
00682         hr = CreateAsyncBindCtx(0, pbsc, NULL, &pbc);
00683         if (hr == NOERROR)
00684         {
00685             hr = IMoniker_BindToObject(pmk, pbc, NULL, iidResult, ppvResult);
00686             IBindCtx_Release(pbc);
00687         }
00688     }
00689     return hr;
00690 }
00691 
00692 /***********************************************************************
00693  *           MkParseDisplayNameEx (URLMON.@)
00694  */
00695 HRESULT WINAPI MkParseDisplayNameEx(IBindCtx *pbc, LPCWSTR szDisplayName, ULONG *pchEaten, LPMONIKER *ppmk)
00696 {
00697     TRACE("(%p %s %p %p)\n", pbc, debugstr_w(szDisplayName), pchEaten, ppmk);
00698 
00699     if (!pbc || !szDisplayName || !*szDisplayName || !pchEaten || !ppmk)
00700         return E_INVALIDARG;
00701 
00702     if(is_registered_protocol(szDisplayName)) {
00703         HRESULT hres;
00704 
00705         hres = CreateURLMoniker(NULL, szDisplayName, ppmk);
00706         if(SUCCEEDED(hres)) {
00707             *pchEaten = strlenW(szDisplayName);
00708             return hres;
00709         }
00710     }
00711 
00712     return MkParseDisplayName(pbc, szDisplayName, pchEaten, ppmk);
00713 }
00714 
00715 
00716 /***********************************************************************
00717  *           URLDownloadToCacheFileA (URLMON.@)
00718  */
00719 HRESULT WINAPI URLDownloadToCacheFileA(LPUNKNOWN lpUnkCaller, LPCSTR szURL, LPSTR szFileName,
00720         DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
00721 {
00722     LPWSTR url = NULL, file_name = NULL;
00723     int len;
00724     HRESULT hres;
00725 
00726     TRACE("(%p %s %p %d %d %p)\n", lpUnkCaller, debugstr_a(szURL), szFileName,
00727             dwBufLength, dwReserved, pBSC);
00728 
00729     if(szURL) {
00730         len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
00731         url = heap_alloc(len*sizeof(WCHAR));
00732         MultiByteToWideChar(CP_ACP, 0, szURL, -1, url, len);
00733     }
00734 
00735     if(szFileName)
00736         file_name = heap_alloc(dwBufLength*sizeof(WCHAR));
00737 
00738     hres = URLDownloadToCacheFileW(lpUnkCaller, url, file_name, dwBufLength*sizeof(WCHAR),
00739             dwReserved, pBSC);
00740 
00741     if(SUCCEEDED(hres) && file_name)
00742         WideCharToMultiByte(CP_ACP, 0, file_name, -1, szFileName, dwBufLength, NULL, NULL);
00743 
00744     heap_free(url);
00745     heap_free(file_name);
00746 
00747     return hres;
00748 }
00749 
00750 /***********************************************************************
00751  *           URLDownloadToCacheFileW (URLMON.@)
00752  */
00753 HRESULT WINAPI URLDownloadToCacheFileW(LPUNKNOWN lpUnkCaller, LPCWSTR szURL, LPWSTR szFileName,
00754                 DWORD dwBufLength, DWORD dwReserved, LPBINDSTATUSCALLBACK pBSC)
00755 {
00756     WCHAR cache_path[MAX_PATH + 1];
00757     FILETIME expire, modified;
00758     HRESULT hr;
00759     LPWSTR ext;
00760 
00761     static WCHAR header[] = {
00762         'H','T','T','P','/','1','.','0',' ','2','0','0',' ',
00763         'O','K','\\','r','\\','n','\\','r','\\','n',0
00764     };
00765 
00766     TRACE("(%p, %s, %p, %d, %d, %p)\n", lpUnkCaller, debugstr_w(szURL),
00767           szFileName, dwBufLength, dwReserved, pBSC);
00768 
00769     if (!szURL || !szFileName)
00770         return E_INVALIDARG;
00771 
00772     ext = PathFindExtensionW(szURL);
00773 
00774     if (!CreateUrlCacheEntryW(szURL, 0, ext, cache_path, 0))
00775         return E_FAIL;
00776 
00777     hr = URLDownloadToFileW(lpUnkCaller, szURL, cache_path, 0, pBSC);
00778     if (FAILED(hr))
00779         return hr;
00780 
00781     expire.dwHighDateTime = 0;
00782     expire.dwLowDateTime = 0;
00783     modified.dwHighDateTime = 0;
00784     modified.dwLowDateTime = 0;
00785 
00786     if (!CommitUrlCacheEntryW(szURL, cache_path, expire, modified, NORMAL_CACHE_ENTRY,
00787                               header, sizeof(header), NULL, NULL))
00788         return E_FAIL;
00789 
00790     if (strlenW(cache_path) > dwBufLength)
00791         return E_OUTOFMEMORY;
00792 
00793     lstrcpyW(szFileName, cache_path);
00794 
00795     return S_OK;
00796 }
00797 
00798 /***********************************************************************
00799  *           HlinkSimpleNavigateToMoniker (URLMON.@)
00800  */
00801 HRESULT WINAPI HlinkSimpleNavigateToMoniker(IMoniker *pmkTarget,
00802     LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
00803     IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
00804 {
00805     LPWSTR target;
00806     HRESULT hres;
00807 
00808     TRACE("\n");
00809 
00810     hres = IMoniker_GetDisplayName(pmkTarget, pbc, 0, &target);
00811     if(hres == S_OK)
00812         hres = HlinkSimpleNavigateToString( target, szLocation, szTargetFrameName,
00813                                             pUnk, pbc, pbsc, grfHLNF, dwReserved );
00814     CoTaskMemFree(target);
00815 
00816     return hres;
00817 }
00818 
00819 /***********************************************************************
00820  *           HlinkSimpleNavigateToString (URLMON.@)
00821  */
00822 HRESULT WINAPI HlinkSimpleNavigateToString( LPCWSTR szTarget,
00823     LPCWSTR szLocation, LPCWSTR szTargetFrameName, IUnknown *pUnk,
00824     IBindCtx *pbc, IBindStatusCallback *pbsc, DWORD grfHLNF, DWORD dwReserved)
00825 {
00826     FIXME("%s %s %s %p %p %p %u %u partial stub\n", debugstr_w( szTarget ), debugstr_w( szLocation ),
00827           debugstr_w( szTargetFrameName ), pUnk, pbc, pbsc, grfHLNF, dwReserved);
00828 
00829     /* undocumented: 0 means HLNF_OPENINNEWWINDOW*/
00830     if (!grfHLNF) grfHLNF = HLNF_OPENINNEWWINDOW;
00831 
00832     if (grfHLNF == HLNF_OPENINNEWWINDOW)
00833     {
00834         SHELLEXECUTEINFOW sei;
00835         static const WCHAR openW[] = { 'o', 'p', 'e', 'n', 0 };
00836 
00837         memset(&sei, 0, sizeof(sei));
00838         sei.cbSize = sizeof(sei);
00839         sei.lpVerb = openW;
00840         sei.nShow = SW_SHOWNORMAL;
00841         sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NO_CONSOLE;
00842         sei.lpFile = szTarget;
00843 
00844         if (ShellExecuteExW(&sei)) return S_OK;
00845     }
00846 
00847     return E_NOTIMPL;
00848 }
00849 
00850 /***********************************************************************
00851  *           HlinkNavigateString (URLMON.@)
00852  */
00853 HRESULT WINAPI HlinkNavigateString( IUnknown *pUnk, LPCWSTR szTarget )
00854 {
00855     TRACE("%p %s\n", pUnk, debugstr_w( szTarget ) );
00856     return HlinkSimpleNavigateToString( 
00857                szTarget, NULL, NULL, pUnk, NULL, NULL, 0, 0 );
00858 }
00859 
00860 /***********************************************************************
00861  *           GetSoftwareUpdateInfo (URLMON.@)
00862  */
00863 HRESULT WINAPI GetSoftwareUpdateInfo( LPCWSTR szDistUnit, LPSOFTDISTINFO psdi )
00864 {
00865     FIXME("%s %p\n", debugstr_w(szDistUnit), psdi );
00866     return E_FAIL;
00867 }
00868 
00869 /***********************************************************************
00870  *           AsyncInstallDistributionUnit (URLMON.@)
00871  */
00872 HRESULT WINAPI AsyncInstallDistributionUnit( LPCWSTR szDistUnit, LPCWSTR szTYPE,
00873                             LPCWSTR szExt, DWORD dwFileVersionMS, DWORD dwFileVersionLS,
00874                             LPCWSTR szURL, IBindCtx *pbc, LPVOID pvReserved, DWORD flags )
00875 {
00876     FIXME(": stub\n");
00877     return E_NOTIMPL;
00878 }

Generated on Fri May 25 2012 04:24:48 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.