示例#1
0
void dlgRepCluster::CheckChange()
{
	if (cluster)
	{
		int sel = cbAdminNode->GetCurrentSelection();
		bool changed = (sel >= 0 && (long)cbAdminNode->wxEvtHandler::GetClientData() != cluster->GetAdminNodeID());

		EnableOK(changed || txtComment->GetValue() != cluster->GetComment());
	}
	else
	{
		size_t i;
		bool enable = true;

		CheckValid(enable, chkJoinCluster->GetValue() || (!createScript.IsEmpty()),
		           _("Slony-I creation scripts not available; only joining possible."));

		if (chkJoinCluster->GetValue())
			CheckValid(enable, !cbClusterName->GetValue().IsEmpty(), _("Please select a cluster name."));
		else
			CheckValid(enable, !txtClusterName->GetValue().IsEmpty(), _("Please specify name."));

		long nodeId = StrToLong(txtNodeID->GetValue());
		CheckValid(enable, nodeId > 0, _("Please specify local node ID."));
		for (i = 0 ; i < usedNodes.GetCount() && enable; i++)
			CheckValid(enable, nodeId != usedNodes[i], _("Node ID is already in use."));

		CheckValid(enable, !txtNodeName->GetValue().IsEmpty(), _("Please specify local node name."));

		txtAdminNodeName->Enable(nodeId != StrToLong(txtAdminNodeID->GetValue()));

		EnableOK(enable);
	}
}
HRESULT CMyAuctionItemPageAnalyze::_InnerGetAuctionsEndedRowItemInfo(CComQIPtr<IHTMLElementCollection>& spChildElements, 
																	WowItemInfoPtr& spItemInfo, 
																	const CString& strSearchItemName)
{
	//CFHTMLElementCollectionDumper dumper(spChildElements, CFOutputWindowInfoOutput::Instance(), 0);
	HRESULT hr = E_FAIL;
	long nLength = 0;
	COM_VERIFY(spChildElements->get_length(&nLength));
	FTLASSERT(nLength >= AuctionsEnded::siiMinCount);
	if (nLength >= AuctionsEnded::siiMinCount)
	{
		spItemInfo->SetItemStatus(isMyAuctionEnded);
		spItemInfo->SetSeller(CUserInfoManager::Instance()->GetUserName());

		CString strItemName = _GetCollectionItemValue(spChildElements, AuctionsEnded::siiName, ivtInnerText, TRUE);
		if (strSearchItemName.IsEmpty() || strSearchItemName == strItemName)
		{
			CString strUrl = _GetCollectionItemValue(spChildElements, AuctionsEnded::siiTypeUrl, ivtToString);
			spItemInfo->SetUrl(strUrl);
			int nPosSlash = strUrl.ReverseFind(_T('/'));
			if (nPosSlash > 0)
			{
				CString strTypeId = strUrl.Mid(nPosSlash + 1);
				spItemInfo->SetTypeId(StrToLong(strTypeId));
			}
			spItemInfo->SetItemName(strItemName);

			spItemInfo->SetQuantity(StrToLong(_GetCollectionItemValue(spChildElements, AuctionsEnded::siiQuantity, ivtInnerText)));
			spItemInfo->SetRemainDayInMail(StrToLong(_GetCollectionItemValue(spChildElements, AuctionsEnded::siiRemainDayInMail, ivtInnerText, TRUE)));
		}
	}
	return hr;
}
示例#3
0
void dlgDomain::CheckChange()
{
	bool enable = true;

	if (domain)
	{
		enable = false;
		if (connection->BackendMinimumVersion(7, 4) || lstColumns->GetItemCount() > 0)
		{
			enable = !GetSql().IsEmpty();
		}
		if (seclabelPage && connection->BackendMinimumVersion(9, 1))
			enable = enable || !(seclabelPage->GetSqlForSecLabels().IsEmpty());
	}
	else
	{
		wxString name = GetName();
		long varlen = StrToLong(txtLength->GetValue()),
		     varprec = StrToLong(txtPrecision->GetValue());

		txtPrecision->Enable(isVarPrec && varlen > 0);

		CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
		CheckValid(enable, cbDatatype->GetGuessedSelection() >= 0, _("Please select a datatype."));
		CheckValid(enable, !isVarLen || txtLength->GetValue().IsEmpty()
		           || (varlen >= minVarLen && varlen <= maxVarLen && NumToStr(varlen) == txtLength->GetValue()),
		           _("Please specify valid length."));
		CheckValid(enable, !txtPrecision->IsEnabled()
		           || (varprec >= 0 && varprec <= varlen && NumToStr(varprec) == txtPrecision->GetValue()),
		           _("Please specify valid numeric precision (0..") + NumToStr(varlen) + wxT(")."));
	}
	EnableOK(enable);
}
示例#4
0
void dlgColumn::CheckChange()
{
	bool enable = true;
	long varlen = StrToLong(txtLength->GetValue()),
	     varprec = StrToLong(txtPrecision->GetValue());

	if (column)
	{
		txtPrecision->Enable(column->GetTable()->GetMetaType() != PGM_VIEW && isVarPrec && varlen > 0);

		CheckValid(enable, cbDatatype->GetGuessedSelection() >= 0, _("Please select a datatype."));
		if (!connection->BackendMinimumVersion(7, 5))
		{
			CheckValid(enable, !isVarLen || !txtLength->GetValue().IsEmpty() || varlen >= column->GetLength(),
			           _("New length must not be less than old length."));
			CheckValid(enable, !txtPrecision->IsEnabled() || varprec >= column->GetPrecision(),
			           _("New precision must not be less than old precision."));
			CheckValid(enable, !txtPrecision->IsEnabled() || varlen - varprec >= column->GetLength() - column->GetPrecision(),
			           _("New total digits must not be less than old total digits."));
		}

		if (enable)
			enable = GetName() != column->GetName()
			         || txtDefault->GetValue() != column->GetDefault()
			         || txtComment->GetValue() != column->GetComment()
			         || chkNotNull->GetValue() != column->GetNotNull()
			         || (cbDatatype->GetCount() > 1 && cbDatatype->GetGuessedStringSelection() != column->GetRawTypename() && !column->GetIsArray())
			         || (cbDatatype->GetCount() > 1 && cbDatatype->GetGuessedStringSelection() != column->GetRawTypename() + wxT("[]") && column->GetIsArray())
			         || (!cbCollation->GetValue().IsEmpty() && cbCollation->GetValue() != column->GetCollation())
			         || (isVarLen && varlen != column->GetLength())
			         || (isVarPrec && varprec != column->GetPrecision())
			         || txtAttstattarget->GetValue() != NumToStr(column->GetAttstattarget())
			         || cbStorage->GetValue() != column->GetStorage()
			         || dirtyVars;

		if (seclabelPage && connection->BackendMinimumVersion(9, 1))
			enable = enable || !(seclabelPage->GetSqlForSecLabels().IsEmpty());

		EnableOK(enable || securityChanged);
	}
	else
	{
		txtPrecision->Enable(isVarPrec && varlen > 0);

		wxString name = GetName();

		CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
		CheckValid(enable, cbDatatype->GetGuessedSelection() >= 0, _("Please select a datatype."));
		CheckValid(enable, !isVarLen || txtLength->GetValue().IsEmpty()
		           || (varlen >= minVarLen && varlen <= maxVarLen && NumToStr(varlen) == txtLength->GetValue()),
		           _("Please specify valid length."));
		CheckValid(enable, !txtPrecision->IsEnabled()
		           || (varprec >= 0 && varprec <= varlen && NumToStr(varprec) == txtPrecision->GetValue()),
		           _("Please specify valid numeric precision (0..") + NumToStr(varlen) + wxT(")."));

		EnableOK(enable);
	}
}
示例#5
0
void dlgColumn::ApplyChangesToObj(pgColumn *changedCol)
{
	changedCol->iSetName(txtName->GetValue());
	changedCol->iSetComment(txtComment->GetValue());

	changedCol->iSetRawTypename(cbDatatype->GetValue());

	if (!txtLength->GetValue().IsEmpty())
		changedCol->iSetLength(StrToLong(txtLength->GetValue()));
	if (!txtPrecision->GetValue().IsEmpty())
		changedCol->iSetPrecision(StrToLong(txtPrecision->GetValue()));
	changedCol->iSetCollation(cbCollation->GetValue());

	changedCol->iSetStorage(cbStorage->GetValue());
	changedCol->iSetAttstattarget(StrToLong(txtAttstattarget->GetValue()));
	changedCol->iSetNotNull(chkNotNull->GetValue());
	changedCol->iSetDefault(txtDefault->GetValue());

	changedCol->GetVariables().Clear();
	for (int pos = 0 ; pos < lstVariables->GetItemCount() ; pos++)
	{
		changedCol->GetVariables().Add(lstVariables->GetText(pos) + wxT("=") + lstVariables->GetText(pos, 1));
	}

	if(securityPage && connection->BackendMinimumVersion(8, 4))
	{
		changedCol->iSetAcl(securityPage->GetUserPrivileges());
	}

	if(seclabelPage && connection->BackendMinimumVersion(9, 1))
	{
		wxArrayString secLabels;
		wxString providers;
		wxString labels;
		seclabelPage->GetCurrentProviderLabelArray(secLabels);

		if(!secLabels.IsEmpty())
		{
			for(size_t pos = 0; pos < secLabels.Count(); pos += 2)
			{
				if(pos == 0)
				{
					providers += wxT("{") + secLabels.Item(pos);
					labels += wxT("{") + secLabels.Item(pos + 1);
				}
				else
				{
					providers += wxT(",") + secLabels.Item(pos);
					labels += wxT(",") + secLabels.Item(pos + 1);
				}
			}
			providers += wxT("}");
			labels += wxT("}");
		}
		changedCol->iSetProviders(providers);
		changedCol->iSetLabels(labels);
	}
}
示例#6
0
void dlgServer::CheckChange()
{
	wxString name = GetName();
	bool enable = true;

	if (server)
	{
		// Get old value
		wxColour colour;
		wxString sColour = wxEmptyString;

		if (colour.Set(server->GetColour()))
			sColour = colour.GetAsString(wxC2S_HTML_SYNTAX);

		// Get new value
		wxString sColour2 = colourPicker->GetColourString();

		enable =  name != server->GetName()
		          || txtHostAddr->GetValue() != server->GetHostAddr()
		          || txtDescription->GetValue() != server->GetDescription()
		          || txtService->GetValue() != server->GetService()
		          || txtServiceID->GetValue() != server->GetServiceID()
		          || StrToLong(txtPort->GetValue()) != server->GetPort()
		          || cbDatabase->GetValue() != server->GetDatabaseName()
		          || txtUsername->GetValue() != server->GetUsername()
		          || cbSSL->GetCurrentSelection() != server->GetSSL()
		          || chkStorePwd->GetValue() != server->GetStorePwd()
		          || txtRolename->GetValue() != server->GetRolename()
		          || chkRestore->GetValue() != server->GetRestore()
		          || txtDbRestriction->GetValue() != server->GetDbRestriction()
		          || sColour != sColour2
		          || cbGroup->GetValue() != server->GetGroup()
		          || pickerSSLCert->GetPath() != server->GetSSLCert()
		          || pickerSSLKey->GetPath() != server->GetSSLKey()
		          || pickerSSLRootCert->GetPath() != server->GetSSLRootCert()
		          || pickerSSLCrl->GetPath() != server->GetSSLCrl()
		          || chkSSLCompression->GetValue() != server->GetSSLCompression();
	}

#ifdef __WXMSW__
	CheckValid(enable, !name.IsEmpty(), _("Please specify address."));
#else
	bool isPipe = (name.IsEmpty() || name.StartsWith(wxT("/")));
	cbSSL->Enable(!isPipe && !connection);
#endif
	CheckValid(enable, !txtDescription->GetValue().IsEmpty(), _("Please specify description."));
	if (txtService->GetValue().IsEmpty())
	{
		CheckValid(enable, StrToLong(txtPort->GetValue()) > 0, _("Please specify port."));
		CheckValid(enable, !txtUsername->GetValue().IsEmpty(), _("Please specify user name"));
	}
	CheckValid(enable, dbRestrictionOk, _("Restriction not valid."));

	EnableOK(enable && !connection);
}
LONG CItemPageAnalyzeBase::_GetPriceInfo(CComQIPtr<IHTMLElementCollection>& spChildElements, INT nGoldIndex, INT nSilverIndex, INT nCopperIndex)
{
	LONG nPrice = 0;
	LONG nGold = StrToLong(_GetCollectionItemValue(spChildElements, nGoldIndex, ivtInnerText));
	LONG nSilver = StrToLong(_GetCollectionItemValue(spChildElements, nSilverIndex, ivtInnerText));
	LONG nCopper = StrToLong(_GetCollectionItemValue(spChildElements, nCopperIndex, ivtInnerText));

	nPrice = nGold * 10000 + nSilver * 100 + nCopper;
	//FTLTRACE(TEXT("_GetPriceInfo for %d,%d,%d is %d\n"), nGoldIndex, nSilverIndex, nCopperIndex, nPrice);

	return nPrice;
}
HRESULT CSellerItemPageAnalyze::_GetRowItemInfo(const CString& strTableName, CComQIPtr<IHTMLElementCollection>& spChildElements, 
												   WowItemInfoPtr& spItemInfo, 
												   const CString& strSearchItemName)
{
	HRESULT hr = E_FAIL;
	long nLength = 0;
	COM_VERIFY(spChildElements->get_length(&nLength));
	FTLASSERT(nLength >= siiMinCount);

	spItemInfo->SetItemStatus(isOtherSelling);

	if (nLength > siiMinCount)
	{
		CString strItemName = _GetCollectionItemValue(spChildElements, siiName, ivtInnerText);
		if (strSearchItemName.IsEmpty() || strSearchItemName == strItemName)
		{
			//搜索全部或当前的项目名就是需要搜索的项目
			CString strUrl = _GetCollectionItemValue(spChildElements, siiTypeUrl, ivtToString);
			spItemInfo->SetUrl(strUrl);
			int nPosSlash = strUrl.ReverseFind(_T('/'));
			if (nPosSlash > 0)
			{
				CString strTypeId = strUrl.Mid(nPosSlash + 1);
				spItemInfo->SetTypeId(StrToLong(strTypeId));
			}

			spItemInfo->SetItemName(strItemName);
			spItemInfo->SetSeller(_GetCollectionItemValue(spChildElements, siiSeller, ivtInnerText));
			spItemInfo->SetQuantity(StrToLong(_GetCollectionItemValue(spChildElements, siiQuantity, ivtInnerText)));

			CString strTimeInfo = _GetCollectionItemValue(spChildElements, siiTimeInfo, ivtInnerText);
			spItemInfo->SetItemSellTimeInfo(_ConvertTimeInfo(strTimeInfo));

			spItemInfo->SetPriceBid(_GetPriceInfo(spChildElements, siiPriceBidGold, siiPriceBidSilver, siiPriceBidCopper));
			spItemInfo->SetPriceBuyout(_GetPriceInfo(spChildElements, siiPriceBuyoutGold, siiPriceBuyoutSilver, siiPriceBuyoutCopper));

			//最后才更新时间 -- 保证 SetItemSellTimeInfo 时能获取到上次更新的时间信息
			//spItemInfo->UpdateRefreshTime();
		}
	}
	else
	{
		hr = E_FAIL;
		FTLASSERT(FALSE && _T("Web Page Change"));
	}

	return hr;
}
示例#9
0
wxString dlgGroup::GetSql()
{
    wxString sql;
    wxString name = GetName();
    int cnt, pos;

    if (group)
    {
        // Edit Mode

        AppendNameChange(sql);

        cnt = lbUsersIn->GetCount();
        wxArrayString tmpUsers = group->GetUsersIn();

        // check for added users
        for (pos = 0 ; pos < cnt ; pos++)
        {
            wxString userName = lbUsersIn->GetString(pos);

            int index = tmpUsers.Index(userName);
            if (index >= 0)
                tmpUsers.RemoveAt(index);
            else
                sql += wxT("ALTER GROUP ") + qtIdent(name)
                       +  wxT("\n  ADD USER ") + qtIdent(userName) + wxT(";\n");
        }

        // check for removed users
        for (pos = 0 ; pos < (int)tmpUsers.GetCount() ; pos++)
        {
            sql += wxT("ALTER GROUP ") + qtIdent(name)
                   +  wxT("\n  DROP USER ") + qtIdent(tmpUsers.Item(pos)) + wxT(";\n");
        }
    }
    else
    {
        // Create Mode
        wxString name = GetName();

        long id = StrToLong(txtID->GetValue());

        sql = wxT(
                  "CREATE GROUP ") + qtIdent(name);
        if (id)
            sql += wxT("\n  WITH SYSID ") + NumToStr(id);
        cnt = lbUsersIn->GetCount();
        if (cnt)
            sql += wxT("\n   USER ");
        for (pos = 0 ; pos < cnt ; pos++)
        {
            if (pos)
                sql += wxT(", ");
            sql += qtIdent(lbUsersIn->GetString(pos));
        }
        sql += wxT(";\n");

    }
    return sql;
}
示例#10
0
wxString dlgRepSequence::GetSql()
{
	wxString sql;

	if (sequence)
	{
		// edit mode
	}
	else
	{
		// create mode

		sql = wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("setaddsequence(")
		      + NumToStr(set->GetSlId()) + wxT(", ");

		if (StrToLong(txtID->GetValue()) > 0)
			sql += txtID->GetValue();
		else
			sql += wxT("(SELECT COALESCE(MAX(seq_id), 0) + 1 FROM ") + cluster->GetSchemaPrefix() + wxT("sl_sequence)");

		sql += wxT(", ") + qtDbString(cbSequence->GetGuessedStringSelection())
		       +  wxT(", ") + qtDbString(txtComment->GetValue())
		       + wxT(")\n");
	}

	return sql;
}
示例#11
0
void dlgJob::OnChangeSchedule(wxCommandEvent &ev)
{
	long pos = lstSchedules->GetSelection();
	pgaSchedule *obj = (pgaSchedule *) StrToLong(lstSchedules->GetText(pos, 3));

	dlgSchedule schedule(&scheduleFactory, mainForm, obj, job);
	schedule.CenterOnParent();
	schedule.SetConnection(connection);

	if (schedule.Go(true) != wxID_CANCEL)
	{
		lstSchedules->SetItem(pos, 0, schedule.GetName());
		lstSchedules->SetItem(pos, 1, schedule.GetComment());

		if (lstSchedules->GetText(pos, 3).IsEmpty())
		{
			wxString *scheduleSql = new wxString(schedule.GetInsertSql());
			lstSchedules->SetItemData(pos, (long)scheduleSql);
		}
		else
		{
			wxString *scheduleSql = new wxString(schedule.GetUpdateSql());
			lstSchedules->SetItemData(pos, (long)scheduleSql);
		}

		CheckChange();
	}
}
示例#12
0
void FAdWindow::OnAdLoaded()
{
	m_bAdLoaded = TRUE; 
	m_bAdInProgress = FALSE; 

	//Update timeout values, etc.

	long dwTimeout = StrToLong(CallScriptStr("ltv_getAdDuration", ""));
	
	if (dwTimeout <= 0)
		dwTimeout = (long)m_CurrentItem.m_TimeoutMS;

	if (dwTimeout > 0)
		m_CurrentItem.m_dwFlags &= ~AD_FLAG_PERSISTENT; 
	else //timeout is 0
	{
		if (m_CurrentItem.m_TimeEndMS == 0)	//has end position ?
			dwTimeout = DEFAULT_AD_DURATION; 
	}

	if (m_CurrentItem.m_dwFlags & AD_FLAG_PERSISTENT)
	{
		//Persistent, no timer required.
	}
	else
	{
		m_CurrentItem.m_TimeoutMS = dwTimeout; 
	}
}
示例#13
0
void pgUser::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
    if (!expandedKids)
    {
        expandedKids = true;

        pgSet *set = GetServer()->ExecuteSet(wxT("SELECT groname, grolist FROM pg_group ORDER BY groname"));
        if (set)
        {
            while (!set->Eof())
            {
                wxString groupName = set->GetVal(wxT("groname"));
                wxString str = set->GetVal(wxT("grolist"));
                if (!str.IsNull())
                {
                    wxStringTokenizer ids(str.Mid(1, str.Length() - 2), wxT(","));
                    while (ids.HasMoreTokens())
                    {
                        if (StrToLong(ids.GetNextToken()) == GetUserId())
                        {
                            groupsIn.Add(groupName);
                            break;
                        }
                    }
                }
                set->MoveNext();
            }
            delete set;
        }
    }
    if (properties)
    {
        CreateListColumns(properties);

        properties->AppendItem(_("Name"), GetName());
        properties->AppendItem(_("User ID"), GetUserId());
        properties->AppendItem(_("Account expires"), DateToAnsiStr(GetAccountExpires()));
        properties->AppendItem(_("Superuser?"), BoolToYesNo(GetSuperuser()));
        properties->AppendItem(_("Create databases?"), BoolToYesNo(GetCreateDatabase()));
        properties->AppendItem(_("Update catalogs?"), BoolToYesNo(GetUpdateCatalog()));

        wxString groupList;

        size_t index;
        for (index = 0 ; index < groupsIn.GetCount() ; index++)
        {
            if (!groupList.IsEmpty())
                groupList += wxT(", ");
            groupList += groupsIn.Item(index);
        }
        properties->AppendItem(_("Member of"), groupList);

        for (index = 0; index < configList.GetCount() ; index++)
        {
            wxString item = configList.Item(index);
            properties->AppendItem(item.BeforeFirst('='), item.AfterFirst('='));
        }
    }
}
HRESULT CMyAuctionItemPageAnalyze::_InnerGetAuctionsActiveRowItemInfo(CComQIPtr<IHTMLElementCollection>& spChildElements, 
															WowItemInfoPtr& spItemInfo, 
															const CString& strSearchItemName)
{
	//CFHTMLElementCollectionDumper dumper(spChildElements, CFOutputWindowInfoOutput::Instance(), 0);

	HRESULT hr = E_FAIL;
	long nLength = 0;
	COM_VERIFY(spChildElements->get_length(&nLength));
	FTLASSERT(nLength >= AuctionsActive::siiMinCount);
	if (nLength >= AuctionsActive::siiMinCount)
	{
		spItemInfo->SetItemStatus(isMyAuctionActive);

		CString strItemName = _GetCollectionItemValue(spChildElements, AuctionsActive::siiName, ivtInnerText);
		if (strSearchItemName.IsEmpty() || strSearchItemName == strItemName)
		{
			CString strUrl = _GetCollectionItemValue(spChildElements, AuctionsActive::siiTypeUrl, ivtToString);
			spItemInfo->SetUrl(strUrl);
			int nPosSlash = strUrl.ReverseFind(_T('/'));
			if (nPosSlash > 0)
			{
				CString strTypeId = strUrl.Mid(nPosSlash + 1);
				spItemInfo->SetTypeId(StrToLong(strTypeId));
			}

			spItemInfo->SetItemName(strItemName);
			spItemInfo->SetSeller(_GetCollectionItemValue(spChildElements, AuctionsActive::siiSeller, ivtInnerText));
			spItemInfo->SetQuantity(StrToLong(_GetCollectionItemValue(spChildElements, AuctionsActive::siiQuantity, ivtInnerText)));

			CString strTimeInfo = _GetCollectionItemValue(spChildElements, AuctionsActive::siiTimeInfo, ivtInnerText, TRUE);
			spItemInfo->SetItemSellTimeInfo(_ConvertTimeInfo(strTimeInfo));
			CString strCurBid = _GetCollectionItemValue(spChildElements, AuctionsActive::siiCurrentBid, ivtInnerText, TRUE);

			spItemInfo->SetPriceBid(_GetPriceInfo(spChildElements, AuctionsActive::siiPriceBidGold, 
				AuctionsActive::siiPriceBidSilver, AuctionsActive::siiPriceBidCopper));
			spItemInfo->SetPriceBuyout(_GetPriceInfo(spChildElements, AuctionsActive::siiPriceBuyoutGold, 
				AuctionsActive::siiPriceBuyoutSilver, AuctionsActive::siiPriceBuyoutCopper));

			//最后才更新时间 -- 保证 SetItemSellTimeInfo 时能获取到上次更新的时间信息
			//spItemInfo->UpdateRefreshTime();
		}
	}

	return hr;
}
示例#15
0
/*
 * serveraccept:
 *      Accept a server socket from the named port
 */
