williamr@2: /* williamr@2: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * Name : SdpMediaField.h williamr@2: * Part of : SDP Codec williamr@2: * Interface : SDK API, SDP Codec API williamr@2: * Version : 1.0 williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: #ifndef CSDPMEDIAFIELD_H williamr@2: #define CSDPMEDIAFIELD_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include "_sdpdefs.h" williamr@2: #include williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: class RReadStream; williamr@2: class RWriteStream; williamr@2: class CSdpConnectionField; williamr@2: class CSdpBandwidthField; williamr@2: class CSdpAttributeField; williamr@2: class CSdpKeyField; williamr@2: class CSdpFmtAttributeField; williamr@2: class CSdpCodecParseUtil; williamr@2: williamr@2: // CLASS DECLARATION williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: * williamr@2: * This class encapsulates the media description field and related media williamr@2: * specific subfields of the Session Description Protocol. williamr@2: * williamr@2: * The normative reference for correct formatting and values is williamr@2: * draft-ietf-mmusic-sdp-new-14 unless specified otherwise in williamr@2: * member documentation. The implementation supports this normative williamr@2: * reference, but does not enforce it fully. williamr@2: * williamr@2: * @lib sdpcodec.lib williamr@2: */ williamr@2: class CSdpMediaField : public CBase williamr@2: { williamr@2: williamr@2: public: williamr@2: williamr@2: williamr@2: public: // Constructors and destructor williamr@2: /** williamr@2: * Constructs a new media description field. williamr@2: * williamr@2: * @param aText A correctly formatted media field williamr@2: * terminated by a CRLF followed by zero or more media williamr@2: * attribute fields separated by a CRLF. williamr@2: * @param aRecurse If ETrue, attempts to construct also media williamr@2: * attributes following the CRLF terminating the media field. williamr@2: * @return a new instance. williamr@2: */ williamr@2: IMPORT_C static CSdpMediaField* DecodeL(const TDesC8& aText, williamr@2: TBool aRecurse = ETrue); williamr@2: williamr@2: /** williamr@2: * Constructs a new media description field and adds the pointer to williamr@2: * the cleanup stack. williamr@2: * williamr@2: * @param aText A correctly formatted media field williamr@2: * terminated by a CRLF followed by zero or more media williamr@2: * attribute fields separated by a CRLF. williamr@2: * @param aRecurse If ETrue, attempts to construct also media williamr@2: * attributes following the CRLF terminating the media field. williamr@2: * @return a new instance. williamr@2: */ williamr@2: IMPORT_C static CSdpMediaField* DecodeLC(const TDesC8& aText, williamr@2: TBool aRecurse = ETrue); williamr@2: williamr@2: /** williamr@2: * Constructs a new media description field. williamr@2: * The optional portcount component of the field is initialized to 1. williamr@2: * williamr@2: * @param aMedia A valid media type name. williamr@2: * @param aPort Port number. williamr@2: * @param aProtocol A valid media protocol name. williamr@2: * @param aFormatList A valid format list. williamr@2: * @return a new instance. williamr@2: */ williamr@2: IMPORT_C static CSdpMediaField* NewL(RStringF aMedia, williamr@2: TUint aPort, williamr@2: RStringF aProtocol, williamr@2: const TDesC8& aFormatList); williamr@2: williamr@2: /** williamr@2: * Constructs a new media description field and adds the pointer to williamr@2: * the cleanup stack. williamr@2: * The optional portcount component of the field is initialized to 1. williamr@2: * williamr@2: * @param aMedia A valid media type name. williamr@2: * @param aPort Port number. williamr@2: * @param aProtocol A valid media protocol name. williamr@2: * @param aFormatList A valid format list. williamr@2: * @return a new instance. williamr@2: */ williamr@2: IMPORT_C static CSdpMediaField* NewLC(RStringF aMedia, williamr@2: TUint aPort, williamr@2: RStringF aProtocol, williamr@2: const TDesC8& aFormatList); williamr@2: williamr@2: /** williamr@2: * Deletes the resources held by the instance. williamr@2: */ williamr@2: IMPORT_C ~CSdpMediaField(); williamr@2: williamr@2: public: // New functions williamr@2: /** williamr@2: * Outputs the field formatted according to SDP syntax and including williamr@2: * the terminating CRLF. Optionally output also the related media williamr@2: * level fields. williamr@2: * williamr@2: * @param aStream Stream used for output. On return the williamr@2: * stream includes correctly formatted media field with williamr@2: * media part fields if aRecurse is defined to ETrue. williamr@2: * @param aRecurse Flag to specify whether to output media williamr@2: * attributes also (ETrue) or only the media field (EFalse). williamr@2: */ williamr@2: IMPORT_C void williamr@2: EncodeL(RWriteStream& aStream, TBool aRecurse = ETrue) const; williamr@2: williamr@2: /** williamr@2: * Creates a new instance that is equal to the target. williamr@2: * Optionally also related subfields are cloned. williamr@2: * williamr@2: * @param aRecurse Flag to specify whether to clone subfields williamr@2: * also (ETrue) or only the media field (EFalse). williamr@2: * @return a new instance. williamr@2: */ williamr@2: IMPORT_C CSdpMediaField * CloneL(TBool aRecurse = ETrue) const; williamr@2: williamr@2: /** williamr@2: * Compares this instance to another for equality. Subfields are williamr@2: * included in the comparison if present. williamr@2: * williamr@2: * @param aObj The instance to compare to. williamr@2: * @return ETrue if equal, EFalse if not. williamr@2: */ williamr@2: IMPORT_C TBool operator == (const CSdpMediaField& aObj) const; williamr@2: williamr@2: /** williamr@2: * Checks the consistency between the media field and it's subfields. williamr@2: * In particular, this function checks that each format specific williamr@2: * attribute is related to a format in the format list of the williamr@2: * media field. williamr@2: * williamr@2: * @return ETrue if media description is consistent and EFalse if not. williamr@2: */ williamr@2: IMPORT_C TBool IsValid() const; williamr@2: williamr@2: /** williamr@2: * Gets the media type. williamr@2: * williamr@2: * @return The media type. williamr@2: */ williamr@2: IMPORT_C RStringF Media() const; williamr@2: williamr@2: /** williamr@2: * Sets the media type. williamr@2: * williamr@2: * @param aMedia The media type. williamr@2: * @leave KErrSdpCodecMediaField if aMedia is not valid character williamr@2: */ williamr@2: IMPORT_C void SetMediaL(RStringF aMedia); williamr@2: williamr@2: /** williamr@2: * Gets the media protocol. williamr@2: * williamr@2: * @return The media protocol. williamr@2: */ williamr@2: IMPORT_C RStringF Protocol() const; williamr@2: williamr@2: /** williamr@2: * Sets the media protocol. williamr@2: * williamr@2: * @param aProtocol The media protocol. williamr@2: * @leave KErrSdpCodecMediaField if williamr@2: * aProtocol containing two elements divided by slash are not williamr@2: * valid tokens. williamr@2: */ williamr@2: IMPORT_C void SetProtocolL(RStringF aProtocol); williamr@2: williamr@2: /** williamr@2: * Gets the port number. williamr@2: * williamr@2: * @return The port number. williamr@2: */ williamr@2: IMPORT_C TUint Port() const; williamr@2: williamr@2: /** williamr@2: * Sets the port number. williamr@2: * williamr@2: * @param aPort The port number. williamr@2: * @leave KErrSdpCodecMediaField if port is not valid number as williamr@2: * defined in draft-ietf-mmusic-sdp-new-14 williamr@2: */ williamr@2: IMPORT_C void SetPortL(TUint aPort); williamr@2: williamr@2: /** williamr@2: * Gets the port count. williamr@2: * williamr@2: * @return The port count. williamr@2: */ williamr@2: IMPORT_C TUint PortCount() const; williamr@2: williamr@2: /** williamr@2: * Sets the port count. williamr@2: * williamr@2: * @param aCount The port count that must be greater than zero. williamr@2: * @leave KErrSdpCodecMediaField if aCount equals to zero. williamr@2: */ williamr@2: IMPORT_C void SetPortCountL(TUint aCount); williamr@2: williamr@2: /** williamr@2: * Gets the format list. williamr@2: * williamr@2: * @return The format list. williamr@2: */ williamr@2: IMPORT_C const TDesC8& FormatList() const; williamr@2: williamr@2: /** williamr@2: * Sets the format list. williamr@2: * The format list should contain one or more format tokens separated williamr@2: * by a single whitespace character. williamr@2: * williamr@2: * @param aValue A valid format list. williamr@2: * @leave KErrSdpCodecMediaField if aValue contains invalid tokens williamr@2: */ williamr@2: IMPORT_C void SetFormatListL(const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Return the media level info field value. williamr@2: * williamr@2: * @return The value or an empty descriptor if not present. williamr@2: */ williamr@2: IMPORT_C const TDesC8& Info() const; williamr@2: williamr@2: /** williamr@2: * Sets the media level info field value. williamr@2: * williamr@2: * @param aValue A valid info field value. williamr@2: * @leave KErrSdpCodecMediaInfoField if aValue is not KNullDesC8 or williamr@2: * aValue includes invalid byte strings (´\0´, ´\n´, ´\r´). williamr@2: */ williamr@2: IMPORT_C void SetInfoL(const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Gets the media level encryption key field. williamr@2: * Note, that the ownership is not transferred and williamr@2: * the instance must not be deleted by the caller. williamr@2: * williamr@2: * @return Encryption key field or null if not present. williamr@2: */ williamr@2: IMPORT_C CSdpKeyField* Key(); williamr@2: williamr@2: /** williamr@2: * Gets the media level encryption key field. williamr@2: * williamr@2: * @return Encryption key field or null if not present. williamr@2: */ williamr@2: IMPORT_C const CSdpKeyField* Key() const; williamr@2: williamr@2: /** williamr@2: * Sets or removes the media level encryption key field. williamr@2: * williamr@2: * @param aObj The new key field or null if field is williamr@2: * to be removed. Ownership of the referenced object williamr@2: * is transferred to the media field instance. williamr@2: */ williamr@2: IMPORT_C void SetKey(CSdpKeyField* aObj); williamr@2: williamr@2: /** williamr@2: * Gets the set of media format level attributes. williamr@2: * This array is used directly for element insertion and removal. williamr@2: * williamr@2: * The objects referenced from the array are owned by the media williamr@2: * field instance and must not be deleted. An object can be williamr@2: * removed from the media description by setting the corresponding williamr@2: * element to zero. By doing so, the calling party receives ownership williamr@2: * of the removed object. williamr@2: * williamr@2: * @return The set of media format level attributes. williamr@2: */ williamr@2: IMPORT_C RPointerArray& FormatAttributeFields(); williamr@2: williamr@2: /** williamr@2: * Gets the set of media level, format independent attributes. williamr@2: * This array is used directly for element insertion and removal. williamr@2: * williamr@2: * The objects referenced from the array are owned by the media williamr@2: * field instance and must not be deleted. An object can be williamr@2: * removed from the media description by setting the corresponding williamr@2: * element to zero. By doing so, the calling party receives ownership williamr@2: * of the removed object. williamr@2: * williamr@2: * @return The set of media level attributes. williamr@2: */ williamr@2: IMPORT_C RPointerArray& AttributeFields(); williamr@2: williamr@2: /** williamr@2: * Gets the set of media level bandwidth fields. williamr@2: * This array is used directly for element insertion and removal. williamr@2: * williamr@2: * The objects referenced from the array are owned by the media williamr@2: * field instance and must not be deleted. An object can be williamr@2: * removed from the media description by setting the corresponding williamr@2: * element to zero. By doing so, the calling party receives ownership williamr@2: * of the removed object. williamr@2: * williamr@2: * @return The set of media level bandwidth fields. williamr@2: */ williamr@2: IMPORT_C RPointerArray& BandwidthFields(); williamr@2: williamr@2: /** williamr@2: * Gets the set of media level connection fields. williamr@2: * This array is used directly for element insertion and removal. williamr@2: * williamr@2: * The objects referenced from the array are owned by the media williamr@2: * field instance and must not be deleted. An object can be williamr@2: * removed from the media description by setting the corresponding williamr@2: * element to zero. By doing so, the calling party receives ownership williamr@2: * of the removed object. williamr@2: * williamr@2: * @return The set of media level connection fields. williamr@2: */ williamr@2: IMPORT_C RPointerArray& ConnectionFields(); williamr@2: williamr@2: /** williamr@2: * Removes a specific format from the media description. williamr@2: * The function will remove the named format from the format list if williamr@2: * found and then delete all format level attributes of type williamr@2: * CSdpFmtAttributeField related to the removed format. williamr@2: * williamr@2: * @param aFormat The name of the format to remove. williamr@2: */ williamr@2: IMPORT_C void RemoveFormatL(const TDesC8& aFormat); williamr@2: williamr@2: /** williamr@2: * Removes all formats except one from the media description. williamr@2: * The function will set the format list to only contain the one williamr@2: * format to keep and then delete all format level attributes that williamr@2: * are related to the removed formats. If the format is not found williamr@2: * from the format list, it is added there. If there are no format williamr@2: * level attributes for the specified format, the format level williamr@2: * attribute set will be empty. williamr@2: * williamr@2: * @param aFormat The name of the format to keep after williamr@2: * removing all others. williamr@2: */ williamr@2: IMPORT_C void KeepFormatL(const TDesC8& aFormat); williamr@2: williamr@2: /** williamr@2: * Sets this media description into rejected state. williamr@2: * The rejected state is defined by the offer/answer model in williamr@2: * RFC3264. The function sets the port number to 0 and removes williamr@2: * all formats except one. The remaining format is determined williamr@2: * by the implementation. williamr@2: */ williamr@2: IMPORT_C void RejectMedia(); williamr@2: williamr@2: public: williamr@2: /** williamr@2: * Shows if contact is present williamr@2: * williamr@2: * @return ETrue if contact present, otherwise EFalse williamr@2: */ williamr@2: TBool IsContactPresent() const; williamr@2: williamr@2: /** williamr@2: * Externalizes the object to stream williamr@2: * williamr@2: * @param aStream Stream where the object's state will be stored williamr@2: */ williamr@2: void ExternalizeL(RWriteStream& aStream) const; williamr@2: williamr@2: /** williamr@2: * Creates object from the stream data williamr@2: * williamr@2: * @param aStream Stream where the object's state will be read williamr@2: * @return Initialized object williamr@2: */ williamr@2: static CSdpMediaField* InternalizeL(RReadStream& aStream); williamr@2: williamr@2: private: williamr@2: CSdpMediaField(); williamr@2: void ConstructL(); williamr@2: void ConstructL(TBool aRecurse); williamr@2: void ConstructL(RStringF aMedia, TUint aPort, RStringF aProtocol, williamr@2: const TDesC8& aFormatList); williamr@2: williamr@2: void ConstructL(const CSdpMediaField& aSdpMediaField); williamr@2: void DoInternalizeL(RReadStream& aStream); williamr@2: void ParseL (const TDesC8& aText); williamr@2: void ParseMediaL(); williamr@2: void ParseInformationL(); williamr@2: void ParseConnectionL(); williamr@2: void ParseBandwithL(); williamr@2: void ParseEncryptionKeyL(); williamr@2: void ParseAttributeFieldsL(); williamr@2: TDesC8& GetTokenFromStreamL(RReadStream& aStream); williamr@2: williamr@2: williamr@2: CSdpMediaField(const CSdpMediaField&); // Hidden. williamr@2: CSdpMediaField& operator = (const CSdpMediaField&); // Hidden williamr@2: williamr@2: private: // Data williamr@2: HBufC8* iInfo; williamr@2: CSdpKeyField* iSdpKeyField; williamr@2: RArray iElementArray; williamr@2: RStringPool iPool; williamr@2: TBool iRecurse; williamr@2: RStringF iMedia; williamr@2: RStringF iProtocol; williamr@2: TUint iPort; williamr@2: TUint iPortCount; williamr@2: HBufC8* iFormatList; williamr@2: RPointerArray* iBandwidthFields; williamr@2: RPointerArray* iAttributeFields; williamr@2: RPointerArray* iConnectionFields; williamr@2: RPointerArray* iFmtAttrFields; williamr@2: HBufC8* iToken; williamr@2: CSdpCodecParseUtil* iSdpCodecParseUtil; williamr@2: }; williamr@2: williamr@2: #endif // CSDPMEDIAFIELD_H