×
Namespaces

Variants
Actions

创建cmwap接入点

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台: S60 3rd Edition, FP2

文章
关键词: CCommsDatabase
zengcity 在 20 Jul 2009 创建
最后由 hamishwillee 在 19 Oct 2011 编辑

创建cmwap接入点

  • 开发平台:

S60 3rd Edition, FP2

  • 代码:
_LIT(KDefaultIapName,"Nokia.com");
 
TInt CHIAPEngine::CreateWapAp(){
TCommDbOpeningMethod OpeningMethod;
TInt error;
TUint32 GPRSId;
 
// 还是打开common db这个数据库,与上次的只读不同,这次是准备写入了
CCommsDatabase* commsDb = CCommsDatabase::NewL(EDatabaseTypeIAP,OpeningMethod);
CleanupStack::PushL(commsDb);
 
// 打开common db数据库中的OUTGOING_GPRS表,这个表是存放gprs
// 对外连接方式数据的
CCommsDbTableView* commsView = commsDb->OpenTableLC(TPtrC(OUTGOING_GPRS));
 
//插入一条数据,id是GPRSId
TRAP(error,commsView->InsertRecord(GPRSId));
if (error!=KErrNone) return -1;
 
// 这里是写入这个接入点的设置,就跟在手机中设置接入点是一样的
// 但是需要加入好多BOOL值
commsView->WriteTextL(TPtrC(COMMDB_NAME),KDefaultIapName);
commsView->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), ETrue);
commsView->WriteBoolL(TPtrC(GPRS_IP_ADDR_FROM_SERVER), ETrue);
commsView->WriteBoolL(TPtrC(GPRS_IP_DNS_ADDR_FROM_SERVER), ETrue);
commsView->WriteTextL(TPtrC(GPRS_IP_GATEWAY), _L("0.0.0.0"));
commsView->WriteTextL(TPtrC(GPRS_IF_AUTH_NAME), _L(""));
commsView->WriteTextL(TPtrC(GPRS_IF_AUTH_PASS),_L(""));
commsView->WriteTextL(TPtrC(GPRS_APN), _L("cmwap"));
commsView->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0);
commsView->WriteBoolL(TPtrC(GPRS_IF_PROMPT_FOR_AUTH), EFalse);
commsView->WriteTextL(TPtrC(GPRS_IF_NETWORKS), _L("ip"));
commsView->WriteBoolL(TPtrC(GPRS_HEADER_COMPRESSION), EFalse);
commsView->WriteBoolL(TPtrC(GPRS_DATA_COMPRESSION), EFalse);
commsView->WriteUintL(TPtrC(GPRS_REQ_PRECEDENCE), 0);
commsView->WriteUintL(TPtrC(GPRS_REQ_DELAY), 0);
commsView->WriteUintL(TPtrC(GPRS_REQ_RELIABILITY), 0);
commsView->WriteUintL(TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0);
commsView->WriteUintL(TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0);
commsView->WriteUintL(TPtrC(GPRS_MIN_PRECEDENCE), 0);
commsView->WriteUintL(TPtrC(GPRS_MIN_DELAY), 0);
commsView->WriteUintL(TPtrC(GPRS_MIN_RELIABILITY), 0);
commsView->WriteUintL(TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0);
commsView->WriteUintL(TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0);
commsView->WriteBoolL(TPtrC(GPRS_ANONYMOUS_ACCESS), EFalse);
commsView->WriteBoolL(TPtrC(GPRS_USE_EDGE), EFalse);
commsView->WriteBoolL(TPtrC(GPRS_ENABLE_LCP_EXTENSIONS), EFalse);
commsView->WriteBoolL(TPtrC(GPRS_DISABLE_PLAIN_TEXT_AUTH), EFalse);
commsView->WriteUintL(TPtrC(GPRS_AP_TYPE), 0);
commsView->WriteUintL(TPtrC(GPRS_QOS_WARNING_TIMEOUT), -1);
commsView->WriteUintL(TPtrC(GPRS_PDP_TYPE), 0);
commsView->WriteTextL(TPtrC(GPRS_PDP_ADDRESS), _L(""));
commsView->WriteTextL(TPtrC(GPRS_IF_PARAMS), _L(""));
commsView->WriteUintL(TPtrC(GPRS_IF_AUTH_RETRIES), 0);
commsView->WriteTextL(TPtrC(GPRS_IP_NETMASK), _L(""));
commsView->WriteTextL(TPtrC(GPRS_IP_ADDR),_L("0.0.0.0"));
commsView->WriteTextL(TPtrC(GPRS_IP_NAME_SERVER1),_L("0.0.0.0"));
commsView->WriteTextL(TPtrC(GPRS_IP_NAME_SERVER2),_L("0.0.0.0"));
 
// 告诉common db的view类数据已经变化了,使添加生效
// 在加入新的记录之前,必须调用这个PutRecordChanges函数
// 否则就前面那些设置就白忙活了。
TRAP(error,commsView->PutRecordChanges());
if (error!=KErrNone) return -1;
 
CleanupStack::PopAndDestroy(commsView);
 
// 在NETWORK表中添加记录
TUint32 networkId;
commsView = commsDb->OpenTableLC(TPtrC(NETWORK));
TRAP(error,commsView->InsertRecord(networkId));
if (error!=KErrNone) return -1;
// 设置数据内容
commsView->WriteTextL(TPtrC(COMMDB_NAME), _L("WayneNETWORK"));
// 保存设置,并使添加操作生效
TRAP(error,commsView->PutRecordChanges(EFalse, EFalse));
if (error!=KErrNone) return -1;
CleanupStack::PopAndDestroy(commsView);
 
