Exemplo n.º 1
0
ULONG64 GetOSVersion()
{
	ULONG32 osMajorVersion, osMinorVersion;
	ULONG64 address =  GetPebAddress();
	if (IsTarget64())
	{
		if (GetFieldValue(address, "ntdll!_PEB", "OSMajorVersion", osMajorVersion) != 0)
		{
			dprintf("read OSMajorVersion failed\n");
			return 0;
		}
		if (GetFieldValue(address, "ntdll!_PEB", "OSMinorVersion", osMinorVersion) != 0)
		{
			dprintf("read OSMinorVersion failed\n");
			return 0;
		}
	}
	else
	{
		ULONG cb;
		if (!READMEMORY(address + 0xa4, osMajorVersion))
		{
			dprintf("read OSMajorVersion failed\n");
			return 0;
		}
		if (!READMEMORY(address + 0xa8, osMinorVersion))
		{
			dprintf("read OSMinorVersion failed\n");
			return 0;
		}
	}
	return (((ULONG64)osMajorVersion << 32) | osMinorVersion);
}
Exemplo n.º 2
0
/**********************************************
 SetEnv(): Convert field=value pairs into
 variables: A and Akey.
 **********************************************/
void    SetEnv  (char *S)
{
  char Field[256];
  char Value[1024];
  int GotOther=0;
  char *OrigS;

  OrigS=S;
  Akey=-1;
  memset(A,'\0',sizeof(A));

  while(S && (S[0] != '\0'))
    {
    S = GetFieldValue(S,Field,256,Value,1024);
    if (Value[0] != '\0')
	{
	if (!strcasecmp(Field,"akey")) Akey=atoi(Value);
	else if (!strcasecmp(Field,"a")) strncpy(A,Value,sizeof(A));
	else GotOther=1;
	}
    }

  if (GotOther || (Akey < 0) || (A[0]=='\0'))
    {
    printf("ERROR: Data is in an unknown format.\n");
    printf("LOG: Unknown data: '%s'\n",OrigS);
    fflush(stdout);
    DBclose(DB);
    exit(-1);
    }
} /* SetEnv() */
Exemplo n.º 3
0
	const U32 Packet::GetPacketID() const
	{
		U32 packetID;

		GetFieldValue("packetID", packetID);

		return packetID;
	}
Exemplo n.º 4
0
/**
 * If any changes have been made to this component,
 * they are now applied to the schematic component
 */
void BOM_TABLE_COMPONENT::ApplyFieldChanges()
{
    for( auto& unit : Units )
    {
        auto cmp = unit.GetComp();

        if( !cmp )
            continue;

        // Iterate over each column
        SCH_FIELD* field;

        for( auto& column : m_columnList->Columns )
        {
            if( column && HasValueChanged( column ) )
            {
                wxString value = GetFieldValue( column->Id() );

                switch( column->Id() )
                {
                // Ignore read-only fields
                case BOM_COL_ID_REFERENCE:
                case BOM_COL_ID_QUANTITY:
                    continue;

                // Special field considerations
                case BOM_COL_ID_FOOTPRINT:
                    field = cmp->GetField( FOOTPRINT );
                    break;

                case BOM_COL_ID_VALUE:
                    field = cmp->GetField( VALUE );
                    break;
                case BOM_COL_ID_DATASHEET:
                    field = cmp->GetField( DATASHEET );
                    break;

                default:
                    // Find the field by name (but ignore default fields)
                    field = cmp->FindField( column->Title(), false );
                    break;
                }

                // New field needs to be added?
                if( !field && !value.IsEmpty() )
                {
                    SCH_FIELD newField( wxPoint( 0, 0 ), -1, cmp, column->Title() );
                    field = cmp->AddField( newField );
                }

                if( field )
                {
                    field->SetText( value );
                }
            }
        }
    }
}
Exemplo n.º 5
0
bool BOM_FIELD_VALUES::HasValueChanged( unsigned int aFieldId) const
{
    wxString currentValue, backupValue;

    GetFieldValue( aFieldId, currentValue );
    GetBackupValue( aFieldId, backupValue );

    return currentValue.Cmp( backupValue ) != 0;
}
Exemplo n.º 6
0
void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
                                     const CFX_WideString& parent_name,
                                     FX_BOOL bNotify,
                                     int nLevel) {
  CFX_WideString name;
  if (!parent_name.IsEmpty())
    name = parent_name + L".";

  name += pFieldDict->GetUnicodeTextBy("T");
  CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
  if (pKids) {
    for (size_t i = 0; i < pKids->GetCount(); i++) {
      CPDF_Dictionary* pKid = pKids->GetDictAt(i);
      if (!pKid)
        continue;
      if (nLevel <= nMaxRecursion)
        FDF_ImportField(pKid, name, bNotify, nLevel + 1);
    }
    return;
  }
  if (!pFieldDict->KeyExist("V"))
    return;

  CPDF_FormField* pField = m_pFieldTree->GetField(name);
  if (!pField)
    return;

  CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding);
  int iType = pField->GetFieldType();
  if (bNotify && m_pFormNotify) {
    int iRet = 0;
    if (iType == FIELDTYPE_LISTBOX)
      iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
    else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
      iRet = m_pFormNotify->BeforeValueChange(pField, csWValue);

    if (iRet < 0)
      return;
  }

  pField->SetValue(csWValue);
  CPDF_FormField::Type eType = pField->GetType();
  if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) &&
      pFieldDict->KeyExist("Opt")) {
    pField->m_pDict->SetAt(
        "Opt", pFieldDict->GetDirectObjectBy("Opt")->CloneDirectObject());
  }

  if (bNotify && m_pFormNotify) {
    if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON)
      m_pFormNotify->AfterCheckedStatusChange(pField);
    else if (iType == FIELDTYPE_LISTBOX)
      m_pFormNotify->AfterSelectionChange(pField);
    else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
      m_pFormNotify->AfterValueChange(pField);
  }
}
Exemplo n.º 7
0
NS_IMETHODIMP nsImportFieldMap::GetFieldValueByDescription(nsIAbCard *card, const PRUnichar *fieldDesc, PRUnichar **_retval)
{
    NS_PRECONDITION(fieldDesc != nsnull, "null ptr");
  if (!fieldDesc)
    return NS_ERROR_NULL_POINTER;
  PRInt32 i = FindFieldNum( fieldDesc);
  if (i == -1)
    return NS_ERROR_FAILURE;
  return GetFieldValue( card, i, _retval);
}
Exemplo n.º 8
0
/**
 * Get the value of a particular item in the model
 */
