Example #1
0
static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
                                          DWORD dwFlags, IMediaStream** ppNewStream)
{
    IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
    HRESULT hr;
    IMediaStream* pStream;
    IMediaStream** pNewStreams;

    FIXME("(%p/%p)->(%p,%s,%x,%p) partial stub!\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);

    hr = mediastream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
    if (SUCCEEDED(hr))
    {
        pNewStreams = CoTaskMemRealloc(This->pStreams, (This->nbStreams+1) * sizeof(IMediaStream*));
        if (!pNewStreams)
        {
            IMediaStream_Release(pStream);
            return E_OUTOFMEMORY;
        }
        This->pStreams = pNewStreams;
        This->pStreams[This->nbStreams] = pStream;
        This->nbStreams++;

        if (ppNewStream)
            *ppNewStream = pStream;
    }

    return hr;
}
Example #2
0
/* A helper function:  Allocate and fill rString.  Return number of bytes read. */
static DWORD get_profile_string(LPCWSTR lpAppName, LPCWSTR lpKeyName,
                                LPCWSTR lpFileName, WCHAR **rString )
{
    DWORD r = 0;
    DWORD len = 128;
    WCHAR *buffer;

    buffer = CoTaskMemAlloc(len * sizeof(*buffer));
    if (buffer != NULL)
    {
        r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName);
        while (r == len-1)
        {
            WCHAR *realloc_buf;

            len *= 2;
            realloc_buf = CoTaskMemRealloc(buffer, len * sizeof(*buffer));
            if (realloc_buf == NULL)
            {
                CoTaskMemFree(buffer);
                *rString = NULL;
                return 0;
            }
            buffer = realloc_buf;

            r = GetPrivateProfileStringW(lpAppName, lpKeyName, NULL, buffer, len, lpFileName);
        }
    }

    *rString = buffer;
    return r;
}
HRESULT WIACamera::CDataCallback::StoreBuffer()
{
    // Increase the successfully transferred buffers array size
    IStream **ppStream = (IStream **) CoTaskMemRealloc(
		*m_pppStream, (*m_plCount + 1) * sizeof(IStream *)
	);
    if (ppStream == NULL) {
        return E_OUTOFMEMORY;
    }
    *m_pppStream = ppStream;

	// Rewind the current buffer
    LARGE_INTEGER liZero = { 0 };
    m_pStream->Seek(liZero, STREAM_SEEK_SET, 0);

    // Store the current buffer as the last successfully transferred buffer
	(*m_pppStream)[*m_plCount] = m_pStream;
    (*m_pppStream)[*m_plCount]->AddRef();
    *m_plCount += 1;

    // Reset the current buffer
    m_pStream->Release();

    m_nDataSize = 0;

    return S_OK;
}
Example #4
0
static HRESULT WINAPI MediaStreamFilterImpl_AddMediaStream(IMediaStreamFilter* iface, IAMMediaStream *pAMMediaStream)
{
    IMediaStreamFilterImpl *This = impl_from_IMediaStreamFilter(iface);
    IMediaStream** streams;
    IPin** pins;
    MediaStreamFilter_InputPin* pin;
    HRESULT hr;
    PIN_INFO info;
    MSPID purpose_id;

    TRACE("(%p)->(%p)\n", iface, pAMMediaStream);

    streams = CoTaskMemRealloc(This->streams, (This->nb_streams + 1) * sizeof(IMediaStream*));
    if (!streams)
        return E_OUTOFMEMORY;
    This->streams = streams;
    pins = CoTaskMemRealloc(This->pins, (This->nb_streams + 1) * sizeof(IPin*));
    if (!pins)
        return E_OUTOFMEMORY;
    This->pins = pins;
    info.pFilter = (IBaseFilter*)&This->filter;
    info.dir = PINDIR_INPUT;
    hr = IAMMediaStream_GetInformation(pAMMediaStream, &purpose_id, NULL);
    if (FAILED(hr))
        return hr;
    /* Pin name is "I{guid MSPID_PrimaryVideo or MSPID_PrimaryAudio}" */
    info.achName[0] = 'I';
    StringFromGUID2(&purpose_id, info.achName + 1, 40);
    hr = BaseInputPin_Construct(&MediaStreamFilter_InputPin_Vtbl, sizeof(BaseInputPin), &info, &input_BaseFuncTable,
            &input_BaseInputFuncTable, &This->filter.csFilter, NULL, &This->pins[This->nb_streams]);
    if (FAILED(hr))
        return hr;

    pin = (MediaStreamFilter_InputPin*)This->pins[This->nb_streams];
    pin->pin.pin.pinInfo.pFilter = (LPVOID)This;
    This->streams[This->nb_streams] = (IMediaStream*)pAMMediaStream;
    This->nb_streams++;

    IMediaStream_AddRef((IMediaStream*)pAMMediaStream);

    return S_OK;
}
Example #5
0
/***********************************************************************
 *             HlinkGetSpecialReference (HLINK.@)
 */
