Example #1
0
int
md_get_uint32le(struct mdchain *mdp, u_int32_t *x)
{
	u_int32_t v;
	int error;

	error = md_get_uint32(mdp, &v);
	*x = letohl(v);
	return error;
}
Example #2
0
void
smb2fs_smb_file_id_check(struct smb_share *share, uint64_t ino,
                         char *network_name, uint32_t network_name_len)
{
    uint32_t no_file_ids = 0;
    
    /*
     * Check to see if server supports File IDs or not
     * Watch out because the ".." in every Query Dir response has File ID of 0
     * which is supposed to be illegal. Sigh.
     */
    if (SSTOVC(share)->vc_misc_flags & SMBV_HAS_FILEIDS) {
        if (ino == 0) {
            no_file_ids = 1;
            
            if ((network_name != NULL) && (network_name_len > 0)) {
                if ((network_name_len == 2 &&
                     letohs(*(uint16_t * ) network_name) == 0x002e) ||
                    (network_name_len == 4 &&
                     letohl(*(uint32_t *) network_name) == 0x002e002e)) {
                        /*
                         * Its the ".." dir so allow the File ID of 0. "." and ".."
                         * dirs are ignored by smbfs_findnext so we can safely leave
                         * their fa_ino to be 0
                         */
                        no_file_ids = 0;
                    }
            }
        }
    }
    
    if (no_file_ids == 1) {
        SMBDEBUG("Server does not support File IDs \n");
        SSTOVC(share)->vc_misc_flags &= ~SMBV_HAS_FILEIDS;
    }
}
// Advances the mCurrentChunk to the next data chunk within the stream
UtlBoolean StreamWAVFormatDecoder::nextDataChunk(ssize_t& iLength)
{
   UtlBoolean bSuccess = FALSE ;
   ssize_t iRead ;
   char Header[128];
   uint32_t blockSize=0;  // 4 byte value in WAV file
   ssize_t iCurrentPosition ;
   iLength = 0 ;

   StreamDataSource* pDataSource = getDataSource() ;
   if (pDataSource != NULL)
   {
      while (!mbEnd && pDataSource->read((char*) Header, 4, iRead) == OS_SUCCESS)
      {
         pDataSource->getPosition(iCurrentPosition);
         if (iCurrentPosition == 4 && memcmp(Header, MpWaveFileFormat, 4) != 0)
         {
             //if this is true, then this file is not a wav, since
             //all wave files start with RIFF.
             mbEnd = TRUE;
             iLength = 0;

             // Search to see if this is a 404 error.
             pDataSource->read((char*) Header + 4, 123, iRead);
             Header[127] = '\0';
             if (strstr(Header, "404 Not Found") != NULL)
                syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (404 Not Found).)");
             else
                syslog(FAC_STREAMING, PRI_ERR,
                       "StreamWAVFormatDecoder::nextDataChunk (%s not detected.)",
                       MpWaveFileFormat
                       );

             // Just return successful with zero data read.
             return TRUE;
         }
         else
         if (memcmp(Header, MpWaveFileFormat, 4) == 0)
         {
             //just read the block size
            if (pDataSource->read((char*) &blockSize, sizeof(blockSize), iRead) != OS_SUCCESS)
            {
                syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (Error reading block size!)");
                break;
            }

         }
         else
         if (memcmp(Header, "WAVE", 4) == 0)
             ; //do nothing, doesn't even have block size
         else
         if (memcmp(Header, "fmt ", 4) == 0)
         {

            FORMATChunkInfo formatChunkInfo;
            if (pDataSource->read((char*) &blockSize, sizeof(blockSize), iRead) == OS_SUCCESS)
            {
                blockSize = letohl(blockSize);

                //save the current position, well need it for the jump
                if (pDataSource->getPosition(iCurrentPosition) != OS_SUCCESS)
                {
                   break;
                }

                if (pDataSource->read((char*) &formatChunkInfo, sizeof(formatChunkInfo), iRead) == OS_SUCCESS)
                {
                    //Make sure the read integer values are in the host byte order
                    formatChunkInfo.formatTag = letohs(formatChunkInfo.formatTag);
                    formatChunkInfo.nChannels = letohs(formatChunkInfo.nChannels);
                    formatChunkInfo.nSamplesPerSec = letohl(formatChunkInfo.nSamplesPerSec);
                    formatChunkInfo.nAvgBytesPerSec = letohl(formatChunkInfo.nAvgBytesPerSec);
                    formatChunkInfo.nBlockAlign = letohs(formatChunkInfo.nBlockAlign);
                    formatChunkInfo.nBitsPerSample = letohs(formatChunkInfo.nBitsPerSample);
                    // for streaming, we currently only support one format:
                    // 16 bit, 8khz, signed.
                    if (formatChunkInfo.nSamplesPerSec != 8000 || formatChunkInfo.nBitsPerSample != 16 ||
                        formatChunkInfo.nChannels != 1)
                    {
                        syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (File is not 16 bit, 8khz, mono, signed format!)");
                         mbEnd = TRUE;
                         break;
                    }

                    memcpy(&mFormatChunk, &formatChunkInfo, sizeof(formatChunkInfo)) ;
                    iLength = blockSize ;

                    //now move to next block
                    if (pDataSource->seek(iCurrentPosition + blockSize) != OS_SUCCESS)
                    {
                       // Kick out if we cannot seek
                       syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (Error seeking past block \"fmt\"!)");
                       break ;
                    }
                }
                else
                {
                    syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (Error reading block \"fmt\"!)");
                    break;
                }
            }
            else
            {
                syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (Error reading block size of fmt chunk)");
                break;
            }
             //we won't set true yet, because we'd like to get one block of data first
         }
         else
         if (memcmp(Header, "data", 4) == 0)
         {
            if (pDataSource->read((char*) &blockSize, sizeof(blockSize), iRead) == OS_SUCCESS)
            {
                 iLength = letohl(blockSize);
                 bSuccess = TRUE ;
                 break ;
            }
         }
         else
         {
            // Unsupported chunk, advance to the next one...
            //just read the block size & block
            if (pDataSource->read((char*) &blockSize, sizeof(blockSize), iRead) == OS_SUCCESS)
            {
                char tmpbuf[16000];
                int  totalLeftToRead, bytesToRead;

                blockSize = letohl(blockSize);
                for (totalLeftToRead = blockSize; totalLeftToRead > 0; totalLeftToRead -= iRead )
                {
                    bytesToRead = sizeof(tmpbuf);
                    if (totalLeftToRead < bytesToRead)
                    {
                        bytesToRead = totalLeftToRead;
                    }
                    if (pDataSource->read(tmpbuf, bytesToRead, iRead) != OS_SUCCESS)
                    {
                        syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (Error reading block data)");
                        break;
                    }
                }
            }
            else
            {
                syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (Error reading block size of block)");
                break;
            }
         }
      }


       //if we haven't reached the end of the stream and we are still not success
       //then fire the decoding error
       ssize_t currentPosition;
       ssize_t streamLength;

       pDataSource->getLength(streamLength);
       pDataSource->getPosition(currentPosition);

       if (!bSuccess && (currentPosition < streamLength || streamLength == 0))
       {
           syslog(FAC_STREAMING, PRI_ERR, "StreamWAVFormatDecoder::nextDataChunk (FireEvent DecodingErrorEvent)");
          fireEvent(DecodingErrorEvent) ;
       }
   }


   return bSuccess ;
}