// 查找手机的LOCATION ID
TInt result;
TUint32 locationId;
TUint32 mobileLocationId;
commsView = commsDb->OpenTableLC(TPtrC(LOCATION));
result = commsView->GotoFirstRecord();
TBuf<128> locationName;
while (result == KErrNone) {
commsView->ReadTextL(TPtrC(COMMDB_NAME), locationName);
commsView->ReadUintL(TPtrC(LOCATION_MOBILE), locationId);
if (locationName.Match(_L("Mobile"))!= KErrNotFound)
mobileLocationId = locationId;
result = commsView->GotoNextRecord();
}
CleanupStack::PopAndDestroy(commsView);
 
// 利用刚刚找到的LOCATION ID在IAP表中添加记录
TUint32 iapId;
commsView = commsDb->OpenTableLC(TPtrC(IAP));
TRAP(error,commsView->InsertRecord(iapId));
if (error!=KErrNone) return -1;
 
// 设置记录的内容
commsView->WriteTextL(TPtrC(COMMDB_NAME), KDefaultIapName);
commsView->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
commsView->WriteUintL(TPtrC(IAP_SERVICE), GPRSId);
commsView->WriteUintL(TPtrC(IAP_NETWORK_WEIGHTING), 0);
commsView->WriteUintL(TPtrC(IAP_NETWORK), networkId);
commsView->WriteUintL(TPtrC(IAP_BEARER), 2);
commsView->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(MODEM_BEARER));
commsView->WriteUintL(TPtrC(IAP_LOCATION), mobileLocationId);
// 添加这条新的记录
TRAP(error,commsView->PutRecordChanges());
if (error!=KErrNone) return -1;
 
CleanupStack::PopAndDestroy(commsView);
 
// 在WAP_ACCESS_POINT表中添加记录
TUint32 wapId;
commsView = commsDb->OpenTableLC(TPtrC(WAP_ACCESS_POINT));
TRAP(error,commsView->InsertRecord(wapId));
if (error!=KErrNone) return -1;
commsView->WriteTextL(TPtrC(COMMDB_NAME), KDefaultIapName);
commsView->WriteTextL(TPtrC(WAP_CURRENT_BEARER), TPtrC(WAP_IP_BEARER));
 
// 使添加操作生效
TRAP(error,commsView->PutRecordChanges());
if (error!=KErrNone) return -1;
CleanupStack::PopAndDestroy(commsView);
 
// 在WAP_IP_BEARER表中添加记录
TUint32 wapIPId;
commsView = commsDb->OpenTableLC(TPtrC(WAP_IP_BEARER));
TRAP(error,commsView->InsertRecord(wapIPId));
if (error!=KErrNone)
{
return -1;
}
// 属性记录设置
commsView->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), wapId);
commsView->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), _L("0.0.0.0"));
commsView->WriteUintL(TPtrC(WAP_WSP_OPTION),EWapWspOptionConnectionOriented);
commsView->WriteBoolL(TPtrC(WAP_SECURITY), EFalse);
commsView->WriteUintL(TPtrC(WAP_IAP),iapId);
commsView->WriteUintL(TPtrC(WAP_PROXY_PORT), 0);
commsView->WriteTextL(TPtrC(WAP_PROXY_LOGIN_NAME), _L(""));
commsView->WriteTextL(TPtrC(WAP_PROXY_LOGIN_PASS), _L(""));
// 添加完成
TRAP(error,commsView->PutRecordChanges(EFalse, EFalse));
if (error!=KErrNone) return -1;
CleanupStack::PopAndDestroy(commsView);
 
// 在接入点菜单中添加新增的接入点项
CStoreableOverrideSettings* overrides = CStoreableOverrideSettings::NewL(CStoreableOverrideSettings::EParamListFull);
CleanupStack::PushL(overrides);
CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
pref.iRanking = 1;
pref.iDirection = ECommDbConnectionDirectionOutgoing;
pref.iDialogPref = ECommDbDialogPrefDoNotPrompt;
pref.iBearer.iBearerSet = ECommDbBearerGPRS;
pref.iBearer.iIapId=iapId;
TRAP(error,overrides->SetConnectionPreferenceOverride(pref));
if (error!=KErrNone) return -1;
CleanupStack::PopAndDestroy(overrides);
 
// 这里是添加cmwap的网关代理,著名的10.0.0.172
// 按照老外的原话是"proxy for chinese"
TUint32 proxiesId;
CCommsDbTableView* view7 = commsDb->OpenTableLC(TPtrC(PROXIES));
 
User::LeaveIfError( view7->InsertRecord(proxiesId));
 
view7->WriteUintL(TPtrC(PROXY_ISP), GPRSId);
view7->WriteTextL(TPtrC(PROXY_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
view7->WriteBoolL(TPtrC(PROXY_USE_PROXY_SERVER), ETrue);
view7->WriteLongTextL(TPtrC(PROXY_SERVER_NAME), _L("10.0.0.172"));
view7->WriteTextL(TPtrC(PROXY_PROTOCOL_NAME), _L("http"));
view7->WriteUintL(TPtrC(PROXY_PORT_NUMBER),80);
 
error = view7->PutRecordChanges(EFalse,EFalse);
 
if(error != KErrNone) User::Leave(error);
 
CleanupStack::PopAndDestroy(overrides);
CleanupStack::PopAndDestroy(commsDb);
return iapId;
 
}
This page was last modified on 19 October 2011, at 05:30.
100 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×