long
serveraccept(char *pname, struct sockaddr_in *ha)
{
  struct sockaddr_in sin; 
  long ha_len = sizeof(*ha);
  int s, sa;
  long port;
  struct servent *sp;
  long on = 1;

  /* Create address corresponding our service */
  bzero((caddr_t)&sin, sizeof(sin));
  sin.sin_len = sizeof(struct sockaddr_in);
  sin.sin_family = AF_INET;

  /* A port must be in the range 1 - 65535 */
  if (StrToLong(pname, &port) > 0 && port < 65536 )
    sin.sin_port = port;
  else if (sp = getservbyname(pname, "tcp"))
    sin.sin_port = sp->s_port;
  else {
    return -1;
  }

  sin.sin_addr.s_addr = INADDR_ANY;

  if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    PrintNetFault(Errno(), "socket");
    return -1;
  }

  /* Reuse this port */
  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) {
    PrintNetFault(Errno(), "setsockopt");
    sa = -1; goto Return;
  }

  /* Bind it to socket */
  if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0 ) {
    PrintNetFault(Errno(), "bind");
    sa = -1; goto Return;
  }

  if (listen(s, 1) < 0) {
    PrintNetFault(Errno(), "listen");
    sa = -1; goto Return;
  }

  if ((sa = accept(s, (struct sockaddr *)ha, &ha_len)) < 0){
    PrintNetFault(Errno(), "accept");
  }

 Return:
  CloseSocket(s);
  return sa;
}
示例#16
0
dlgServer::~dlgServer()
{
	if (!server)
	{
		settings->SetLastDatabase(cbDatabase->GetValue());
		settings->SetLastPort(StrToLong(txtPort->GetValue()));
		settings->SetLastSSL(cbSSL->GetCurrentSelection());
		settings->SetLastUsername(txtUsername->GetValue());
	}
}
示例#17
0
long slNode::GetOutstandingAcks()
{
	long l = StrToLong(GetDatabase()->ExecuteScalar(
	                       wxT("SELECT SUM(st_lag_num_events) AS sumlagevents\n")
	                       wxT("  FROM ") + GetCluster()->GetSchemaPrefix() + wxT("sl_status\n")
	                       wxT(" WHERE st_origin = ") + NumToStr(GetCluster()->GetLocalNodeID()) + wxT("\n")
	                       wxT("  GROUP BY st_last_event")));

	return l;
}
示例#18
0
LONG ArgInt(char **tt, STRPTR entry, LONG defaultval)
{
STRPTR result;

   if (tt && (result = FindToolType(tt,entry)))
   {
       StrToLong(result,&defaultval);
   }

   return (defaultval);
}
示例#19
0
void Trainer2::ReadPartitionData(std::string data_file) {
  
  char *line = NULL;
  size_t num_byte;
  size_t num_token = 0;
  FILE *data_fp = fopen(data_file.c_str(), "r");
  CHECK_NOTNULL(data_fp);
  int linecnt = 0;
  while (getline(&line, &num_byte, data_fp) != -1) {
    if(linecnt% workers_ != threadid){
      linecnt++;
      continue;
    }
    linecnt++;
    Data doc;
    char *ptr = line;
    while (*ptr++ != ' '); // ptr at first space
    while (*ptr != ' ') ++ptr; // ptr at second space
    while (*ptr != '\n') {
      int word_id = StrToLong(++ptr, &ptr); // ptr at space or \n
      doc.token_.push_back(word_id);
      ++num_token;
    }
    eval_.emplace_back(doc); // reason in next paragraph
  }
  fclose(data_fp);
  free(line);
  // Construct inverted index from docs, while separating out test set
  std::shuffle(RANGE(eval_), _rng);
  for (size_t doc_id = 0; doc_id < eval_.size() - eval_size_; ++doc_id) {
    for (const auto word_id : eval_[doc_id].token_) {
      if (data_.size() <= (size_t)word_id)
        data_.resize(word_id + 1); // zero-based
      data_[word_id].token_.push_back(doc_id);
    }
  }
  stat_.resize(eval_.size() - eval_size_); 
  mutex_pool_.reset(new std::mutex[stat_.size()+1]); // for multi threading version 

  // stat_ size is small now since now eval_ have only small portion after switching to dist version.
  // but no problem... it will expand dynamically. 
  eval_.erase(eval_.begin(), eval_.end() - eval_size_);
  num_token_ = num_token;
  vocnt_ = data_.size();

  LOG(INFO) << "num doc (train): " << stat_.size();
  LOG(INFO) << "num doc (eval): " << eval_.size();
  LOG(INFO) << "num word (total): " << data_.size(); 
  LOG(INFO) << "num token (total): " << num_token;
  LOG(INFO) << "total workers (total): " << workers_;
  LOG(INFO) << "ALPHA: " << ALPHA;
  LOG(INFO) << "BETA: " << BETA;
  LOG(INFO) << "--------------------------------------------------------------";
}
示例#20
0
long slCluster::GetSlonPid()
{
	long slonPid;
	wxString pidcol = GetConnection()->BackendMinimumVersion(9, 2) ? wxT("pid") : wxT("procpid");

	if (GetConnection()->BackendMinimumVersion(9, 0))
	{
		slonPid = StrToLong(GetConnection()->ExecuteScalar(
		                        wxT("SELECT nl_backendpid FROM ") + qtIdent(wxT("_") + GetName()) + wxT(".sl_nodelock nl, ")
		                        wxT("pg_stat_activity sa WHERE nl.nl_backendpid = sa.") + pidcol + wxT(" AND nl_nodeid = ")
		                        + NumToStr(GetLocalNodeID())));
	}
	else
	{
		slonPid = StrToLong(GetConnection()->ExecuteScalar(
		                        wxT("SELECT listenerpid FROM pg_listener WHERE relname = ")
		                        + qtDbString(wxT("_") + GetName() + wxT("_Event"))));
	}

	return slonPid;
}
示例#21
0
pgObject *dlgRepSet::CreateObject(pgCollection *collection)
{
	wxString restriction;
	if (StrToLong(txtID->GetValue()) > 0)
		restriction = txtID->GetValue();
	else
		restriction = wxT("(SELECT MAX(set_id) FROM ") + cluster->GetSchemaPrefix() + wxT("sl_set)");

	pgObject *obj = setFactory.CreateObjects(collection, 0,
	                wxT(" WHERE set_id = ") + restriction);

	return obj;
}
示例#22
0
void FAdWindow::OnDocumentComplete(DWORD dwID, BOOL bMainFrame)
{
	m_bAdLoaded = TRUE; 

	if (!m_bAdInProgress)	
		return ; //Ad canceled.

	long lHeight = StrToLong(CallScriptStr("ltv_getAdHeight", ""));
	long lWidth = StrToLong(CallScriptStr("ltv_getAdWidth", ""));

	FString Str;
	Str.Format("%u", GetId());
	CallJScript("ltv_setWindowID", Str);
	Str.Format("%u", m_InitData.m_AdType);
	CallJScript("ltv_setAdType", Str); 

	if (lHeight > 0)
		m_CurrentItem.m_Height = lHeight; 

	if (lWidth > 0)
		m_CurrentItem.m_Width = lWidth; 

	if (m_CurrentItem.m_Height == 0 && (m_CurrentItem.m_Type == AdHBottom || m_CurrentItem.m_Type == AdHTop))
	{
		m_CurrentItem.m_Height = 90; 
	}

	if (m_CurrentItem.m_Width == 0 && (m_CurrentItem.m_Type == AdVLeft || m_CurrentItem.m_Type == AdVRight))
	{
		m_CurrentItem.m_Width = 90;
	}

	OnAdLoaded();	
	m_InitData.m_pNotify->OnDocumentComplete(dwID, bMainFrame); 
	m_CurrentItem.m_LastDisplay = GetTickCount(); 
	
}
示例#23
0
void dlgDomain::CheckChange()
{
	bool enable = true;

	if (domain)
	{
		enable = txtName->GetValue() != domain->GetName()
                 || txtDefault->GetValue() != domain->GetDefault()
		         || cbSchema->GetValue() != domain->GetSchema()->GetName()
		         || chkNotNull->GetValue() != domain->GetNotNull()
		         || txtCheck->GetValue() != domain->GetCheck()
		         || cbOwner->GetValue() != domain->GetOwner()
		         || txtComment->GetValue() != domain->GetComment();
		if (connection->BackendMinimumVersion(9, 2) && !domain->GetValid() && !chkDontValidate->GetValue())
			enable = true;
		if (seclabelPage && connection->BackendMinimumVersion(9, 1))
			enable = enable || !(seclabelPage->GetSqlForSecLabels().IsEmpty());
	}
	else
	{
		wxString name = GetName();
		long varlen = StrToLong(txtLength->GetValue()),
		     varprec = StrToLong(txtPrecision->GetValue());

		txtPrecision->Enable(isVarPrec && varlen > 0);

		CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
		CheckValid(enable, cbDatatype->GetGuessedSelection() >= 0, _("Please select a datatype."));
		CheckValid(enable, !isVarLen || txtLength->GetValue().IsEmpty()
		           || (varlen >= minVarLen && varlen <= maxVarLen && NumToStr(varlen) == txtLength->GetValue()),
		           _("Please specify valid length."));
		CheckValid(enable, !txtPrecision->IsEnabled()
		           || (varprec >= 0 && varprec <= varlen && NumToStr(varprec) == txtPrecision->GetValue()),
		           _("Please specify valid numeric precision (0..") + NumToStr(varlen) + wxT(")."));
	}
	EnableOK(enable);
}
示例#24
0
pgObject *dlgServer::CreateObject(pgCollection *collection)
{
	wxString name = GetName();

	pgServer *obj = new pgServer(GetName(), txtHostAddr->GetValue(), txtDescription->GetValue(),
	                             txtService->GetValue(), cbDatabase->GetValue(),
	                             txtUsername->GetValue(), StrToLong(txtPort->GetValue()),
	                             chkTryConnect->GetValue() && chkStorePwd->GetValue(),
	                             txtRolename->GetValue(), chkRestore->GetValue(), cbSSL->GetCurrentSelection(),
	                             colourPicker->GetColourString(), cbGroup->GetValue());

	obj->iSetDbRestriction(txtDbRestriction->GetValue().Trim());

	return obj;
}
示例#25
0
wxString dlgRepPath::GetSql()
{
	wxString sql;

	int sel = cbServer->GetCurrentSelection();

	if (sel >= 0)
	{
		sql = wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("storepath(")
		      + NumToStr((OID)cbServer->wxItemContainer::GetClientData(sel)) + wxT(", ")
		      + NumToStr(node->GetSlId()) + wxT(", ")
		      + qtDbString(txtConnInfo->GetValue()) + wxT(", ")
		      + NumToStr(StrToLong(txtConnRetry->GetValue())) + wxT(");");
	}
	return sql;
}
示例#26
0
文件: fileicon.c 项目: mingpen/OpenNT
int GetRegInt(HKEY hk, LPCTSTR szKey, int def)
{
    DWORD cb;
    TCHAR ach[20];

    if (hk == NULL)
        return def;

    ach[0] = 0;
    cb = SIZEOF(ach);
    RegQueryValueEx(hk, szKey, NULL, NULL, (LPBYTE)ach, &cb);

    if (ach[0] >= TEXT('0') && ach[0] <= TEXT('9'))
        return (int)StrToLong(ach);
    else
        return def;
}
示例#27
0
wxString dlgRepSet::GetSql()
{
	wxString sql;

	sql = wxT("-- Create replication set\n\n")
	      wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("storeset(");

	if (StrToLong(txtID->GetValue()) > 0)
		sql += txtID->GetValue();
	else
		sql += wxT("(SELECT COALESCE(MAX(set_id), 0) + 1 FROM ")
		       +  cluster->GetSchemaPrefix() + wxT("sl_set)");

	sql += wxT(", ") + qtDbString(txtComment->GetValue())
	       +  wxT(");\n");

	return sql;
}
示例#28
0
int main(int argc, char **argv)
{
    long val;
    long long val2;
    int ret;
    
    if (argc < 2)
    {
        printf("Usage: %s str [base]\n", argv[0]);
        return -1;
    }
    
    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());
    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());

    ret = StrToLong(argv[1], &val, (argc < 3) ? 0 : atoi(argv[2]));
    if (ret < 0)
    {
        printf("StrToLong failed. [ret: %d]\n", ret);
    }
    else
    {
        printf("%ld\n", val);
    }

    ret = StrToLongLong(argv[1], &val2, (argc < 3) ? 0 : atoi(argv[2]));
    if (ret < 0)
    {
        printf("StrToLongLong failed. [ret: %d]\n", ret);
    }
    else
    {
        printf("%lld\n", val2);
    }
    
    usleep(1000 * 1000);

    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());
    printf("GetCycleCount: %lld, GetMsCount: %lld, GetSecCount: %lld\n", GetCycleCount(), GetMsCount(), GetSecCount());
    
    return 0;
        
}
示例#29
0
void dlgRepPath::CheckChange()
{
	if (path)
	{
		EnableOK(txtConnInfo->GetValue() != path->GetConnInfo()
		         ||   StrToLong(txtConnRetry->GetValue()) != path->GetConnRetry());
	}
	else
	{
		bool enable = true;
		CheckValid(enable, cbServer->GetCount() > 0, _("No provider node without path definition left."));
		CheckValid(enable, cbServer->GetCurrentSelection() >= 0, _("Please select provider node."));

		wxString connInfo = txtConnInfo->GetValue();
		CheckValid(enable, connInfo.Find(wxT("host=")) >= 0, _("Please provide host in connect info."));
		CheckValid(enable, connInfo.Find(wxT("dbname=")) >= 0, _("Please provide dbname in connect info."));
		CheckValid(enable, connInfo.Find(wxT("user="******"Please provide user in connect info."));

		EnableOK(enable);
	}
}
示例#30
0
wxString dlgRepNode::GetSql()
{
	wxString sql;

	sql = wxT("-- Create replication node\n\n")
	      wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("storenode(");

	if (StrToLong(txtID->GetValue()) > 0)
		sql += txtID->GetValue();
	else
		sql += wxT("(SELECT COALESCE(MAX(no_id), 0) + 1 FROM ")
		       +  cluster->GetSchemaPrefix() + wxT("sl_node)");

	sql += wxT(", ") + qtDbString(txtComment->GetValue());

	// The spool parameter was removed for Slony 2.0
	if (!cluster->ClusterMinimumVersion(2, 0))
		sql +=  wxT(", false");

	sql += wxT(");\n");

	return sql;
}