void BOM_TABLE_MODEL::GetValue( wxVariant& aVariant, const wxDataViewItem& aItem,
                                unsigned int aFieldId ) const
{
    auto row = ItemToRow( aItem );

    if( row )
    {
        aVariant = row->GetFieldValue( aFieldId );
    }
}
/**
* Description:  DecodePacket().     解析RTSP包
* @param  [in]  strPacket   RTSP包
* @param  [out] stResult    解析结果
* @return       long.   返回码
*/
long CRtspPacket::DecodePacket
(
    IN  const string&           strPacket,
    OUT RTSP::DECODE_RESULT&    stResult
)const
{
    //long lResult = RTSP::RET_CODE_OK;

    string strFirstHeader;
    string strField;

    //获取首行首字段和头域内容
    long lResult = GetFirstLine(strPacket, strFirstHeader, strField);
    if (RTSP::RET_CODE_OK != lResult)
    {
        return lResult;
    }

    //响应消息直接返回
    if (0 == strFirstHeader.compare(RTSP::RTSP_VERSION))
    {
        stResult.ulMsgType = RTSP::MSG_TYPE_RESP;

        //获取RTP-Info,只有NAT穿越响应消息才有
        (void)GetRtpInfo(strField, stResult);
    
        return RTSP::RET_CODE_OK;
    }
    //只解析SET_PARAMETER消息
    else if (0 != strFirstHeader.compare("SET_PARAMETER"))
    {
        return RTSP::RET_CODE_FAIL;
    }

    stResult.ulMsgType = RTSP::MSG_TYPE_SET_PARAMETER;

    //将头域内容的多行转为单行
    MuiltLineToOneLine(strField);

    //获取CSeq
    lResult = GetFieldValue(strField, "CSeq", stResult.strCSeq);
    if (RTSP::RET_CODE_OK != lResult)
    {
        return RTSP::RET_CODE_FAIL;
    }

    //获取播放信息类型
    lResult = GetPlayInfoType(strField, stResult.ulPlayInfoType);
    if (RTSP::RET_CODE_OK != lResult)
    {
        return RTSP::RET_CODE_FAIL;
    }

    return RTSP::RET_CODE_OK;
}
Exemplo n.º 10
0
bool BOM_TABLE_GROUP::GetAttr( unsigned int aFieldId, wxDataViewItemAttr& aAttr ) const
{
    if( GetFieldValue( aFieldId ).Cmp( ROW_MULT_ITEMS ) == 0 )
    {
        aAttr.SetItalic( true );
        aAttr.SetColour( ROW_COLOUR_MULTIPLE_ITEMS );
        return true;
    }

    return BOM_TABLE_ROW::GetAttr( aFieldId, aAttr );
}
Exemplo n.º 11
0
double OGRDODSSequenceLayer::GetFieldValueAsDouble( OGRDODSFieldDefn *poFDefn,
                                                    int nFeatureId )

{
    BaseType *poBT;

    poBT = GetFieldValue( poFDefn, nFeatureId, NULL );
    if( poBT == NULL )
        return 0.0;

    return BaseTypeToDouble( poBT );
}
Exemplo n.º 12
0
/**
* Description:  GetRtpInfo().  获取RTP-Info
* @param  [in]  strField        所有头域字符串
* @param  [out] stResult    解析结果
* @return       long.   返回码
*/
long CRtspPacket::GetRtpInfo
(
    IN  const string&           strField,
    OUT RTSP::DECODE_RESULT&    stResult
)const
{
    string strRtpInfo;
    //获取RTP-Info头域
    long lResult = GetFieldValue(strField, "RTP-Info", strRtpInfo);
    if (RTSP::RET_CODE_OK != lResult)
    {
        return RTSP::RET_CODE_FAIL;
    }

    //获取RTP-Info头域中第一个seq和rtptime
    string strRtpSeq;
    string strRtpTime;
    
    lResult = GetFieldValue(strRtpInfo, "seq", strRtpSeq, RTSP::SEMI_COLON, RTSP::EQUAL_SIGN);
    if (RTSP::RET_CODE_OK != lResult)
    {
        return RTSP::RET_CODE_FAIL;
    }

    lResult = GetFieldValue(strRtpInfo, "rtptime", strRtpTime, RTSP::SEMI_COLON, RTSP::EQUAL_SIGN);
    if (RTSP::RET_CODE_OK != lResult)
    {
        return RTSP::RET_CODE_FAIL;
    }

    stResult.bHasRtpInfo = 1;
    stResult.ulRtpSeq    = strtoul(strRtpSeq.c_str(), NULL, 0);
    stResult.ulRtpTime   = strtoul(strRtpTime.c_str(), NULL, 0);

    return RTSP::RET_CODE_OK;
}
Exemplo n.º 13
0
double tContour::Field(int x, int y)     /* evaluate funct if we must,  */
{
    double x1, y1;
    
    if (FnctData(x,y)->m_sTopLen != -1)  /* is it already in the array */
        return(FnctData(x,y)->m_dFnVal);

    /* not in the array, create new array element */
    x1 = m_pLimits[0]+m_dDx*x;
    y1 = m_pLimits[2]+m_dDy*y;
    FnctData(x,y)->m_sTopLen = 0;
    FnctData(x,y)->m_sBotLen = 0;
    FnctData(x,y)->m_sRightLen = 0;
    FnctData(x,y)->m_sLeftLen = 0;
    return (FnctData(x,y)->m_dFnVal = GetFieldValue(x1, y1));
}
Exemplo n.º 14
0
 bool Loop()
 {
    size_t row = 0;
    if (!(IsBOF() && IsEOF())) for (MoveFirst(); !IsEOF(); MoveNext(), row++)
    {
       //TRACE(_T("row %3d\n"), row);
       NewRecord();
       for (int i = 0; i < GetFieldCount(); i++)
       {
          COleVariant var;
    	   GetFieldValue(i, var);
          SaveField(i, var);
       }
       SaveRecord();
    }
    return true;
 }