HRESULT WINAPI HlinkGetSpecialReference(ULONG uReference, LPWSTR *ppwzReference)
{
    DWORD res, type, size = 100;
    LPCWSTR value_name;
    WCHAR *buf;
    HKEY hkey;

    static const WCHAR start_pageW[] = {'S','t','a','r','t',' ','P','a','g','e',0};
    static const WCHAR search_pageW[] = {'S','e','a','r','c','h',' ','P','a','g','e',0};

    static const WCHAR ie_main_keyW[] =
        {'S','o','f','t','w','a','r','e',
         '\\','M','i','c','r','o','s','o','f','t','\\',
         'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',
         '\\','M','a','i','n',0};

    TRACE("(%u %p)\n", uReference, ppwzReference);

    *ppwzReference = NULL;

    switch(uReference) {
    case HLSR_HOME:
        value_name = start_pageW;
        break;
    case HLSR_SEARCHPAGE:
        value_name = search_pageW;
        break;
    case HLSR_HISTORYFOLDER:
        return E_NOTIMPL;
    default:
        return E_INVALIDARG;
    }

    res = RegOpenKeyW(HKEY_CURRENT_USER, ie_main_keyW, &hkey);
    if(res != ERROR_SUCCESS) {
        WARN("Could not open key: %u\n", res);
        return HRESULT_FROM_WIN32(res);
    }

    buf = CoTaskMemAlloc(size);
    res = RegQueryValueExW(hkey, value_name, NULL, &type, (PBYTE)buf, &size);
    buf = CoTaskMemRealloc(buf, size);
    if(res == ERROR_MORE_DATA)
        res = RegQueryValueExW(hkey, value_name, NULL, &type, (PBYTE)buf, &size);
    RegCloseKey(hkey);
    if(res != ERROR_SUCCESS) {
        WARN("Could not query value %s: %u\n", debugstr_w(value_name), res);
        CoTaskMemFree(buf);
        return HRESULT_FROM_WIN32(res);
    }

    *ppwzReference = buf;
    return S_OK;
}
Example #6
0
void allocCoTaskMem(bool bFree)
{
    void* leaked = CoTaskMemAlloc(7);
    if (bFree)
    {
        CoTaskMemFree(leaked);
    }
    void* leaked2 = CoTaskMemAlloc(7);
    void* realloced = CoTaskMemRealloc(leaked2, 29);
    if (bFree)
    {
        CoTaskMemFree(realloced);
    }
}
Example #7
0
HRESULT STDMETHODCALLTYPE CACLMulti::Append(IUnknown *punk)
{
    TRACE("(%p, %p)\n", this, punk);
    if (punk == NULL)
        return E_FAIL;

    fObjects = static_cast<ACLMultiSublist *>(
        CoTaskMemRealloc(fObjects, sizeof(fObjects[0]) * (fObjectCount + 1)));
    fObjects[fObjectCount].punk = punk;
    punk->AddRef();
    if (FAILED(punk->QueryInterface(IID_IEnumString, reinterpret_cast<void **>(&fObjects[fObjectCount].pEnum))))
        fObjects[fObjectCount].pEnum = NULL;
    if (FAILED(punk->QueryInterface(IID_IACList, reinterpret_cast<void **>(&fObjects[fObjectCount].pACL))))
        fObjects[fObjectCount].pACL = NULL;
    fObjectCount++;
    return S_OK;
}
Example #8
0
STDMETHODIMP CLAVSubtitleFrame::AddBitmap(CLAVSubRect *subRect)
{
  // Allocate memory for the new block
  void *mem = CoTaskMemRealloc(m_Bitmaps, sizeof(*m_Bitmaps) * (m_NumBitmaps+1));
  if (!mem) {
    return E_OUTOFMEMORY;
  }

  m_Bitmaps = (CLAVSubRect **)mem;
  m_Bitmaps[m_NumBitmaps] = subRect;
  m_NumBitmaps++;

  // Hold reference on the subtitle rect
  subRect->AddRef();

  return S_OK;
}
Example #9
0
BYTE * AddLAVFrameSideData(LAVFrame *pFrame, GUID guidType, size_t size)
{
  BYTE * ptr = (BYTE *)CoTaskMemRealloc(pFrame->side_data, sizeof(LAVFrameSideData) * (pFrame->side_data_count + 1));
  if (!ptr)
    return NULL;

  pFrame->side_data = (LAVFrameSideData *)ptr;
  pFrame->side_data[pFrame->side_data_count].guidType = guidType;
  pFrame->side_data[pFrame->side_data_count].data = (BYTE *)CoTaskMemAlloc(size);
  pFrame->side_data[pFrame->side_data_count].size = size;

  if (!pFrame->side_data[pFrame->side_data_count].data)
    return NULL;

  pFrame->side_data_count++;

  return pFrame->side_data[pFrame->side_data_count - 1].data;
}
Example #10
0
HRESULT STDMETHODCALLTYPE CACLMulti::Remove(IUnknown *punk)
{
    int                                     i;

    TRACE("(%p, %p)\n", this, punk);
    for (i = 0; i < fObjectCount; i++)
        if (fObjects[i].punk == punk)
        {
            release_obj(&fObjects[i]);
            MoveMemory(&fObjects[i], &fObjects[i + 1], (fObjectCount - i - 1) * sizeof(ACLMultiSublist));
            fObjectCount--;
            fObjects = static_cast<ACLMultiSublist *>(
                CoTaskMemRealloc(fObjects, sizeof(fObjects[0]) * fObjectCount));
            return S_OK;
        }

    return E_FAIL;
}
Example #11
0
void MonitorSink::SetCustomHeaders(LPWSTR *pszAdditionalHeaders)
{
    if (pszAdditionalHeaders && *pszAdditionalHeaders)
    {
        CStringW strHeaders(*pszAdditionalHeaders);
        size_t nOrigLen = strHeaders.GetLength();

        bool bSendDNT1 = abp::AdBlockPlus::shouldSendDNTHeader(m_strURL.GetString());
        bool bSendDNT0 = PrefManager::instance().isDNTEnabled() && PrefManager::instance().getDNTValue() == 0;
        bool bSendDNT = bSendDNT1 || bSendDNT0;
        int nDNTValue = bSendDNT1 ? 1 : 0;
        if (bSendDNT)
        {
            LPWSTR lpDNT = NULL;
            size_t nDNTLen = 0;
            bool hasDNT = false;
            if (Utils::HTTP::ExtractFieldValue(*pszAdditionalHeaders, L"DNT:", &lpDNT, &nDNTLen))
            {
                if (nDNTLen)
                {
                    // Already has DNT header
                    hasDNT = true;
                }
                if (lpDNT) Utils::HTTP::FreeFieldValue(lpDNT);
            }
            // Append DoNotTrack (DNT) header
            if (!hasDNT)
                strHeaders.AppendFormat(L"DNT: %d\r\n", nDNTValue);
        }

        if (strHeaders.GetLength() == nOrigLen)
            return; // Not modified, return immediately

        size_t nLen = strHeaders.GetLength() + 2;
        if (*pszAdditionalHeaders = (LPWSTR)CoTaskMemRealloc(*pszAdditionalHeaders, nLen * sizeof(WCHAR)))
        {
            wcscpy_s(*pszAdditionalHeaders, nLen, strHeaders);
        }
    }
}
Example #12
0
void
CString::ConcatInPlace(LPCSTR lpszSrc, int nSrcLen)
{
	if (nSrcLen > 0) {
		int	nNewAllocLength = m_nDataLength + nSrcLen;

		if (nNewAllocLength > m_nAllocLength) {
			if (m_nAllocLength == 0) {
				m_pchData = (LPSTR)CoTaskMemAlloc(nNewAllocLength + 1);
			
			} else {
				// realloc the existing memory
				m_pchData = (LPSTR)CoTaskMemRealloc(m_pchData, nNewAllocLength + 1);
			}

			m_nAllocLength = nNewAllocLength;
		}
	
		memcpy(&m_pchData[m_nDataLength], lpszSrc, nSrcLen);
		m_nDataLength += nSrcLen;
		m_pchData[m_nDataLength] = '\0';
	}
}
Example #13
0
bool BstrStream::resize(ULONG cb)
{
    m_Buf = (LPBYTE)CoTaskMemRealloc(m_Buf, m_Size = cb);
    return m_Buf != NULL;
}
void CDVSMainPPage::AllocLangs(int nLangs)
{
	m_ppLangs = (WCHAR**)CoTaskMemRealloc(m_ppLangs, sizeof(WCHAR*)*nLangs);
	m_nLangs = nLangs;
}
Example #15
0
int willus_mem_realloc_robust(double **ptr,long newsize,long oldsize,char *name)

    {
#if (defined(WIN32) && !defined(__DMC__) && !defined(MINGW))
    unsigned long memsize;
    void *newptr;
#else
    size_t  memsize;
    void *newptr;
#endif
#ifndef NOMEMDEBUG
#ifdef DEBUG
    int ra=0;
#endif
#endif // NOMEMDEBUG

#if (defined(WIN32) && !defined(__DMC__) && !defined(MINGW))
    memsize=(unsigned long)newsize;
#else
    memsize=(size_t)newsize;
#endif
    if (memsize!=newsize)
        return(0);
    if ((*ptr)==NULL || oldsize<=0)
        return(willus_mem_alloc(ptr,newsize,name));
#if (defined(WIN32) && !defined(__DMC__) && !defined(MINGW))
#ifdef USEGLOBAL
    newptr = (void *)GlobalReAlloc((void *)(*ptr),memsize,GMEM_MOVEABLE);
#else
    newptr = (void *)CoTaskMemRealloc((void *)(*ptr),memsize);
#endif
#else
    newptr = realloc((void *)(*ptr),memsize);
#endif
    if (newptr==NULL && willus_mem_alloc((double **)&newptr,newsize,name))
        {
#ifndef NOMEMDEBUG
#ifdef DEBUG
        ra=1;
        printf("Copying %ld bytes from old pointer to new pointer.\n",oldsize);
#endif
#endif // NOMEMDEBUG
        memcpy(newptr,(*ptr),oldsize);
#ifndef NOMEMDEBUG
#ifdef DEBUG
        printf("Done.\n");
#endif
#endif // NOMEMDEBUG
        willus_mem_free(ptr,name);
        }
    if (newptr==NULL)
        return(0);
#ifndef NOMEMDEBUG
#ifdef DEBUG
    if (!willus_mem_inited)
        willus_mem_init();
    if (ra==0)
    {
    int i;
    char label[80];

    for (i=0;i<n && ptrs[i]!=(*ptr);i++);
    if (i>=n)
        {
        sprintf(label,"!!Bad RRA!! oldptr=%p,oldsize=%d ",(*ptr),(int)oldsize);
        totmem += memsize-oldsize;
        ptrs[n] = newptr;
        sizealloced[n] = memsize;
        strncpy(fname[n],name,31);
        fname[n][31]='\0';
        n++;
        allocated_ptrs++;
        willus_mem_update(label,name,memsize,newptr);
        }
        // printf("*** !! realloc can't find pointer in list !! ***\n");
    else
        {
        totmem += memsize-sizealloced[i];
        sizealloced[i] = memsize;
        ptrs[i] = newptr;
        strncpy(fname[i],name,31);
        fname[i][31]='\0';
        willus_mem_update(" RRA  ",name,memsize,newptr);
        }
    }
#endif
#endif // NOMEMDEBUG

    (*ptr) = newptr;
    return(1);
    }
