Esempio n. 1
0
// @pymethod object|PyIEnumBackgroundCopyFiles|Next|Retrieves a specified number of items in the enumeration sequence.
PyObject *PyIEnumBackgroundCopyFiles::Next(PyObject *self, PyObject *args)
{
	long celt = 1;
	// @pyparm int|num|1|Number of items to retrieve.
	if ( !PyArg_ParseTuple(args, "|l:Next", &celt) )
		return NULL;

	IEnumBackgroundCopyFiles *pIEnumBackgroundCopyFiles = GetI(self);
	if ( pIEnumBackgroundCopyFiles == NULL )
		return NULL;

	IBackgroundCopyFile **rgVar = new IBackgroundCopyFile *[celt];
	if ( rgVar == NULL ) {
		PyErr_SetString(PyExc_MemoryError, "allocating result BackgroundCopyFiless");
		return NULL;
	}

	int i;
/*	for ( i = celt; i--; )
		// *** possibly init each structure element???
*/

	ULONG celtFetched = 0;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pIEnumBackgroundCopyFiles->Next(celt, rgVar, &celtFetched);
	PY_INTERFACE_POSTCALL;
	if (  HRESULT_CODE(hr) != ERROR_NO_MORE_ITEMS && FAILED(hr) )
	{
		delete [] rgVar;
		return PyCom_BuildPyException(hr,pIEnumBackgroundCopyFiles, IID_IEnumBackgroundCopyFiles);
	}

	PyObject *result = PyTuple_New(celtFetched);
	if ( result != NULL )
	{
		for ( i = celtFetched; i--; )
		{
			PyObject *ob = PyCom_PyObjectFromIUnknown(rgVar[i], IID_IBackgroundCopyFile, FALSE);
			if ( ob == NULL )
			{
				Py_DECREF(result);
				result = NULL;
				break;
			}
			PyTuple_SET_ITEM(result, i, ob);
		}
	}

/*	for ( i = celtFetched; i--; )
		// *** possibly cleanup each structure element???
*/
	delete [] rgVar;
	return result;
}
/**
 * For each file in the job, obtains the (final) HTTP headers received from the
 * remote server that hosts the files and then displays the HTTP headers.
 */
HRESULT
DisplayFileHeaders( _In_ IBackgroundCopyJob *Job )
{
    HRESULT hr;
    IEnumBackgroundCopyFiles *FileEnumerator;

    printf( "Individual file information.\n" );

    hr = Job->EnumFiles( &FileEnumerator );
    if( FAILED(hr) )
    {
        printf( "WARNING: Unable to obtain an IEnumBackgroundCopyFiles interface.\n");
        printf( "         No further information can be provided about the files in the job.\n");
    }
    else
    {
        ULONG Count;

        hr = FileEnumerator->GetCount( &Count );
        if( FAILED(hr) )
        {
            printf("WARNING: Unable to obtain a count of the number of files in the job.\n" );
            printf( "        No further information can be provided about the files in the job.\n");
        }
        else
        {
            for( ULONG i=0; i < Count; ++i )
            {
                IBackgroundCopyFile *TempFile;

                hr = FileEnumerator->Next(1, &TempFile, NULL);
                if( FAILED(hr) )
                {
                    printf("WARNING: Unable to obtain an IBackgroundCopyFile interface for the next file in the job.\n" );
                    printf( "        No further information can be provided about this file.\n");
                }
                else
                {
                    IBackgroundCopyFile5 *File;
                    hr = TempFile->QueryInterface( __uuidof( IBackgroundCopyFile5 ), (void **) &File );
                    if( FAILED(hr) )
                    {
                        printf("WARNING: Unable to obtain an IBackgroundCopyFile5 interface for the file.\n" );
                        printf( "        No further information can be provided about this file.\n");
                    }
                    else
                    {
                        LPWSTR RemoteFileName;
                        hr = File->GetRemoteName( &RemoteFileName );
                        if( FAILED(hr) )
                        {
                            printf("WARNING: Unable to obtain the remote file name for this file.\n" );
                        }
                        else
                        {
                            printf("HTTP headers for remote file '%ws'\n", RemoteFileName );
                            CoTaskMemFree( RemoteFileName );
                            RemoteFileName = NULL;
                        }

                        BITS_FILE_PROPERTY_VALUE Value;
                        hr = File->GetProperty(
                                        BITS_FILE_PROPERTY_ID_HTTP_RESPONSE_HEADERS,
                                        &Value
                                        );
                        if( FAILED(hr) )
                        {
                            printf("WARNING: Unable to obtain the HTTP headers for this file.\n" );
                        }
                        else
                        {
                            if(Value.String)
							{
								DisplayHeaders( Value.String );
								CoTaskMemFree( Value.String );
								Value.String = NULL;
							}
                        }

                        File->Release();
                        File = NULL;
                    }

                    TempFile->Release();
                    TempFile = NULL;
                }
            }
        }

        FileEnumerator->Release();
        FileEnumerator = NULL;
    }

    return S_OK;
}