Exemplo n.º 15
0
GInt32 HFAEntry::GetIntField( const char * pszFieldPath, CPLErr *peErr )

{
    GInt32 nIntValue = 0;

    if( !GetFieldValue( pszFieldPath, 'i', &nIntValue, NULL ) )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return 0;
    }

    if( peErr != NULL )
        *peErr = CE_None;

    return nIntValue;
}
Exemplo n.º 16
0
double HFAEntry::GetDoubleField( const char * pszFieldPath, CPLErr *peErr )

{
    double dfDoubleValue = 0;

    if( !GetFieldValue( pszFieldPath, 'd', &dfDoubleValue, NULL ) )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return 0.0;
    }

    if( peErr != NULL )
        *peErr = CE_None;

    return dfDoubleValue;
}
Exemplo n.º 17
0
const char *HFAEntry::GetStringField( const char * pszFieldPath, CPLErr *peErr,
                                      int *pnRemainingDataSize)

{
    char *pszResult = NULL;

    if( !GetFieldValue( pszFieldPath, 's', &pszResult, pnRemainingDataSize ) )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return NULL;
    }

    if( peErr != NULL )
        *peErr = CE_None;

    return pszResult;
}
Exemplo n.º 18
0
const char *HFAEntry::GetStringField( const char * pszFieldPath, CPLErr *peErr)

{
    char *pszResult = NULL;

    if( !GetFieldValue( pszFieldPath, 's', &pszResult ) )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return NULL;
    }
    else
    {
        if( peErr != NULL )
            *peErr = CE_None;

        return pszResult;
    }
}
Exemplo n.º 19
0
double HFAEntry::GetDoubleField( const char * pszFieldPath, CPLErr *peErr )

{
    void	*pRetData;

    pRetData = GetFieldValue( pszFieldPath, 'd' );
    if( pRetData == NULL )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return 0.0;
    }
    else
    {
        if( peErr != NULL )
            *peErr = CE_None;

        return *((double *) pRetData);
    }
}
Exemplo n.º 20
0
const char *HFAEntry::GetStringField( const char * pszFieldPath, CPLErr *peErr)

{
    void	*pRetData;

    pRetData = GetFieldValue( pszFieldPath, 's' );
    if( pRetData == NULL )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return NULL;
    }
    else
    {
        if( peErr != NULL )
            *peErr = CE_None;

        return (char *) pRetData;
    }
}
Exemplo n.º 21
0
int HFAEntry::GetIntField( const char * pszFieldPath, CPLErr *peErr )

