예제 #1
0
파일: FileINI.cpp 프로젝트: MaxHenger/FENN
void fio::FileINI::Add(const std::string sHeader, const std::string sName, const std::string sValue)
{
    std::vector<FileINIHeader>::iterator it = FindHeader(sHeader);
    if (it == m_veHeaders.end()) {
        it = CreateHeader(sHeader);
    }

    it->veEntries.push_back(FileINIEntry(sName, sValue));
}
예제 #2
0
파일: FileINI.cpp 프로젝트: MaxHenger/FENN
bool fio::FileINI::GetNumEntries(const std::string sHeader, unsigned int &res) const
{
    std::vector<FileINIHeader>::const_iterator it = FindHeader(sHeader);

    if (it == m_veHeaders.end()) {
        res = 0;
        return false;
    }

    res = it->veEntries.size();
    return true;
}
예제 #3
0
// -----------------------------------------------------------------------------
// MceSip::HasTlsInContact
// -----------------------------------------------------------------------------
//
TBool MceSip::HasTlsInContactL( const CSIPMessageElements& aMessage )
	{
	TBool hasTls = EFalse;
	CSIPHeaderBase* contact = FindHeader( aMessage, SIPStrings::StringF( 
											SipStrConsts::EContactHeader ) );
                                    
    if ( !contact )
    	{
    	contact = FindHeader( aMessage, SIPStrings::StringF( 
											SipStrConsts::EContactHeaderCompact ) );
    	}
    
    if ( contact )
    	{
	
		const TDesC8& uriPath = static_cast< CSIPContactHeader* >( contact )->SIPAddress()->Uri8().Uri().Extract( EUriPath );
		if ( uriPath.FindF( KMceSipTransportTLS ) != KErrNotFound )
			{
			hasTls = ETrue;
			}
		}
		
	return hasTls;
	}
예제 #4
0
// -----------------------------------------------------------------------------
// MceSip::HasSipsUriInContact
// -----------------------------------------------------------------------------
//
TBool MceSip::HasSipsUriInContactL( const CSIPMessageElements& aMessage )
	{
	TBool hasSipsUri = EFalse;
	CSIPHeaderBase* contact = FindHeader( aMessage, SIPStrings::StringF( 
											SipStrConsts::EContactHeader ) );
                                    
    if ( !contact )
    	{
    	contact = FindHeader( aMessage, SIPStrings::StringF( 
											SipStrConsts::EContactHeaderCompact ) );
    	}
    
    if ( contact )
    	{
		const TDesC8& uriScheme = static_cast< CSIPContactHeader* >( contact )->
									SIPAddress()->Uri8().Uri().Extract( EUriScheme );
		if ( uriScheme.FindF( KMceSipUriSchemeSIPs ) != KErrNotFound )
			{
			hasSipsUri = ETrue;
			}
		}

	return hasSipsUri;		
	}
예제 #5
0
TInt MceSip::RSeq( const CSIPResponseElements& aResponseElements )
    {
        
    TInt value = KErrNotFound; // if its not found
    
    CSIPHeaderBase* rseqHeader = FindHeader( aResponseElements.MessageElements(),
                            SIPStrings::StringF( SipStrConsts::ERSeqHeader ) );
                                    
    if ( rseqHeader )
        {
        value = static_cast< CSIPRSeqHeader* >( rseqHeader )->Value(); 
        }
           
    return value;    
    }