Example #16
0
int willus_mem_realloc(double **ptr,long newsize,char *name)

    {
#if (defined(WIN32) && !defined(__DMC__) && !defined(MINGW))
    unsigned long memsize;
    void *newptr;
#else
    size_t  memsize;
    void *newptr;
#endif

#if (defined(WIN32) && !defined(__DMC__) && !defined(MINGW))
    memsize=(unsigned long)newsize;
#else
    memsize=(size_t)newsize;
#endif
    if (memsize!=newsize)
        return(0);
    if ((*ptr)==NULL)
        return(willus_mem_alloc(ptr,newsize,name));
#if (defined(WIN32) && !defined(__DMC__) && !defined(MINGW))
#ifdef USEGLOBAL
    newptr = (void *)GlobalReAlloc((void *)(*ptr),memsize,GMEM_MOVEABLE);
    if (newptr==NULL)
        {
        printf("GlobalReAlloc fails:\n    %s\n",win_lasterror());
        printf("    Function:  %s\n",name);
        printf("    Mem size requested:  %ld\n",newsize);
        }
#else
    newptr = (void *)CoTaskMemRealloc((void *)(*ptr),memsize);
#endif
#else
    newptr = realloc((void *)(*ptr),memsize);
#endif
    if (newptr==NULL && willus_mem_alloc((double **)&newptr,newsize,name))
        {
        printf("!! DIRTY REALLOC in willus_mem_realloc !!\n");
        memcpy(newptr,(*ptr),newsize);
        willus_mem_free(ptr,name);
        }
    if (newptr==NULL)
        return(0);
#ifndef NOMEMDEBUG
#ifdef DEBUG
    if (!willus_mem_inited)
        willus_mem_init();
    {
    int i;
    char label[64];
    for (i=0;i<n && ptrs[i]!=(*ptr);i++);
    if (i>=n)
        {
        sprintf(label,"!!Bad SRA!! oldptr=%p ",(*ptr));
        totmem += memsize;
        ptrs[n] = newptr;
        sizealloced[n] = memsize;
        strncpy(fname[n],name,31);
        fname[n][31]='\0';
        n++;
        allocated_ptrs++;
        willus_mem_update(label,name,memsize,newptr);
        }
    else
        {
        totmem += memsize-sizealloced[i];
        sizealloced[i] = memsize;
        ptrs[i] = newptr;
        strncpy(fname[i],name,31);
        fname[i][31]='\0';
        willus_mem_update(" SRA  ",name,memsize,newptr);
        }
    }
#endif
#endif // NOMEMDEBUG

    (*ptr) = newptr;
    return(1);
    }