{
    void	*pRetData;

    pRetData = GetFieldValue( pszFieldPath, 'i' );
    if( pRetData == NULL )
    {
        if( peErr != NULL )
            *peErr = CE_Failure;

        return 0;
    }
    else
    {
        if( peErr != NULL )
            *peErr = CE_None;

        return *((int *) pRetData);
    }
}
Exemplo n.º 22
0
ULONG32 GetNtGlobalFlag()
{
	ULONG32 ntGlobalFlag;
	ULONG64 address = GetPebAddress();
	if (IsTarget64())
	{
		if (GetFieldValue(address, "ntdll!_PEB", "NtGlobalFlag", ntGlobalFlag) != 0)
		{
			dprintf("read NtGlobalFlag failed\n");
			return 0;
		}
	}
	else
	{
		ULONG cb;
		if (!READMEMORY(address + 0x68, ntGlobalFlag))
		{
			dprintf("read NtGlobalFlag failed\n");
			return 0;
		}
	}
	return ntGlobalFlag;
}
Exemplo n.º 23
0
CORBA::Boolean
StorageHomeBaseImpl::objectExists( Pid* pPid )
	throw (CORBA::SystemException)
{
	DEBUG_OUT("StorageHomeBaseImpl::objectExists() is called");

	std::string strPid = convertPidToString(pPid);

	std::string strSqlSel;
	strSqlSel = "SELECT COUNT(*) FROM ";
	strSqlSel += strHomeName_;
	strSqlSel += " WHERE pid LIKE \'";
	strSqlSel += strPid;
	strSqlSel += "\';";
    
	if(Open(strSqlSel.c_str()))
	{
		long nID = -1;
		GetFieldValue(0, &nID);
		return (nID==1);
	}
	else
		return FALSE;
}
Exemplo n.º 24
0
std::vector<ModuleInfo> GetLoadedModules()
{
	std::vector<ModuleInfo> info;
	ULONG cb;
	ULONG64 pebAddress = GetPebAddress();
	if (IsTarget64())
	{
		ULONG64 ldr;
		if (GetFieldValue(pebAddress, "ntdll!_PEB", "Ldr", ldr) != 0)
		{
			dprintf("read Ldr failed\n");
			goto ERROR_EXIT;
		}

		ULONG offset;
		if (GetFieldOffset("ntdll!_PEB_LDR_DATA", "InMemoryOrderModuleList", &offset) != 0)
		{
			dprintf("GetFieldOffset(_PEB_LDR_DATA::InMemoryOrderModuleList) failed\n");
			goto ERROR_EXIT;
		}
		ULONG64 headAddress = ldr + offset;
		LIST_ENTRY64 inMemoryOrderModuleList;
		if (GetFieldValue(ldr, "ntdll!_PEB_LDR_DATA", "InMemoryOrderModuleList", inMemoryOrderModuleList) != 0)
		{
			dprintf("read InMemoryOrderModuleList failed\n");
			goto ERROR_EXIT;
		}

		LIST_ENTRY64 entry = inMemoryOrderModuleList;
		while (entry.Flink != headAddress)
		{
			ModuleInfo moduleInfo;
			ULONG64 address = entry.Flink;
			if (!READMEMORY(address, entry))
			{
				dprintf("read entry at %p failed\n", address);
				goto ERROR_EXIT;
			}

			// LDR_DATA_TABLE_ENTRY at address - sizeof(entry)
			ULONG64 dllBase, sizeOfImage;
			if (GetFieldValue(address - sizeof(entry), "ntdll!_LDR_DATA_TABLE_ENTRY", "DllBase", dllBase) != 0)
			{
				dprintf("read DllBase around %p failed\n", address - sizeof(entry));
				goto ERROR_EXIT;
			}
			moduleInfo.DllBase = dllBase;
			if (GetFieldValue(address - sizeof(entry), "ntdll!_LDR_DATA_TABLE_ENTRY", "SizeOfImage", sizeOfImage) != 0)
			{
				dprintf("read SizeOfImage around %p failed\n", address - sizeof(entry));
				goto ERROR_EXIT;
			}
			moduleInfo.SizeOfImage = sizeOfImage;

			// UNICODE_STRING
			struct
			{
				USHORT Length;
				USHORT MaximumLength;
				ULONG64 Buffer;
			} fullDllName;
			if (GetFieldValue(address - sizeof(entry), "ntdll!_LDR_DATA_TABLE_ENTRY", "FullDllName", fullDllName) != 0)
			{
				dprintf("read FullDllName around %p failed\n", address - sizeof(entry));
				goto ERROR_EXIT;
			}
			std::vector<wchar_t> unicode;
			unicode.resize(fullDllName.Length / sizeof(wchar_t));
			if (!ReadMemory(fullDllName.Buffer, &unicode[0], fullDllName.Length, &cb) || cb != fullDllName.Length)
			{
				dprintf("read unicode at %p %d failed\n", fullDllName.Buffer, (int)fullDllName.Length);
				goto ERROR_EXIT;
			}
		
			int written = WideCharToMultiByte(CP_ACP, 0, &unicode[0], fullDllName.Length / sizeof(wchar_t),
				moduleInfo.FullDllName, sizeof(moduleInfo.FullDllName), NULL, NULL);
			if (written < 0 || written >= sizeof(moduleInfo.FullDllName))
			{
				dprintf("WideCharToMultiByte returns %d\n", written);
				goto ERROR_EXIT;
			}
			moduleInfo.FullDllName[written] = '\0';
			info.push_back(moduleInfo);
		}
		return info;
	}
	else
	{
		ULONG32 ldr;
		if (!READMEMORY(pebAddress + 0xc, ldr))
		{
			dprintf("read Ldr failed\n");
			goto ERROR_EXIT;
		}

		ULONG64 headAddress = ldr + 0x14;
		LIST_ENTRY32 inMemoryOrderModuleList;
		if (!READMEMORY(headAddress, inMemoryOrderModuleList))
		{
			dprintf("read InMemoryOrderModuleList failed\n");
			goto ERROR_EXIT;
		}

		LIST_ENTRY32 entry = inMemoryOrderModuleList;
		while (entry.Flink != headAddress)
		{
			ModuleInfo moduleInfo;
			ULONG64 address = entry.Flink;
			if (!READMEMORY(address, entry))
			{
				dprintf("read entry at %p failed\n", address);
				goto ERROR_EXIT;
			}

			// LDR_DATA_TABLE_ENTRY at address - sizeof(entry)
			ULONG32 dllBase, sizeOfImage;
			if (!READMEMORY(address - sizeof(entry) + 0x18, dllBase))
			{
				dprintf("read DllBase at %p failed\n", address - sizeof(entry) + 0x18);
				goto ERROR_EXIT;
			}
			moduleInfo.DllBase = dllBase;
			if (!READMEMORY(address - sizeof(entry) + 0x20, sizeOfImage))
			{
				dprintf("read SizeOfImage at %p failed\n", address - sizeof(entry) + 0x20);
				goto ERROR_EXIT;
			}
			moduleInfo.SizeOfImage = sizeOfImage;

			// UNICODE_STRING
			struct
			{
				USHORT Length;
				USHORT MaximumLength;
				ULONG32 Buffer;
			} fullDllName;
			if (!READMEMORY(address - sizeof(entry) + 0x24, fullDllName))
			{
				dprintf("read FullDllName at %p failed\n", address - sizeof(entry) + 0x24);
				goto ERROR_EXIT;
			}
			std::vector<wchar_t> unicode;
			unicode.resize(fullDllName.Length / sizeof(wchar_t));
			if (!ReadMemory(fullDllName.Buffer, &unicode[0], fullDllName.Length, &cb) || cb != fullDllName.Length)
			{
				dprintf("read unicode at %p %d failed\n", (ULONG64)fullDllName.Buffer, (int)fullDllName.Length);
				goto ERROR_EXIT;
			}
		
			int written = WideCharToMultiByte(CP_ACP, 0, &unicode[0], fullDllName.Length / sizeof(wchar_t),
				moduleInfo.FullDllName, sizeof(moduleInfo.FullDllName), NULL, NULL);
			if (written < 0 || written >= sizeof(moduleInfo.FullDllName))
			{
				dprintf("WideCharToMultiByte returns %d\n", written);
				goto ERROR_EXIT;
			}
			moduleInfo.FullDllName[written] = '\0';
			info.push_back(moduleInfo);
		}
		return info;
	}

ERROR_EXIT:
	info.clear();
	return info;
}
Exemplo n.º 25
0
bool DatabaseUtils::GetDatabaseResults(const MediaType &mediaType, const FieldList &fields, const std::unique_ptr<dbiplus::Dataset> &dataset, DatabaseResults &results)
{
  if (dataset->num_rows() == 0)
    return true;

  const dbiplus::result_set &resultSet = dataset->get_result_set();
  unsigned int offset = results.size();

  if (fields.empty())
  {
    DatabaseResult result;
    for (unsigned int index = 0; index < resultSet.records.size(); index++)
    {
      result[FieldRow] = index + offset;
      results.push_back(result);
    }

    return true;
  }

  if (resultSet.record_header.size() < fields.size())
    return false;

  std::vector<int> fieldIndexLookup;
  fieldIndexLookup.reserve(fields.size());
  for (FieldList::const_iterator it = fields.begin(); it != fields.end(); ++it)
    fieldIndexLookup.push_back(GetFieldIndex(*it, mediaType));

  results.reserve(resultSet.records.size() + offset);
  for (unsigned int index = 0; index < resultSet.records.size(); index++)
  {
    DatabaseResult result;
    result[FieldRow] = index + offset;

    unsigned int lookupIndex = 0;
    for (FieldList::const_iterator it = fields.begin(); it != fields.end(); ++it)
    {
      int fieldIndex = fieldIndexLookup[lookupIndex++];
      if (fieldIndex < 0)
        return false;

      std::pair<Field, CVariant> value;
      value.first = *it;
      if (!GetFieldValue(resultSet.records[index]->at(fieldIndex), value.second))
        CLog::Log(LOGWARNING, "GetDatabaseResults: unable to retrieve value of field %s", resultSet.record_header[fieldIndex].name.c_str());

      if (value.first == FieldYear &&
         (mediaType == MediaTypeTvShow || mediaType == MediaTypeEpisode))
      {
        CDateTime dateTime;
        dateTime.SetFromDBDate(value.second.asString());
        if (dateTime.IsValid())
        {
          value.second.clear();
          value.second = dateTime.GetYear();
        }
      }

      result.insert(value);
    }

    result[FieldMediaType] = mediaType;
    if (mediaType == MediaTypeMovie || mediaType == MediaTypeVideoCollection ||
        mediaType == MediaTypeTvShow || mediaType == MediaTypeMusicVideo)
      result[FieldLabel] = result.at(FieldTitle).asString();
    else if (mediaType == MediaTypeEpisode)
    {
      std::ostringstream label;
      label << (int)(result.at(FieldSeason).asInteger() * 100 + result.at(FieldEpisodeNumber).asInteger());
      label << ". ";
      label << result.at(FieldTitle).asString();
      result[FieldLabel] = label.str();
    }
    else if (mediaType == MediaTypeAlbum)
      result[FieldLabel] = result.at(FieldAlbum).asString();
    else if (mediaType == MediaTypeSong)
    {
      std::ostringstream label;
      label << (int)result.at(FieldTrackNumber).asInteger();
      label << ". ";
      label << result.at(FieldTitle).asString();
      result[FieldLabel] = label.str();
    }
    else if (mediaType == MediaTypeArtist)
      result[FieldLabel] = result.at(FieldArtist).asString();

    results.push_back(result);
  }

  return true;
}
Exemplo n.º 26
0
/**< 解包 */
int Dataprocess::Unpack(unsigned char *PackageIn, unsigned int InLen)
{
    try
	{
        int iRet;
        memcpy(ucRecBuffer,PackageIn,InLen);		//for 冲正存储转发
        nRecDataLen	=	InLen;
        
		// 解包
        iRet = pMsg8583recv->UnPack(PackageIn, InLen);
        if(iRet != 1)
        {
            trace_log(ERR, "UnPack package failed!");
            pMsg8583recv->SetValueByStr(39,"30");			//报文格式错误
            pMsg8583recv->SetValueByStr(56,"报文格式错误");
            return -1;
        }
        trace_log(NML, "UnPack package success!");

        if(0 != GetFieldValue())
		{
			return -1;
		}
	
        // 校验MAC
        if(pMsg8583recv->FieldExist(64))
        {
            unsigned char 	Mac[16];
            unsigned char *	pMab 	= PackageIn + LENOFFSET + MSGTPDULEN + MSGHEADLEN;
            int 			MabLen 	= (int)InLen - LENOFFSET - MSGTPDULEN - MSGHEADLEN - MACLEN;

            trace_mem(pMab, MabLen);
            EnCrypt enCrypt;
            bool enc_ret = enCrypt.CalculateMac((char *)myData.cCardAccepCode, (char *)myData.cCardAccepTerm, pMab, MabLen, Mac);
            if( enc_ret )
            {
                if(memcmp(pMab + MabLen, Mac, MACLEN) != 0)
                {
                    trace_log(ERR, "check mac  error");
                    trace_mem(pMab + MabLen, MACLEN);
                    trace_mem(Mac, MACLEN);
                    pMsg8583recv->SetValueByStr(39,"A0");//MAC校验错误
                    pMsg8583recv->SetValueByStr(56,"MAC校验错误");//MAC校验错误
                    return -1;
                }
                trace_log(NML, "check mac success!");
            }
			else
			{
                trace_log(ERR, "check mac  failed");
                pMsg8583recv->SetValueByStr(39,"A0");//MAC校验错误
                pMsg8583recv->SetValueByStr(56,"MAC校验错误2");//MAC校验错误
                return -1;
            }
        }
        return 0;
    }
	catch(...)
	{
        trace_log(SYS, "Error in Dataprocess::UnPack");
        pMsg8583recv->SetValueByStr(39,"ZZ");//交易失败
        pMsg8583recv->SetValueByStr(56,"System Exception:UpPack err");
        return -1;
    }
}
Exemplo n.º 27
0
OGRFeature *OGRDODSSequenceLayer::GetFeature( GIntBig nFeatureId )