예제 #6
0
파일: FileINI.cpp 프로젝트: MaxHenger/FENN
bool fio::FileINI::GetEntry(const std::string sHeader, const unsigned int iEntry, FileINIEntry &entry) const
{
    std::vector<FileINIHeader>::const_iterator it = FindHeader(sHeader);

    if (it == m_veHeaders.end()) {
        //failed to find the header
        entry.sName.clear();
        entry.sValue.clear();
        return false;
    }

    entry.sName = it->veEntries[iEntry].sName;
    entry.sValue = it->veEntries[iEntry].sValue;
    return true;
}
예제 #7
0
bool CArchiverJACK::GetContainedFileName(LPCTSTR ArcFileName,CString &strFileName)
{
	strFileName.Empty();

	//ファイル内容バッファ
	std::vector<BYTE> Buffer;
	//ファイルオープン
	HANDLE hFile=CreateFile(ArcFileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
	if(INVALID_HANDLE_VALUE==hFile)return false;

	DWORD dwSize=GetFileSize(hFile,NULL);
		//4GBより大きなファイルサイズは取得できないが、現実的にはそのような大きなファイルは扱わない(JACKは分割用)
	Buffer.resize(dwSize);

	DWORD dwRead=0;
	if(dwSize<0){
		CloseHandle(hFile);
		return false;
	}

	//読み取り
	ReadFile(hFile,&Buffer[0],dwSize,&dwRead,NULL);
	CloseHandle(hFile);

	//ヘッダ検索
	int iPos=FindHeader(&Buffer[0],dwRead);
	if(-1==iPos){
		//Not Found
		return false;
	}

	JakHeader* lpHeader=(JakHeader*)&Buffer[iPos];

	for(unsigned int i=0;i<lpHeader->FileNameLen;i++){
		strFileName+=Buffer[iPos+sizeof_JakHeader+i];
	}
	return true;
}
예제 #8
0
파일: FileINI.cpp 프로젝트: MaxHenger/FENN
bool fio::FileINI::GetEntry(const std::string sHeader, const std::string sName, FileINIEntry &entry) const
{
    std::vector<FileINIHeader>::const_iterator itHeader = FindHeader(sHeader);

    if (itHeader == m_veHeaders.end()) {
        //could not find the header
        entry.sName.clear();
        entry.sValue.clear();
        return false;
    }

    std::vector<FileINIEntry>::const_iterator itEntry = FindEntry(itHeader, sName);

    if (itEntry == itHeader->veEntries.end()) {
        //failed to find the entry
        entry.sName.clear();
        entry.sValue.clear();
        return false;
    }

    entry = *itEntry;
    return true;
}
예제 #9
0
Res GetIncludes(const Target* t, const Context* context,
                const string& src_path, const string& inc_dirs_str,
                vector<string>* includes) {
    Hash src_hash;
    Res res = context->ComputeOrGetFileContentHash(src_path, &src_hash);
    if (!res.Ok()) {
        return res;
    }

    Hash deps_file_id;
    deps_file_id << "includes" << src_hash << inc_dirs_str;

    ObjectStore* ostore = context->GetObjectStore();
    FILE* fp = ostore->Read(deps_file_id);
    if (fp) {
        // Read the deps file.
        static const int BUFSIZE = 1000;
        char linebuf[BUFSIZE];
        while (fgets(linebuf, BUFSIZE, fp)) {
            if (linebuf[0] == '\r' || linebuf[0] == '\n' || linebuf[0] == '#') {
                // Skip.
                continue;
            }
            int len = strlen(linebuf);

            // Trim.
            while (len >= 0 && (linebuf[len - 1] == '\n' ||
                                linebuf[len - 1] == '\r')) {
                linebuf[len - 1] = 0;
                len--;
            }

            includes->push_back(linebuf);
        }
        fclose(fp);
    } else {
        // Scan the source file.
        FILE* fp_src = fopen(src_path.c_str(), "rb");
        if (!fp_src) {
            return Res(ERR_FILE_ERROR, "Couldn't open file for include scanning: " +
                       src_path);
        }

        string src_dir = FilenamePathPart(src_path);
        static const int BUFSIZE = 1000;
        char linebuf[BUFSIZE];
        string header_file;
        string header_path;
        bool is_quoted = false;
        while (fgets(linebuf, BUFSIZE, fp_src)) {
            if (ParseIncludeLine(linebuf, &header_file, &is_quoted)) {
                if (FindHeader(src_dir, t, context, header_file, is_quoted,
                               &header_path)) {
                    includes->push_back(header_path);
                }
            }
        }
        fclose(fp_src);

        // Write the deps file.
        FILE* fp = ostore->Write(deps_file_id);
        if (!fp) {
            context->LogVerbose("Unable to write deps to ostore for file: " +
                                src_path);
        } else {
            fprintf(fp, "# includes %s\n", src_path.c_str());
            for (size_t i = 0; i < includes->size(); i++) {
                const string& header_path = (*includes)[i];
                bool ok =
                    (fwrite(header_path.c_str(), header_path.size(), 1, fp) == 1) &&
                    (fputc('\n', fp) != EOF);
                if (!ok) {
                    fclose(fp);
                    return Res(ERR_FILE_ERROR, "Error writing to deps file for " +
                               src_path);
                }
            }
            fclose(fp);
        }
    }

    return Res(OK);
}
nsresult nsEudoraFilters::AddTerm(const char* pHeader, const char* pVerb, const char* pValue, bool booleanAnd, bool negateVerb)
{
  nsresult rv;

  nsMsgSearchAttribValue attrib = FindHeader(pHeader);
  nsMsgSearchOpValue     op = FindOperator(pVerb);
  nsAutoCString          arbitraryHeader;
  nsAutoString           unicodeHeader, unicodeVerb, unicodeValue;
  nsAutoString           filterTitle;

  NS_CopyNativeToUnicode(nsCString(pHeader), unicodeHeader);
  NS_CopyNativeToUnicode(nsCString(pVerb), unicodeVerb);
  NS_CopyNativeToUnicode(nsCString(pValue), unicodeValue);

  filterTitle = NS_LITERAL_STRING("- ");
  filterTitle += unicodeHeader;
  filterTitle += NS_LITERAL_STRING(" ");
  filterTitle += unicodeVerb;
  filterTitle += NS_LITERAL_STRING(" ");
  filterTitle += unicodeValue;
  filterTitle += NS_LITERAL_STRING(": ");

  if (op < 0)
  {
    m_errorLog += filterTitle;
    m_errorLog += nsEudoraStringBundle::FormatString(EUDORAIMPORT_FILTERS_WARN_VERB, pVerb);
    m_errorLog += NS_LITERAL_STRING("\n");
    return NS_ERROR_INVALID_ARG;
  }

  if (!pHeader || !*pHeader)
  {
    m_errorLog += filterTitle;
    m_errorLog += nsEudoraStringBundle::FormatString(EUDORAIMPORT_FILTERS_WARN_EMPTY_HEADER);
    m_errorLog += NS_LITERAL_STRING("\n");
    return NS_ERROR_INVALID_ARG;
  }

  if (negateVerb)
  {
    switch (op)
    {
      case nsMsgSearchOp::Contains:
      case nsMsgSearchOp::Is:
      case nsMsgSearchOp::IsInAB:
        op++;
        break;
      case nsMsgSearchOp::DoesntContain:
      case nsMsgSearchOp::Isnt:
      case nsMsgSearchOp::IsntInAB:
        op--;
        break;
      default:
        m_errorLog += filterTitle;
        m_errorLog += nsEudoraStringBundle::FormatString(EUDORAIMPORT_FILTERS_WARN_NEGATE_VERB, unicodeVerb.get());
        m_errorLog += NS_LITERAL_STRING("\n");
        return NS_ERROR_INVALID_ARG;
    }
  }

  if (attrib < 0)
  {
    // Can't handle other Eudora meta-headers (Any Header, Personality, Junk Score)
    if (*pHeader == *LDAQ)
    {
      m_errorLog += filterTitle;
      m_errorLog += nsEudoraStringBundle::FormatString(EUDORAIMPORT_FILTERS_WARN_META_HEADER, unicodeHeader.get());
      m_errorLog += NS_LITERAL_STRING("\n");
      return NS_ERROR_INVALID_ARG;
    }

    // Arbitrary headers for filters don't like the colon at the end
    arbitraryHeader = pHeader;
    int32_t index = arbitraryHeader.FindChar(':');
    if (index >= 0)
      arbitraryHeader.SetLength(index);

    int32_t headerIndex = AddCustomHeader(arbitraryHeader.get());
    NS_ENSURE_TRUE(headerIndex >= 0, NS_ERROR_FAILURE);

    attrib = nsMsgSearchAttrib::OtherHeader + 1 + headerIndex;
  }

  uint32_t numFilters;
  rv = m_pFilterArray->GetLength(&numFilters);
  NS_ENSURE_SUCCESS(rv, rv);
  for (uint32_t filterIndex = 0; filterIndex < numFilters; filterIndex++)
  {
    nsCOMPtr<nsIMsgFilter> filter = do_QueryElementAt(m_pFilterArray, filterIndex, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISupportsArray> terms;
    rv = filter->GetSearchTerms(getter_AddRefs(terms));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIMsgSearchTerm> term;
    if (booleanAnd)
    {
      term = do_QueryElementAt(terms, 0, &rv);
      if (NS_SUCCEEDED(rv) && term)
      {
        term->SetBooleanAnd(true);
        term = nullptr;
      }
    }

    rv = filter->CreateTerm(getter_AddRefs(term));
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIMsgSearchValue> value;
    rv = term->GetValue(getter_AddRefs(value));
    NS_ENSURE_SUCCESS(rv, rv);

    value->SetAttrib(attrib);
    value->SetStr(unicodeValue);
    term->SetAttrib(attrib);
    term->SetOp(op);
    term->SetBooleanAnd(booleanAnd);
    if (!arbitraryHeader.IsEmpty())
      term->SetArbitraryHeader(arbitraryHeader);
    term->SetValue(value);
    filter->AppendTerm(term);
  }

  return NS_OK;
}
예제 #11
0
		/*!
		 * \brief
		 * The callback called by the HTTP server when a URL starting with "map_download" is requested.
		 * 
		 * \param callback_event
		 * The type of event that has been started by mongoose.
		 * 
		 * \param connection
		 * The connection the response is to be sent to.
		 * 
		 * \param request_info
		 * Pointer to the request information sent to the server by the client.
		 * 
		 * \returns
		 * Always returns a non-NULL value (currently an empty character string);
		 * 
		 * The callback called by the HTTP server when a URL starting with "map_download" is requested.
		 */
		void* ServerCallback(mg_event callback_event, mg_connection* connection)
		{
			const mg_request_info* request_info = mg_get_request_info(connection);

			// the system is not running, so deny the request
			if(!g_map_download_globals.m_flags.system_active)
				SendResponse(connection, Enums::_http_status_code_server_error_service_unavailable);
			else if(callback_event == MG_NEW_REQUEST)
			{
				// deny the request if it has come from somewhere other than the HCE client
				int agent_header_index = FindHeader(request_info, "User-Agent");
				if((-1 == agent_header_index) || (!request_info->http_headers[agent_header_index].value))
				{
					SendResponse(connection, Enums::_http_status_code_client_error_method_not_allowed);
					return "";
				}
				else
				{
					const char* value_pointer = strstr(request_info->http_headers[agent_header_index].value, K_HTTP_CLIENT_ID);
					if(value_pointer != request_info->http_headers[agent_header_index].value)
					{
						SendResponse(connection, Enums::_http_status_code_client_error_method_not_allowed);
						return "";
					}
				}

				// keep track of the number of requests in progress
				g_map_download_globals.m_requests_in_progress++;

				if(strcmp(request_info->request_method, "GET") != 0)
				{
					// the other http methods are not supported
					SendResponse(connection, Enums::_http_status_code_client_error_method_not_allowed);
				}
				else
				{
					c_url_interface url_interface;
					url_interface.ParsePath(request_info->uri);
					url_interface.ParseQuery(request_info->query_string);

					std::string resource = url_interface.GetResource();

					// the actual part definition file might not be called this but it is accessed by this id anyway
					if((resource.length() == 0) || (resource.compare("map_download") != 0))
						SendResponse(connection, Enums::_http_status_code_client_error_method_not_allowed);
					else
					{
						std::string map_name = "";
						std::string part_name = "";
						bool has_map_name = url_interface.GetQueryValue("map", map_name) && (map_name.length() != 0);
						bool has_part_name = url_interface.GetQueryValue("part", part_name) && (part_name.length() != 0);

						if(has_map_name && has_part_name)
							ProcessMapPartDownloadReferral(connection, map_name, part_name);
						else if(has_map_name && !has_part_name)
							ProcessMapPartDefinitionRequest(connection, map_name);
						else
							SendResponse(connection, Enums::_http_status_code_client_error_bad_request);
					}
				}

				// request complete, reduce the requests in progress count
				YELO_ASSERT_DISPLAY(g_map_download_globals.m_requests_in_progress != 0, "requests in progress is already 0");
				g_map_download_globals.m_requests_in_progress--;
			}
			else
				SendResponse(connection, Enums::_http_status_code_client_error_method_not_allowed);

			return "";
		}