// ----------------------------------------------------------------------------- // Check if the property list is valid and extract necessary properties // @param aInvalidParameterIndex if invalid, contains the index of the property. // Undefined, if it is valid. // @return if error, one of the error response code; otherwise EMTPRespCodeOK // ----------------------------------------------------------------------------- TMTPResponseCode CSendObject::VerifyObjectPropListL( TInt& aInvalidParameterIndex ) { PRINT( _L( "MM MTP => CSendObject::VerifyObjectPropListL" ) ); TMTPResponseCode responseCode( EMTPRespCodeOK ); const TInt count = iObjectPropList->NumberOfElements(); iObjectPropList->ResetCursor(); for ( TInt i = 0; i < count; i++ ) { const CMTPTypeObjectPropListElement& element( iObjectPropList->GetNextElementL() ); const TUint32 handle( element.Uint32L( CMTPTypeObjectPropListElement::EObjectHandle ) ); aInvalidParameterIndex = i; if ( handle != KMTPHandleNone ) { responseCode = EMTPRespCodeInvalidObjectHandle; break; } responseCode = CheckPropCodeL( element ); if ( responseCode != EMTPRespCodeOK ) { break; } responseCode = ExtractPropertyL( element ); if ( responseCode != EMTPRespCodeOK ) { break; } } PRINT1( _L( "MM MTP <= CSendObject::VerifyObjectPropListL, responseCode = 0x%x" ), responseCode ); return responseCode; }
void NetworkClient::private_checkResponse() { if ( !enableResponseCodeChecking_ ) { return; } int code = responseCode(); if ( ( !code || (code>= 400 && code<=499)) && errorString() != "Callback aborted" ) { (treatErrorsAsWarnings_ ? LOG(WARNING) : LOG(ERROR) ) << "Request to the URL '"<<m_url<<"' failed. \r\nResponse code: "<<code<<"\r\n"<<errorString()<<"\r\n"<<internalBuffer; } }
inline bool KMSmtpClient::waitAndCheckResponse( int captureCode, KMAbstractMailClient::MailClientError failedError) { //Wait for server response. if(!waitForResponse()) { //Server doesn't response. return false; } qDebug()<<"Response code is:"<<responseCode()<<"Capture code is:"<<captureCode; // The response code needs to be 250. if(responseCode() != captureCode) { //Server error. emit clientError(failedError); //Failed to connect. return false; } //Connect and response correct. return true; }
// ----------------------------------------------------------------------------- // Extracts the file information from the object property list element // @param aElement an object property list element // @param aPropertyCode MTP property code for the element // @return MTP response code // ----------------------------------------------------------------------------- TMTPResponseCode CSendObject::ExtractPropertyL( const CMTPTypeObjectPropListElement& aElement ) { PRINT( _L ( "MM MTP => CSendObject::ExtractPropertyL" ) ); TMTPResponseCode responseCode( EMTPRespCodeOK ); switch ( aElement.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode ) ) { case EMTPObjectPropCodeObjectFileName: { const TDesC& fileName = aElement.StringL( CMTPTypeObjectPropListElement::EValue ); if ( !GetFullPathNameL( fileName ) ) { responseCode = EMTPRespCodeInvalidDataset; } } break; case EMTPObjectPropCodeProtectionStatus: { iProtectionStatus = aElement.Uint16L( CMTPTypeObjectPropListElement::EValue ); if ( iProtectionStatus != EMTPProtectionNoProtection && iProtectionStatus != EMTPProtectionReadOnly ) { responseCode = EMTPRespCodeParameterNotSupported; } } break; case EMTPObjectPropCodeDateModified: delete iDateMod; iDateMod = NULL; iDateMod = aElement.StringL( CMTPTypeObjectPropListElement::EValue ).AllocL(); // Cache it for further usage. break; default: // Only extract necessary properties which conform to SendObjectInfo. break; } PRINT1( _L( "MM MTP <= CSendObject::ExtractPropertyL, responseCode = 0x%x" ), responseCode ); return responseCode; }
auto_ptr<oadrPayload> RegisteredReport::generatePayload() { oadrRegisteredReportType::eiResponse_type eir(responseCode(), requestID()); if (responseDescription() != "") eir.responseDescription(responseDescription()); oadrRegisteredReportType request(eir); request.schemaVersion("2.0b"); request.venID(venID()); oadrSignedObject oso; oso.oadrRegisteredReport(request); auto_ptr<oadrPayload> payload(new oadrPayload(oso)); return payload; }
int main(void) { char * name=loadFile("name.txt"); char * buf= init(name); //get starting message int sockfd, numbytes; struct addrinfo hints, *servinfo, *p; int rv; char s[INET6_ADDRSTRLEN]; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((rv = getaddrinfo(HOST, PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("client: socket"); continue; } if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("client: connect"); continue; } break; } if (p == NULL) { fprintf(stderr, "client: failed to connect\n"); return 2; } inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s); freeaddrinfo(servinfo); // all done with this structure send(sockfd, buf, strlen(buf)+1, 0); char str[MAXDATASIZE]; if ((numbytes = recv(sockfd, str, MAXDATASIZE-1, 0)) == -1) { perror("recv"); exit(1); } str[numbytes] = '\0'; //Determine my player token char * temptok = strstr(strstr(strstr(str, "playerToken"), ":"), "\"")+1; char * tempend = strstr(temptok, "\""); tempend[0]=0; char * token=malloc(tempend-temptok+1); strcpy(token, temptok); tempend[0]='\"'; int res; while(1){ res=getTurn(buf, token, responseCode(str), resources(str), ships(str), errors(str), hits(str), actionResponses(str), pings(str)); if(res==1) break; if(res==2) { send(sockfd, buf, strlen(buf)+1, 0); } if ((numbytes = recv(sockfd, str, MAXDATASIZE-1, 0)) == -1) { perror("recv"); exit(1); } str[numbytes] = '\0'; } close(sockfd); free(buf); free(token); free(name); return 0; }
// ----------------------------------------------------------------------------- // CSendObject::SetObjectPropListL // Reserve object proplist into database // ----------------------------------------------------------------------------- // TMTPResponseCode CSendObject::SetObjectPropListL() { PRINT( _L( "MM MTP => CSendObject::SetObjectPropListL" ) ); TMTPResponseCode responseCode( EMTPRespCodeOK ); const TUint count( iObjectPropList->NumberOfElements() ); iObjectPropList->ResetCursor(); for ( TInt i = 0; i < count; i++ ) { const CMTPTypeObjectPropListElement& element( iObjectPropList->GetNextElementL() ); TUint16 propertyCode = element.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode ); TUint16 dataType = element.Uint16L( CMTPTypeObjectPropListElement::EDatatype ); PRINT2( _L( "MM MTP <> SetObjectPropListL propertyCode = 0x%x, dataType = 0x%x" ), propertyCode, dataType ); switch ( propertyCode ) { case EMTPObjectPropCodeStorageID: case EMTPObjectPropCodeObjectFormat: case EMTPObjectPropCodeObjectSize: case EMTPObjectPropCodeParentObject: case EMTPObjectPropCodePersistentUniqueObjectIdentifier: // Do nothing for those properties are already set. break; case EMTPObjectPropCodeNonConsumable: iReceivedObjectInfo->SetUint( CMTPObjectMetaData::ENonConsumable, element.Uint8L( CMTPTypeObjectPropListElement::EValue ) ); break; case EMTPObjectPropCodeDateAdded: case EMTPObjectPropCodeDateCreated: case EMTPObjectPropCodeObjectFileName: // Do nothing for read-only properties /* spec: * Object properties that are get-only (0x00 GET) * should accept values during object creation by * way of the SendObjectPropList command. */ break; case EMTPObjectPropCodeDateModified: case EMTPObjectPropCodeProtectionStatus: // Already done in AddMediaToStore, it's not necessary to set it again. break; case EMTPObjectPropCodeName: case EMTPObjectPropCodeAlbumArtist: { CMTPTypeString* stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) );// + stringData responseCode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapper( iDpConfig, propertyCode, *stringData, *iReceivedObjectInfo ); CleanupStack::PopAndDestroy( stringData );// - stringData } break; default: { responseCode = iDpConfig.PropSettingUtility()->SetSpecificObjectPropertyL( iDpConfig, propertyCode, *iReceivedObjectInfo, element ); } break; } // end of switch } // end of for PRINT1( _L( "MM MTP <= CSendObject::SetObjectPropListL responseCode = 0x%x" ), responseCode ); return responseCode; }
// ----------------------------------------------------------------------------- // Validates the data type for a given property code. // @param aElement an object property list element // @param aPropertyCode MTP property code for the element // @return EMTPRespCodeOK if the combination is valid, or another MTP response code if not // ----------------------------------------------------------------------------- TMTPResponseCode CSendObject::CheckPropCodeL( const CMTPTypeObjectPropListElement& aElement ) { PRINT( _L( "MM MTP => CSendObject::CheckPropCodeL" ) ); TMTPResponseCode responseCode( EMTPRespCodeOK ); // Checking if the propCode is supported first then check its type const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( iObjectFormat ); TUint16 propCode = aElement.Uint16L( CMTPTypeObjectPropListElement::EPropertyCode ); TUint16 dataType = aElement.Uint16L( CMTPTypeObjectPropListElement::EDatatype ); PRINT2( _L( "MM MTP => CSendObject::CheckPropCodeL propCode = 0x%x, dataType = 0x%x" ), propCode, dataType ); responseCode = EMTPRespCodeInvalidObjectPropCode; const TInt count = properties->Count(); for ( TInt i = 0; i < count; i++ ) { if ( ( *properties )[i] == propCode ) { responseCode = EMTPRespCodeOK; break; } } if ( responseCode != EMTPRespCodeOK ) return responseCode; // TODO: abstractmedia and media dp have different supported propCode, need check common prop code and check others in dp derived processors. // also need to check if the propCode is supported switch ( propCode ) { case EMTPObjectPropCodeStorageID: if ( dataType != EMTPTypeUINT32 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } else if ( iStorageId != aElement.Uint32L( CMTPTypeObjectPropListElement::EValue ) ) { responseCode = EMTPRespCodeInvalidDataset; } break; case EMTPObjectPropCodeObjectFormat: if ( dataType != EMTPTypeUINT16 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } else if ( iObjectFormat != aElement.Uint16L( CMTPTypeObjectPropListElement::EValue ) ) { responseCode = EMTPRespCodeInvalidDataset; } break; case EMTPObjectPropCodeObjectSize: if ( dataType != EMTPTypeUINT64 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } else if ( iObjectSize != aElement.Uint64L( CMTPTypeObjectPropListElement::EValue ) ) { responseCode = EMTPRespCodeInvalidDataset; } PRINT1(_L("MM MTP => CSendObject::CheckPropCodeL Checking ObjectSize %d"), responseCode ); break; case EMTPObjectPropCodeParentObject: if ( dataType != EMTPTypeUINT32 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } else if ( ( iParentHandle != aElement.Uint32L( CMTPTypeObjectPropListElement::EValue ) ) || ( KMTPHandleNone != aElement.Uint32L( CMTPTypeObjectPropListElement::EValue ) ) ) // iParentHandle might be changed in CheckRequestL { responseCode = EMTPRespCodeInvalidDataset; } break; case EMTPObjectPropCodePersistentUniqueObjectIdentifier: // read-only if ( dataType != EMTPTypeUINT128 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } break; case EMTPObjectPropCodeProtectionStatus: if ( dataType != EMTPTypeUINT16 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } break; case EMTPObjectPropCodeDateCreated: case EMTPObjectPropCodeDateModified: case EMTPObjectPropCodeObjectFileName: case EMTPObjectPropCodeName: if ( dataType != EMTPTypeString ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } break; case EMTPObjectPropCodeNonConsumable: if ( dataType != EMTPTypeUINT8 ) { responseCode = EMTPRespCodeInvalidObjectPropFormat; } break; default: // check types of DP specific properties // TODO: Is there anything except datatype need to be checked? responseCode = MmMtpDpUtility::CheckPropType( propCode, dataType ); if ( responseCode == EMTPRespCodeAccessDenied ) { responseCode = EMTPRespCodeOK; } break; } PRINT1( _L( "MM MTP <= CSendObject::CheckPropCode, responseCode = 0x%x" ), responseCode ); return responseCode; }