{
/* -------------------------------------------------------------------- */
/*      Ensure we have the dataset.                                     */
/* -------------------------------------------------------------------- */
    if( !ProvideDataDDS() )
        return NULL;

    Sequence *seq = dynamic_cast<Sequence *>(poTargetVar);

/* -------------------------------------------------------------------- */
/*      Figure out what the super and subsequence number this           */
/*      feature will be, and validate it.  If there is not super        */
/*      sequence the feature id is the subsequence number.              */
/* -------------------------------------------------------------------- */
    int iSubSeq = -1;

    if( nFeatureId < 0 || nFeatureId >= nRecordCount )
        return NULL;

    if( poSuperSeq == NULL )
        iSubSeq = nFeatureId;
    else
    {
        int nSeqOffset = 0, iSuperSeq;

        // for now we just scan through till find find out what
        // super sequence this in.  In the long term we need a better (cached)
        // approach that doesn't involve this quadratic cost.
        for( iSuperSeq = 0; 
             iSuperSeq < nSuperSeqCount; 
             iSuperSeq++ )
        {
            if( nSeqOffset + panSubSeqSize[iSuperSeq] > nFeatureId )
            {
                iSubSeq = nFeatureId - nSeqOffset;
                break;
            }
            nSeqOffset += panSubSeqSize[iSuperSeq];
        }

        CPLAssert( iSubSeq != -1 );

        // Make sure we have the right target var ... the one 
        // corresponding to our current super sequence. 
        if( iSuperSeq != iLastSuperSeq )
        {
            iLastSuperSeq = iSuperSeq;
            poTargetVar = poSuperSeq->var_value( iSuperSeq, pszSubSeqPath );
            seq = dynamic_cast<Sequence *>(poTargetVar);
        }
    }

/* -------------------------------------------------------------------- */
/*      Create the feature being read.                                  */
/* -------------------------------------------------------------------- */
    OGRFeature *poFeature;

    poFeature = new OGRFeature( poFeatureDefn );
    poFeature->SetFID( nFeatureId );
    m_nFeaturesRead++;

/* -------------------------------------------------------------------- */
/*      Process all the regular data fields.                            */
/* -------------------------------------------------------------------- */
    int      iField;

    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        if( papoFields[iField]->pszPathToSequence )
            continue;

        BaseType *poFieldVar = GetFieldValue( papoFields[iField], iSubSeq,
                                              NULL );

        if( poFieldVar == NULL )
            continue;

        switch( poFieldVar->type() )
        {
          case dods_byte_c:
          {
              signed char byVal;
              void *pValPtr = &byVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, byVal );
          }
          break;

          case dods_int16_c:
          {
              GInt16 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, nIntVal );
          }
          break;

          case dods_uint16_c:
          {
              GUInt16 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, nIntVal );
          }
          break;

          case dods_int32_c:
          {
              GInt32 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, nIntVal );
          }
          break;

          case dods_uint32_c:
          {
              GUInt32 nIntVal;
              void *pValPtr = &nIntVal;
              
              poFieldVar->buf2val( &pValPtr );
              poFeature->SetField( iField, (int) nIntVal );
          }
          break;

          case dods_float32_c:
            poFeature->SetField( iField, 
                                 dynamic_cast<Float32 *>(poFieldVar)->value());
            break;

          case dods_float64_c:
            poFeature->SetField( iField, 
                                 dynamic_cast<Float64 *>(poFieldVar)->value());
            break;

          case dods_str_c:
          case dods_url_c:
          {
              string *poStrVal = NULL;
              poFieldVar->buf2val( (void **) &poStrVal );
              poFeature->SetField( iField, poStrVal->c_str() );
              delete poStrVal;
          }
          break;

          default:
            break;
        }
    }
    