Example #17
0
static HRESULT WINAPI IAMMultiMediaStreamImpl_AddMediaStream(IAMMultiMediaStream* iface, IUnknown* pStreamObject, const MSPID* PurposeId,
                                          DWORD dwFlags, IMediaStream** ppNewStream)
{
    IAMMultiMediaStreamImpl *This = impl_from_IAMMultiMediaStream(iface);
    HRESULT hr;
    IMediaStream* pStream;
    IMediaStream** pNewStreams;

    TRACE("(%p/%p)->(%p,%s,%x,%p)\n", This, iface, pStreamObject, debugstr_guid(PurposeId), dwFlags, ppNewStream);

    if (!IsEqualGUID(PurposeId, &MSPID_PrimaryVideo) && !IsEqualGUID(PurposeId, &MSPID_PrimaryAudio))
        return MS_E_PURPOSEID;

    if (dwFlags & AMMSF_ADDDEFAULTRENDERER)
    {
        if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
        {
            /* Default renderer not supported by video stream */
            return MS_E_PURPOSEID;
        }
        else
        {
            IBaseFilter* dsoundrender_filter;

            /* Create the default renderer for audio */
            hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (LPVOID*)&dsoundrender_filter);
            if (SUCCEEDED(hr))
            {
                 hr = IGraphBuilder_AddFilter(This->pFilterGraph, dsoundrender_filter, NULL);
                 IBaseFilter_Release(dsoundrender_filter);
            }

            /* No media stream created when the default renderer is used */
            return hr;
        }
    }

    if (IsEqualGUID(PurposeId, &MSPID_PrimaryVideo))
        hr = ddrawmediastream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
    else
        hr = audiomediastream_create((IMultiMediaStream*)iface, PurposeId, This->StreamType, &pStream);
    if (SUCCEEDED(hr))
    {
        pNewStreams = CoTaskMemRealloc(This->pStreams, (This->nbStreams+1) * sizeof(IMediaStream*));
        if (!pNewStreams)
        {
            IMediaStream_Release(pStream);
            return E_OUTOFMEMORY;
        }
        This->pStreams = pNewStreams;
        This->pStreams[This->nbStreams] = pStream;
        This->nbStreams++;

        if (ppNewStream)
            *ppNewStream = pStream;
    }

    if (SUCCEEDED(hr))
    {
        /* Add stream to the media stream filter */
        IMediaStreamFilter_AddMediaStream((IMediaStreamFilter*)This->media_stream_filter, (IAMMediaStream*)pStream);
    }

    return hr;
}
Example #18
0
static HRESULT WINAPI EnumWorkItems_Next(IEnumWorkItems *iface, ULONG count, LPWSTR **names, ULONG *fetched)
{
    static const WCHAR tasksW[] = { '\\','T','a','s','k','s','\\','*',0 };
    EnumWorkItemsImpl *This = impl_from_IEnumWorkItems(iface);
    WCHAR path[MAX_PATH];
    WIN32_FIND_DATAW data;
    ULONG enumerated, allocated, dummy;
    LPWSTR *list;
    HRESULT hr = S_FALSE;

    TRACE("(%p)->(%u %p %p)\n", This, count, names, fetched);

    if (!count || !names || (!fetched && count > 1)) return E_INVALIDARG;

    if (!fetched) fetched = &dummy;

    *names = NULL;
    *fetched = 0;
    enumerated = 0;
    list = NULL;

    if (This->handle == INVALID_HANDLE_VALUE)
    {
        GetWindowsDirectoryW(path, MAX_PATH);
        lstrcatW(path, tasksW);
        This->handle = FindFirstFileW(path, &data);
        if (This->handle == INVALID_HANDLE_VALUE)
            return S_FALSE;
    }
    else
    {
        if (!FindNextFileW(This->handle, &data))
            return S_FALSE;
    }

    allocated = 64;
    list = CoTaskMemAlloc(allocated * sizeof(list[0]));
    if (!list) return E_OUTOFMEMORY;

    do
    {
        if (is_file(&data))
        {
            if (enumerated >= allocated)
            {
                LPWSTR *new_list;
                allocated *= 2;
                new_list = CoTaskMemRealloc(list, allocated * sizeof(list[0]));
                if (!new_list)
                {
                    hr = E_OUTOFMEMORY;
                    break;
                }
                list = new_list;
            }

            list[enumerated] = CoTaskMemAlloc((lstrlenW(data.cFileName) + 1) * sizeof(WCHAR));
            if (!list[enumerated])
            {
                hr = E_OUTOFMEMORY;
                break;
            }

            lstrcpyW(list[enumerated], data.cFileName);
            enumerated++;

            if (enumerated >= count)
            {
                hr = S_OK;
                break;
            }
        }
    } while (FindNextFileW(This->handle, &data));

    if (FAILED(hr))
        free_list(list, enumerated);
    else
    {
        *fetched = enumerated;
        *names = list;
    }

    return hr;
}
Example #19
0
static HRESULT parse_security_url(const WCHAR *url, PSUACTION action, WCHAR **result) {
    IInternetProtocolInfo *protocol_info;
    WCHAR *tmp, *new_url = NULL, *alloc_url = NULL;
    DWORD size, new_size;
    HRESULT hres = S_OK, parse_hres;

    while(1) {
        TRACE("parsing %s\n", debugstr_w(url));

        protocol_info = get_protocol_info(url);
        if(!protocol_info)
            break;

        size = strlenW(url)+1;
        new_url = CoTaskMemAlloc(size*sizeof(WCHAR));
        if(!new_url) {
            hres = E_OUTOFMEMORY;
            break;
        }

        new_size = 0;
        parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL, 0, new_url, size, &new_size, 0);
        if(parse_hres == S_FALSE) {
            if(!new_size) {
                hres = E_UNEXPECTED;
                break;
            }

            tmp = CoTaskMemRealloc(new_url, new_size*sizeof(WCHAR));
            if(!tmp) {
                hres = E_OUTOFMEMORY;
                break;
            }
            new_url = tmp;
            parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_URL, 0, new_url,
                    new_size, &new_size, 0);
            if(parse_hres == S_FALSE) {
                hres = E_FAIL;
                break;
            }
        }

        if(parse_hres != S_OK || !strcmpW(url, new_url))
            break;

        CoTaskMemFree(alloc_url);
        url = alloc_url = new_url;
        new_url = NULL;
    }

    CoTaskMemFree(new_url);

    if(hres != S_OK) {
        WARN("failed: %08x\n", hres);
        CoTaskMemFree(alloc_url);
        return hres;
    }

    if(action == PSU_DEFAULT && (protocol_info = get_protocol_info(url))) {
        size = strlenW(url)+1;
        new_url = CoTaskMemAlloc(size * sizeof(WCHAR));
        if(new_url) {
            new_size = 0;
            parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN, 0,
                    new_url, size, &new_size, 0);
            if(parse_hres == S_FALSE) {
                if(new_size) {
                    tmp = CoTaskMemRealloc(new_url, new_size*sizeof(WCHAR));
                    if(tmp) {
                        new_url = tmp;
                        parse_hres = IInternetProtocolInfo_ParseUrl(protocol_info, url, PARSE_SECURITY_DOMAIN, 0, new_url,
                                new_size, &new_size, 0);
                        if(parse_hres == S_FALSE)
                            hres = E_FAIL;
                    }else {
                        hres = E_OUTOFMEMORY;
                    }
                }else {
                    hres = E_UNEXPECTED;
                }
            }

            if(hres == S_OK && parse_hres == S_OK) {
                CoTaskMemFree(alloc_url);
                url = alloc_url = new_url;
                new_url = NULL;
            }

            CoTaskMemFree(new_url);
        }else {
            hres = E_OUTOFMEMORY;
        }
        IInternetProtocolInfo_Release(protocol_info);
    }

    if(FAILED(hres)) {
        WARN("failed %08x\n", hres);
        CoTaskMemFree(alloc_url);
        return hres;
    }

    if(!alloc_url) {
        size = strlenW(url)+1;
        alloc_url = CoTaskMemAlloc(size * sizeof(WCHAR));
        if(!alloc_url)
            return E_OUTOFMEMORY;
        memcpy(alloc_url, url, size * sizeof(WCHAR));
    }

    *result = alloc_url;
    return S_OK;
}
Example #20
0
static void DEVENUM_ReadPinTypes(HKEY hkeyPinKey, REGFILTERPINS *rgPin)
{
    HKEY hkeyTypes = NULL;
    DWORD dwMajorTypes, i;
    REGPINTYPES *lpMediaType = NULL;
    DWORD dwMediaTypeSize = 0;

    if (RegOpenKeyExW(hkeyPinKey, wszTypes, 0, KEY_READ, &hkeyTypes) != ERROR_SUCCESS)
        return ;

    if (RegQueryInfoKeyW(hkeyTypes, NULL, NULL, NULL, &dwMajorTypes, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
                != ERROR_SUCCESS)
    {
        RegCloseKey(hkeyTypes);
        return ;
    }

    for (i = 0; i < dwMajorTypes; i++)
    {
        HKEY hkeyMajorType = NULL;
        WCHAR wszMajorTypeName[64];
        DWORD cName = sizeof(wszMajorTypeName) / sizeof(WCHAR);
        DWORD dwMinorTypes, i1;

        if (RegEnumKeyExW(hkeyTypes, i, wszMajorTypeName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;

        if (RegOpenKeyExW(hkeyTypes, wszMajorTypeName, 0, KEY_READ, &hkeyMajorType) != ERROR_SUCCESS) continue;

        if (RegQueryInfoKeyW(hkeyMajorType, NULL, NULL, NULL, &dwMinorTypes, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
                    != ERROR_SUCCESS)
        {
            RegCloseKey(hkeyMajorType);
            continue;
        }

        for (i1 = 0; i1 < dwMinorTypes; i1++)
        {
            WCHAR wszMinorTypeName[64];
            CLSID *clsMajorType = NULL, *clsMinorType = NULL;
            HRESULT hr;

            cName = sizeof(wszMinorTypeName) / sizeof(WCHAR);
            if (RegEnumKeyExW(hkeyMajorType, i1, wszMinorTypeName, &cName, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) continue;

            clsMinorType = CoTaskMemAlloc(sizeof(CLSID));
            if (!clsMinorType) continue;

            clsMajorType = CoTaskMemAlloc(sizeof(CLSID));
            if (!clsMajorType) goto error_cleanup_types;

            hr = CLSIDFromString(wszMinorTypeName, clsMinorType);
            if (FAILED(hr)) goto error_cleanup_types;

            hr = CLSIDFromString(wszMajorTypeName, clsMajorType);
            if (FAILED(hr)) goto error_cleanup_types;

            if (rgPin->nMediaTypes == dwMediaTypeSize)
            {
                DWORD dwNewSize = dwMediaTypeSize + (dwMediaTypeSize < 2 ? 1 : dwMediaTypeSize / 2);
                REGPINTYPES *lpNewMediaType;

                lpNewMediaType = CoTaskMemRealloc(lpMediaType, sizeof(REGPINTYPES) * dwNewSize);
                if (!lpNewMediaType) goto error_cleanup_types;

                lpMediaType = lpNewMediaType;
                dwMediaTypeSize = dwNewSize;
             }

            lpMediaType[rgPin->nMediaTypes].clsMajorType = clsMajorType;
            lpMediaType[rgPin->nMediaTypes].clsMinorType = clsMinorType;
            rgPin->nMediaTypes++;
            continue;

            error_cleanup_types:

            if (clsMajorType) CoTaskMemFree(clsMajorType);
            if (clsMinorType) CoTaskMemFree(clsMinorType);
        }

        RegCloseKey(hkeyMajorType);
    }

    RegCloseKey(hkeyTypes);

    if (lpMediaType && !rgPin->nMediaTypes)
    {
        CoTaskMemFree(lpMediaType);
        lpMediaType = NULL;
    }

    rgPin->lpMediaType = lpMediaType;
}
Example #21
0
FILE* OpenLocalFile(const char* path, const char* mode)
{
    bool relpath = false;
    int pathlen = strlen(path);

#ifdef __WIN32__
    if (pathlen > 3)
    {
        if (path[1] == ':' && path[2] == '\\')
            return OpenFile(path, mode);
    }
#else
    if (pathlen > 1)
    {
        if (path[0] == '/')
            return OpenFile(path, mode);
    }
#endif

    if (pathlen >= 3)
    {
        if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || path[2] == '\\'))
            relpath = true;
    }

    int emudirlen = strlen(EmuDirectory);
    char* emudirpath;
    if (emudirlen)
    {
        int len = emudirlen + 1 + pathlen + 1;
        emudirpath = new char[len];
        strncpy(&emudirpath[0], EmuDirectory, emudirlen);
        emudirpath[emudirlen] = '\\';
        strncpy(&emudirpath[emudirlen+1], path, pathlen);
        emudirpath[emudirlen+1+pathlen] = '\0';
    }
    else
    {
        emudirpath = new char[pathlen+1];
        strncpy(&emudirpath[0], path, pathlen);
        emudirpath[pathlen] = '\0';
    }

    // Locations are application directory, and AppData/melonDS on Windows or XDG_CONFIG_HOME/melonds on Linux

    FILE* f;

    // First check current working directory
    f = OpenFile(path, mode, true);
    if (f) { delete[] emudirpath; return f; }

    // then emu directory
    f = OpenFile(emudirpath, mode, true);
    if (f) { delete[] emudirpath; return f; }

#ifdef __WIN32__

    // a path relative to AppData wouldn't make much sense
    if (!relpath)
    {
        // Now check AppData
        PWSTR appDataPath = NULL;
        SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appDataPath);
        if (!appDataPath)
        {
            delete[] emudirpath;
            return NULL;
        }

        // this will be more than enough
        WCHAR fatperm[4];
        fatperm[0] = mode[0];
        fatperm[1] = mode[1];
        fatperm[2] = mode[2];
        fatperm[3] = 0;

        int fnlen = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
        if (fnlen < 1) { delete[] emudirpath; return NULL; }
        WCHAR* wfileName = new WCHAR[fnlen];
        int res = MultiByteToWideChar(CP_UTF8, 0, path, -1, wfileName, fnlen);
        if (res != fnlen) { delete[] wfileName; delete[] emudirpath; return NULL; } // checkme?

        const WCHAR* appdir = L"\\melonDS\\";

        int pos = wcslen(appDataPath);
        void* ptr = CoTaskMemRealloc(appDataPath, (pos+wcslen(appdir)+fnlen+1)*sizeof(WCHAR));
        if (!ptr) { delete[] wfileName; delete[] emudirpath; return NULL; } // oh well
        appDataPath = (PWSTR)ptr;

        wcscpy(&appDataPath[pos], appdir); pos += wcslen(appdir);
        wcscpy(&appDataPath[pos], wfileName);

        f = _wfopen(appDataPath, L"rb");
        if (f) f = _wfreopen(appDataPath, fatperm, f);
        CoTaskMemFree(appDataPath);
        delete[] wfileName;
        if (f) { delete[] emudirpath; return f; }
    }

#else

    if (!relpath)
    {
        // Now check XDG_CONFIG_HOME
        // TODO: check for memory leak there
        std::string fullpath = std::string(g_get_user_config_dir()) + "/melonds/" + path;
        f = OpenFile(fullpath.c_str(), mode, true);
        if (f) { delete[] emudirpath; return f; }
    }

#endif

    if (mode[0] != 'r')
    {
        f = OpenFile(emudirpath, mode);
        if (f) { delete[] emudirpath; return f; }
    }

    delete[] emudirpath;
    return NULL;
}