/* -------------------------------------------------------------------- */
/*      Handle data nested in sequences.                                */
/* -------------------------------------------------------------------- */
    for( iField = 0; iField < poFeatureDefn->GetFieldCount(); iField++ )
    {
        OGRDODSFieldDefn *poFD = papoFields[iField];
        const char *pszPathFromSubSeq;

        if( poFD->pszPathToSequence == NULL )
            continue;

        CPLAssert( strlen(poFD->pszPathToSequence) 
                   < strlen(poFD->pszFieldName)-1 );

        if( strstr(poFD->pszFieldName,poFD->pszPathToSequence) != NULL )
            pszPathFromSubSeq = 
                strstr(poFD->pszFieldName,poFD->pszPathToSequence)
                + strlen(poFD->pszPathToSequence) + 1;
        else
            continue;

/* -------------------------------------------------------------------- */
/*      Get the sequence out of which this variable will be collected.  */
/* -------------------------------------------------------------------- */
        BaseType *poFieldVar = seq->var_value( iSubSeq, 
                                               poFD->pszPathToSequence );
        Sequence *poSubSeq;
        int nSubSeqCount;

        if( poFieldVar == NULL )
            continue;

        poSubSeq = dynamic_cast<Sequence *>( poFieldVar );
        if( poSubSeq == NULL )
            continue;

        nSubSeqCount = poSubSeq->number_of_rows();
            
/* -------------------------------------------------------------------- */
/*      Allocate array to put values into.                              */
/* -------------------------------------------------------------------- */
        OGRFieldDefn *poOFD = poFeature->GetFieldDefnRef( iField );
        int *panIntList = NULL;
        double *padfDblList = NULL;
        char **papszStrList = NULL;

        if( poOFD->GetType() == OFTIntegerList )
        {
            panIntList = (int *) CPLCalloc(sizeof(int),nSubSeqCount);
        }
        else if( poOFD->GetType() == OFTRealList )
        {
            padfDblList = (double *) CPLCalloc(sizeof(double),nSubSeqCount);
        }
        else if( poOFD->GetType() == OFTStringList )
        {
            papszStrList = (char **) CPLCalloc(sizeof(char*),nSubSeqCount+1);
        }
        else
            continue;

/* -------------------------------------------------------------------- */
/*      Loop, fetching subsequence values.                              */
/* -------------------------------------------------------------------- */
        int iSubIndex;
        for( iSubIndex = 0; iSubIndex < nSubSeqCount; iSubIndex++ )
        {
            poFieldVar = poSubSeq->var_value( iSubIndex, pszPathFromSubSeq );

            if( poFieldVar == NULL )
                continue;

            switch( poFieldVar->type() )
            {
              case dods_byte_c:
              {
                  signed char byVal;
                  void *pValPtr = &byVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = byVal;
              }
              break;
              
              case dods_int16_c:
              {
                  GInt16 nIntVal;
                  void *pValPtr = &nIntVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;
              
              case dods_uint16_c:
              {
                  GUInt16 nIntVal;
                  void *pValPtr = &nIntVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;
              
              case dods_int32_c:
              {
                  GInt32 nIntVal;
                  void *pValPtr = &nIntVal;
                  
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;

              case dods_uint32_c:
              {
                  GUInt32 nIntVal;
                  void *pValPtr = &nIntVal;
              
                  poFieldVar->buf2val( &pValPtr );
                  panIntList[iSubIndex] = nIntVal;
              }
              break;

              case dods_float32_c:
                padfDblList[iSubIndex] = 
                    dynamic_cast<Float32 *>(poFieldVar)->value();
                break;

              case dods_float64_c:
                padfDblList[iSubIndex] = 
                    dynamic_cast<Float64 *>(poFieldVar)->value();
                break;

              case dods_str_c:
              case dods_url_c:
              {
                  string *poStrVal = NULL;
                  poFieldVar->buf2val( (void **) &poStrVal );
                  papszStrList[iSubIndex] = CPLStrdup( poStrVal->c_str() );
                  delete poStrVal;
              }
              break;

              default:
                break;
            }
        }

/* -------------------------------------------------------------------- */
/*      Apply back to feature.                                          */
/* -------------------------------------------------------------------- */
        if( poOFD->GetType() == OFTIntegerList )
        {
            poFeature->SetField( iField, nSubSeqCount, panIntList );
            CPLFree(panIntList);
        }
        else if( poOFD->GetType() == OFTRealList )
        {
            poFeature->SetField( iField, nSubSeqCount, padfDblList );
            CPLFree(padfDblList);
        }
        else if( poOFD->GetType() == OFTStringList )
        {
            poFeature->SetField( iField, papszStrList );
            CSLDestroy( papszStrList );
        }
    }
    
/* ==================================================================== */
/*      Fetch the geometry.                                             */
/* ==================================================================== */
    if( oXField.bValid && oYField.bValid )
    {
        int iXField = poFeature->GetFieldIndex( oXField.pszFieldName );
        int iYField = poFeature->GetFieldIndex( oYField.pszFieldName );
        int iZField = -1;

        if( oZField.bValid )
            iZField = poFeature->GetFieldIndex(oZField.pszFieldName);

/* -------------------------------------------------------------------- */
/*      If we can't find the values in attributes then use the more     */
/*      general mechanism to fetch the value.                           */
/* -------------------------------------------------------------------- */
        
        if( iXField == -1 || iYField == -1 
            || (oZField.bValid && iZField == -1) )
        {
            poFeature->SetGeometryDirectly( 
                new OGRPoint( GetFieldValueAsDouble( &oXField, iSubSeq ),
                              GetFieldValueAsDouble( &oYField, iSubSeq ),
                              GetFieldValueAsDouble( &oZField, iSubSeq ) ) );
        }
/* -------------------------------------------------------------------- */
/*      If the fields are list values, then build a linestring.         */
/* -------------------------------------------------------------------- */
        else if( poFeature->GetFieldDefnRef(iXField)->GetType() == OFTRealList
            && poFeature->GetFieldDefnRef(iYField)->GetType() == OFTRealList )
        {
            const double *padfX, *padfY, *padfZ = NULL;
            int nPointCount, i;
            OGRLineString *poLS = new OGRLineString();
            
            padfX = poFeature->GetFieldAsDoubleList( iXField, &nPointCount );
            padfY = poFeature->GetFieldAsDoubleList( iYField, &nPointCount );
            if( iZField != -1 )
                padfZ = poFeature->GetFieldAsDoubleList(iZField,&nPointCount);

            poLS->setPoints( nPointCount, (double *) padfX, (double *) padfY,
                             (double *) padfZ );

            // Make a pass clearing out NaN or Inf values. 
            for( i = 0; i < nPointCount; i++ )
            {
                double dfX = poLS->getX(i);
                double dfY = poLS->getY(i);
                double dfZ = poLS->getZ(i);
                int bReset = FALSE;

                if( OGRDODSIsDoubleInvalid( &dfX ) )
                {
                    dfX = 0.0;
                    bReset = TRUE;
                }
                if( OGRDODSIsDoubleInvalid( &dfY ) )
                {
                    dfY = 0.0;
                    bReset = TRUE;
                }
                if( OGRDODSIsDoubleInvalid( &dfZ ) )
                {
                    dfZ = 0.0;
                    bReset = TRUE;
                }

                if( bReset )
                    poLS->setPoint( i, dfX, dfY, dfZ );
            }

            poFeature->SetGeometryDirectly( poLS );
        }

/* -------------------------------------------------------------------- */
/*      Otherwise build a point.                                        */
/* -------------------------------------------------------------------- */
        else
        {
            poFeature->SetGeometryDirectly( 
                new OGRPoint( 
                    poFeature->GetFieldAsDouble( iXField ),
                    poFeature->GetFieldAsDouble( iYField ),
                    poFeature->GetFieldAsDouble( iZField ) ) );
        }
    }

    return poFeature;
}
Exemplo n.º 28
0
TInt CParsedFieldCollection::GetFieldValueAndLength(const TDesC& aFieldName, TPtrC& aValue) const
	{
	aValue.Set(GetFieldValue(aFieldName));
	return aValue.Length();
	}
Exemplo n.º 29
0
   dbf_data_type GetFieldType(int field, const CDaoFieldInfo& info, size_t* length)
   {
      dbf_data_type type;

      switch (info.m_nType)
      {
         case dbDate:
         {
            bool date = false;
            bool time = false;
            if (!(IsBOF() && IsEOF())) for (MoveFirst(); !IsEOF(); MoveNext())
            {
               COleVariant var;
      	      GetFieldValue(field, var);
               if (var.vt == VT_DATE)
               {
                  SYSTEMTIME st;
                  COleDateTime dt(var.date);
                  if (dt.GetAsSystemTime(st))
                  {
                     date = date || (st.wYear != 1899);
                     time = time || st.wHour || st.wMinute || st.wSecond;
                  }
               }
            }
            if (date && time)
            {
               type = DBF_DATA_TYPE_DATETIME;
               *length = DBF_LEN_DATETIME;
            }
            else if (time)
            {
               type = DBF_DATA_TYPE_TIME;
               *length = DBF_LEN_TIME;
            }
            else
            {
               type = DBF_DATA_TYPE_DATE;
               *length = DBF_LEN_DATE;
            }
            break;
         }
         case dbDecimal:
         case dbFloat:
         case dbSingle:
         case dbDouble:
            type = DBF_DATA_TYPE_FLOAT;
            break;
         case dbText:
         case dbMemo:
         case dbChar:
            type = DBF_DATA_TYPE_CHAR;
            if (0 == *length)
            {
               *length = 80;
            }
            break;
         case dbInteger:
         case dbLong:
         case dbByte:
         case dbNumeric:
         case dbBigInt:
            type = DBF_DATA_TYPE_INTEGER;
            // workaround: it may be a running number, check if highest one fits.
            // Increase field size if needed
            if (!(IsBOF() && IsEOF()))
            {
               MoveLast();
               COleVariant var;
      	      GetFieldValue(field, var);
               
               int n = 0;
               switch (var.vt)
               {
                  case VT_I2: 
                     n = var.iVal; break;
                  case VT_I4: 
                     n = var.lVal; break;
               }
               if (n)
               {
                  char temp[80];
                  size_t len = _snprintf(temp, _countof(temp), "%d", n);

                  if (len > *length)
                  {
                     *length = len;
                  }
               }
            }
            break;
         case dbBoolean:
            type = DBF_DATA_TYPE_BOOLEAN;
            *length = DBF_LEN_BOOLEAN;
            break;
         case dbCurrency:
         case dbBinary:
         case dbLongBinary:
         case dbGUID:
         case dbVarBinary:
         case dbTime:
         case dbTimeStamp:
         default:
            type = DBF_DATA_TYPE_UNKNOWN;
            break;
      }
      return type;
   }
Exemplo n.º 30
0
void 
StorageHomeBaseImpl::ValuePaser( std::map<std::string, CORBA::Any>& valueMap )
{
	int nType, nLen;
	unsigned char szColName[256];

	unsigned char szData[1024]; // SQL_CHAR or SQL_VARCHAR -> SQL_C_CHAR; SQL_BINARY -> SQL_C_BINARY
	unsigned char ucData; // SQL_BIT -> SQL_C_BIT
	char cData; // SQL_TINYINT -> SQL_C_TINYINT				
	short siData; // SQL_SMALLINT -> SQL_C_SHORT				
	long lData; // SQL_INTEGER -> SQL_C_LONG				
	float fData; // SQL_REAL -> SQL_C_FLOAT
	double dData; // SQL_DOUBLE or SQL_FLOAT -> SQL_C_DOUBLE
	//struct tm* strctData = new struct tm(); // SQL_TYPE_TIMESTAMP -> SQL_C_TYPE_TIMESTAMP(3.x); SQL_TIMESTAMP -> SQL_C_TIMESTAMP(2.x)
	
	for(int iCol=0; iCol<GetFieldCount(); iCol++)
	{
		std::string strColName;
		CORBA::Any anyData;

		memset(szColName, '\0', 256);
		GetFieldAttributes(iCol, szColName, nType, nLen);
		strColName = (char*)szColName;
		
		switch(nType)
		{
			case SQL_CHAR: // also for CORBA::Boolean
			case SQL_VARCHAR:
				memset(szData, '\0', 1024);
				GetFieldValue(iCol, szData);
				anyData <<= (const char*)szData;
				break;
			case SQL_BIT:
				GetFieldValue(iCol, &ucData);
				anyData <<= CORBA::Any::from_octet(ucData);
				break;
			case SQL_TINYINT:
				GetFieldValue(iCol, cData);
				anyData <<= CORBA::Any::from_char(cData);
				break;
			case SQL_SMALLINT:
				GetFieldValue(iCol, &siData);
				anyData <<= (CORBA::Short)siData;
				break;
			case SQL_INTEGER:
				GetFieldValue(iCol, &lData);
				anyData <<= (CORBA::Long)lData;
				break;
			case SQL_REAL:
				GetFieldValue(iCol, &fData);
				anyData <<= (CORBA::Float)fData;
				break;
			case SQL_DOUBLE:
			case SQL_FLOAT:
				GetFieldValue(iCol, &dData);
				anyData <<= (CORBA::Double)dData;
				break;
			//case SQL_TYPE_TIMESTAMP:
			//case SQL_TIMESTAMP:
			//	GetFieldValue(iCol, strctData);
			//	anyData <<= (CORBA::StructDef)strctData;
			//	break;
			//case SQL_NUMERIC:
			//case SQL_DECIMAL:
			//	GetFieldValue(iCol, fltIncome);
			//	break;
			default:
				assert("This data type is unknown!");
				break;
		}

		valueMap[strColName] = anyData;
	}
}