Service() { soap_set_mode(soap, SOAP_XML_INDENT); soap_register_plugin(soap, soap_wsa); soap_register_plugin(soap, soap_wsrm); soap->send_timeout = soap->recv_timeout = 10; // 10 sec soap_set_mode(callback.soap, SOAP_XML_INDENT); soap_register_plugin(callback.soap, soap_wsa); soap_register_plugin(callback.soap, soap_wsrm); callback.soap->send_timeout = callback.soap->recv_timeout = 10; // 10 sec result = 0.0; equation.str(""); equation << 0.0; }
void GetYwblcxCondtionThread::run() { qDebug()<<"准备提前业务办理状态下拉列表"; UtilFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); _ns1__GetDicContentByCondition req; char buffer0[255]; memset(buffer0,0,255*sizeof(char)); strcpy(buffer0, Singleton::GetInstance()->session_id.toUtf8().data()); req.sessionId = buffer0; char buffer1[255]; memset(buffer1,0,255*sizeof(char)); QString queryStr = "[Category]='业务办理状态' and [Enabled]=1 "; string condition = NetSecurity::encrypt(queryStr); strcpy(buffer1, condition.data()); req.condition = buffer1; _ns1__GetDicContentByConditionResponse res; if (soap.__ns7__GetDicContentByCondition(&req,&res) == SOAP_OK) { for (int i=0; i<res.GetDicContentByConditionResult->__sizeDIC_USCOREContent; ++i) { QString name = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Name); QString value = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Code); _ref->ui->cbx_state->addItem(name,value); } } else { qDebug()<<"服务器出错,无法提取业务办理状态下拉列表"; } }
CWebServiceApi::CWebServiceApi() { m_soap_endpoint = ""; soap_init(&clientSOAP); setlocale(LC_ALL,"chs"); soap_set_mode(&clientSOAP,SOAP_C_MBSTRING); }
CWebServiceApi::CWebServiceApi(std::string endpoint) :m_soap_endpoint(endpoint) { soap_init(&clientSOAP); setlocale(LC_ALL,"chs"); soap_set_mode(&clientSOAP,SOAP_C_MBSTRING); }
void ydxh_ScrollArea::on_tableWidget_cellPressed(int row, int column) { //判断点击的位置是否有号码 if (phones[row][column].No == "") { return; } //先判断是否被其他人锁定 BusinessFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); _ns1__LockNo req; char buffer1[255]; memset(buffer1,0,255*sizeof(char)); std::string No = NetSecurity::encrypt(phones[row][column].No); strcpy(buffer1, No.data()); req.No = buffer1; char buffer2[255]; memset(buffer2,0,255*sizeof(char)); string userId = NetSecurity::encrypt(Singleton::GetInstance()->getUser().Id); strcpy(buffer2, userId.data()); req.userId = buffer2; char buffer3[255]; memset(buffer3,0,255*sizeof(char)); strcpy(buffer3, Singleton::GetInstance()->session_id.toUtf8().data()); //qDebug()<<"session:"+QString::fromStdString(phoneNo); req.sessionId = buffer3; _ns1__LockNoResponse res; ui->tableWidget->setEnabled(false); this->setCursor(Qt::BusyCursor); if (soap.__ns13__LockNo(&req,&res) == SOAP_OK) { QString result = QString::fromUtf8(res.LockNoResult); if (result.contains("成功")) { QString no = phones[row][column].No; QString value = phones[row][column].value; QString noSection = phones[row][column].NoSection; BuyNoDialog buyNoDialog(this); buyNoDialog.init(no,value,noSection); ui->tableWidget->setEnabled(true); this->setCursor(Qt::ArrowCursor); buyNoDialog.exec(); } else { QMessageBox::warning(this,tr("提示"),result,QMessageBox::Ok); } } else { qDebug()<<"服务器出错!不能锁定号码"; } ui->tableWidget->setEnabled(true); this->setCursor(Qt::ArrowCursor); }
Client(const char *serverURI) { soap_set_mode(soap, SOAP_XML_INDENT); soap_register_plugin(soap, soap_wsa); soap_register_plugin(soap, soap_wsrm); soap_endpoint = serverURI; soap->send_timeout = soap->recv_timeout = 10; // 10 sec soap_set_mode(callback.soap, SOAP_XML_INDENT); soap_register_plugin(callback.soap, soap_wsa); soap_register_plugin(callback.soap, soap_wsrm); callback.soap->send_timeout = callback.soap->recv_timeout = 10; // 10 sec callback.soap->bind_flags = SO_REUSEADDR; // allow immediate bind if (!soap_valid_socket(callback.bind(NULL, clientPort, 100))) { callback.soap_stream_fault(std::cerr); exit(1); } #ifdef CB_THREAD THREAD_CREATE(&tid, (void*(*)(void*))callback_server, (void*)&callback); #endif }
void GetBusinessListThread::run() { UtilFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); _ns1__GetDicContentByCondition req; char buffer0[255]; memset(buffer0,0,255*sizeof(char)); strcpy(buffer0, Singleton::GetInstance()->session_id.toUtf8().data()); req.sessionId = buffer0; char buffer1[255]; memset(buffer1,0,255*sizeof(char)); QString queryStr = "[Category]='业务办理类型'"; if ((Config::GetInstance()->_client_type == "移动客户端")) { queryStr += " and [Code]='移动'"; } else { queryStr += " and [Code]<>'移动'"; } queryStr += " and [Enabled]=1 order by [附加字段2]"; std::string condition = NetSecurity::encrypt(queryStr); strcpy(buffer1, condition.data()); req.condition = buffer1; _ns1__GetDicContentByConditionResponse res; if (soap.__ns7__GetDicContentByCondition(&req,&res) == SOAP_OK) { _ref->ui->tableWidget->setRowCount(res.GetDicContentByConditionResult->__sizeDIC_USCOREContent); for (int i=0; i<res.GetDicContentByConditionResult->__sizeDIC_USCOREContent; ++i) { BusinessInfo business; business.name = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Name); business.winType = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->val1); _ref->list.append(business); QString content = business.name; QTableWidgetItem *item = new QTableWidgetItem (content); item->setTextAlignment(Qt::AlignCenter); _ref->ui->tableWidget->setItem(i, 0, item); } } else { qDebug()<<"服务器出错,无法提取业务办理列表"; } }
int main(int argc, char *argv[]) { long_t master; int32_t Signal; GMI_RESULT Result = GMI_SUCCESS; struct soap soap; sigset_t NewMask; sigset_t OldMask; struct sigaction Sa; //signal Sa.sa_handler = SignalHandler; sigfillset(&Sa.sa_mask); Sa.sa_flags = SA_NOMASK; sigemptyset(&NewMask); for (Signal = 1; Signal <= _NSIG; ++Signal) { if ( ( Signal == SIGIO ) || ( Signal == SIGPOLL ) || ( Signal == SIGINT ) || ( Signal == SIGQUIT ) || ( Signal == SIGHUP ) || ( Signal == SIGPIPE ) || ( Signal == SIGSEGV ) ) { sigaction(Signal, &Sa, NULL); } else { sigaddset(&NewMask, Signal); } } sigprocmask(SIG_BLOCK, &NewMask, &OldMask); //get debug opt const char_t *OptString = "ei"; struct option Opts[] = { {"error", no_argument, NULL, 'e'}, {"info", no_argument, NULL, 'i'}, {0, 0, 0, 0}, }; int C; boolean_t ErrLog = false; boolean_t InfoLog = false; while ((C = getopt_long(argc, argv, OptString, Opts, NULL)) != -1) { switch (C) { case 'e': ErrLog = true; break; case 'i': InfoLog = true; break; default: break; } printf("opts:%d:%d\n", ErrLog, InfoLog); } //log init Result = LogInitial(ErrLog, InfoLog); if (FAILED(Result)) { ONVIF_ERROR("LogInitial fail, Result = 0x%lx\n", Result); return Result; } //daemon register to daemon server Result = DaemonRegister(); if (FAILED(Result)) { ONVIF_ERROR("DaemonRegister fail, Result = 0x%lx\n", Result); DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, " DaemonRegister fail, Result = 0x%lx\n", Result); return Result; } //system initial Result = SysInitialize(GMI_ONVIF_AUTH_PORT); if (FAILED(Result)) { DaemonUnregister(); ONVIF_ERROR("SysInitialize fail, Result = 0x%lx\n", Result); DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, " SysInitialize fail, Result = 0x%lx\n", Result); return Result; } //get onvif port, rtsp port uint16_t SessionId = 0; uint32_t AuthValue = 0; SysPkgNetworkPort SysNetworkPort; Result = SysGetNetworkPort(SessionId, AuthValue, &SysNetworkPort); if (FAILED(Result)) { g_ONVIF_Port = DEFAULT_SERVER_PORT; g_RTSP_Port = DEFAULT_RTSP_PORT; ONVIF_ERROR("SysGetNetworkPort fail, Result = 0x%lx\n", Result); } else { g_ONVIF_Port = SysNetworkPort.s_ONVIF_Port; g_RTSP_Port = SysNetworkPort.s_RTSP_Port; } ONVIF_INFO("ONVIF_Port %d, RTSP_Port %d\n", g_ONVIF_Port, g_RTSP_Port); //ptz service __tptz__Initialize(); //soap server init soap_init1(&soap, SOAP_ENC_MTOM); soap.socket_flags = MSG_NOSIGNAL; soap.accept_flags |= SO_LINGER; soap.connect_flags |= SO_LINGER; soap.linger_time = 2; soap.bind_flags = SO_REUSEADDR; soap.send_timeout = 2; soap.recv_timeout = 2; soap.accept_timeout = 10; soap.connect_timeout = 10; soap.keep_alive = 5; soap_set_mode(&soap, SOAP_C_UTFSTRING); master = soap_bind(&soap, NULL, g_ONVIF_Port, 30); if (!soap_valid_socket(master)) { ONVIF_ERROR("soap_bind fail, Result = 0x%lx\n", Result); DEBUG_LOG(g_DefaultLogClient, e_DebugLogLevel_Exception, " soap_bind fail, Result = 0x%lx\n", Result); soap_print_fault(&soap, stderr); SysDeinitialize(); DaemonUnregister(); exit(1); } //main server start ServerLoop(&soap); ONVIF_INFO("soap_end start\n"); //soap release soap_end(&soap); soap_done(&soap); ONVIF_INFO("soap_end stop\n"); //ptz deinitialize __tptz__Deinitialize(); ONVIF_INFO("SysDeinitialize start\n"); SysDeinitialize(); ONVIF_INFO("SysDeinitialize end\n"); ONVIF_INFO("DaemonUnregister start\n"); //daemon unregister DaemonUnregister(); ONVIF_INFO("DaemonUnregister end\n"); return 0; }
void GetYwblcxListThread::run() { qDebug()<<"准备提取业务办理信息"; int total = 0; BusinessFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); _ns1__GettBusinessRecordHistoryByCondition req; req.top = 0; char buffer1[255]; memset(buffer1,0,255*sizeof(char)); QString queryStr = " [提交网点用户Id]='"+Singleton::GetInstance()->getUser().Id+"' "+currentCondition+"order by [办理时间] desc"; std::string condition = NetSecurity::encrypt(queryStr); qDebug()<<"queryStr="+QString::fromStdString(condition); strcpy(buffer1, condition.data()); req.condition = buffer1; char buffer2[255]; memset(buffer2,0,255*sizeof(char)); strcpy(buffer2, Singleton::GetInstance()->session_id.toUtf8().data()); qDebug()<<"session="+Singleton::GetInstance()->session_id; req.sessionId = buffer2; _ns1__GettBusinessRecordHistoryByConditionResponse res; if (soap.__ns13__GettBusinessRecordHistoryByCondition(&req,&res) == SOAP_OK) { _ref->ui->tableWidget->clearContents(); QString content = ""; total = res.GettBusinessRecordHistoryByConditionResult->__sizeBusinessItem; _ref->ui->tableWidget->setRowCount(total); for (int i=0; i<res.GettBusinessRecordHistoryByConditionResult->__sizeBusinessItem; ++i) { for (int j=0; j<10; ++j) { switch (j) { case 0: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->Id); break; case 1: content = Singleton::GetInstance()->getUser().loggingName; break; case 2: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->businessName); break; case 3: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->no); break; case 4: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->businessSpec); break; case 5: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->state); break; case 6: content = QString::number(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->returnMoney,'f',2); break; case 7: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->content); break; case 8: content = QString::fromUtf8(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->replay); break; case 9: if (-1 == res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->datetime) continue; char cTime[50]; memset(cTime,0,50); strftime(cTime,32,"%Y-%m-%d %H:%M:%S",localtime(&(res.GettBusinessRecordHistoryByConditionResult->BusinessItem[i]->datetime))); content = QString(cTime); break; } QTableWidgetItem *item = new QTableWidgetItem (content); _ref->ui->tableWidget->setItem(i, j, item); } } QString countStr = "共办理:【"+QString::number(total)+"】笔"; _ref->ui->txt_rpt_total->setText(countStr); } else { qDebug()<<"服务器出错,无法提取业务办理信息"; } }
void GetYdxhCondtionThread::run() { UtilFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); //处理我的号段 QString myNoSection = " "; BusinessFunctionWebServiceSoap soap1; soap_set_mode(soap1.soap, SOAP_C_UTFSTRING); _ns1__GetMyNoSection req1; char buffer0_[255]; memset(buffer0_,0,255*sizeof(char)); strcpy(buffer0_, Singleton::GetInstance()->session_id.toUtf8().data()); req1.sessionId = buffer0_; char buffer1_[255]; memset(buffer1_,0,255*sizeof(char)); std::string userId = NetSecurity::encrypt(Singleton::GetInstance()->getUser().Id); strcpy(buffer1_, userId.data()); req1.userId = buffer1_; _ns1__GetMyNoSectionResponse res1; if (soap1.__ns13__GetMyNoSection(&req1,&res1) == SOAP_OK) { if (res1.GetMyNoSectionResult->__sizestring > 0) { myNoSection += " and ("; for (int i=0; i<res1.GetMyNoSectionResult->__sizestring; ++i) { if (i == 0) myNoSection += " [号段] like '%"+QString::fromUtf8(res1.GetMyNoSectionResult->string[i])+"%'"; else myNoSection += " or [号段] like '%"+QString::fromUtf8(res1.GetMyNoSectionResult->string[i])+"%'"; } myNoSection += ")"; } else { myNoSection = " and [号段]=NULL"; } } else { qDebug()<<"服务器出错,无法提取号段下拉列表"; } qDebug()<<"我的号段:"+myNoSection; _ref->ui->cbx_hd->addItem("我的号段",myNoSection); _ns1__GetDicContentByCondition req; char buffer0[255]; memset(buffer0,0,255*sizeof(char)); strcpy(buffer0, Singleton::GetInstance()->session_id.toUtf8().data()); req.sessionId = buffer0; char buffer1[255]; memset(buffer1,0,255*sizeof(char)); QString queryStr = "[Category]='号段' and [Enabled]=1 "; std::string condition = NetSecurity::encrypt(queryStr); strcpy(buffer1, condition.data()); req.condition = buffer1; _ns1__GetDicContentByConditionResponse res; if (soap.__ns7__GetDicContentByCondition(&req,&res) == SOAP_OK) { for (int i=0; i<res.GetDicContentByConditionResult->__sizeDIC_USCOREContent; ++i) { QString name = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Name); QString value = " and [号段] like '%"+name+"%'"; _ref->ui->cbx_hd->addItem(name,value); } } else { qDebug()<<"服务器出错,无法提取号段下拉列表"; } memset(buffer1,0,255*sizeof(char)); queryStr = "[Category]='尾号特点' and [Enabled]=1 "; condition = NetSecurity::encrypt(queryStr); strcpy(buffer1, condition.data()); req.condition = buffer1; if (soap.__ns7__GetDicContentByCondition(&req,&res) == SOAP_OK) { for (int i=0; i<res.GetDicContentByConditionResult->__sizeDIC_USCOREContent; ++i) { QString name = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Name); QString value = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Code); _ref->ui->cbx_tail_format->addItem(name,value); } } else { qDebug()<<"服务器出错,无法提取尾号特点下拉列表"; } memset(buffer1,0,255*sizeof(char)); queryStr = "[Category]='入网政策' and [Enabled]=1 "; condition = NetSecurity::encrypt(queryStr); strcpy(buffer1, condition.data()); req.condition = buffer1; if (soap.__ns7__GetDicContentByCondition(&req,&res) == SOAP_OK) { for (int i=0; i<res.GetDicContentByConditionResult->__sizeDIC_USCOREContent; ++i) { QString name = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Name); QString value = QString::fromUtf8(res.GetDicContentByConditionResult->DIC_USCOREContent[i]->Code); _ref->ui->cbx_rwzc->addItem(name,value); } } else { qDebug()<<"服务器出错,无法提取入网政策下拉列表"; } }
void ydxh_ScrollArea::refresh(int pageSize, int pageIndex) { qDebug()<<"准备获取号码列表"; BusinessFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); _ns1__GetPhoneNoByCondition req; req.pageSize = pageSize; req.pageIndex = pageIndex; QString queryStr = "[分区] is not null and [选号费] is not null and [使用状态]='未使用' "; if (Config::GetInstance()->_client_type == "移动客户端") { queryStr += "and [运营商]='移动' "; } else { queryStr += "and [运营商]<>'移动' "; } queryStr += searchCondition; qDebug()<<"condition src:"+queryStr; std::string condition = NetSecurity::encrypt(queryStr); char buffer3[condition.length()]; memset(buffer3,0,condition.length()*sizeof(char)); strcpy(buffer3, condition.data()); qDebug()<<"condition:"+QString::fromStdString(condition); req.condition = buffer3; char buffer2[255]; memset(buffer2,0,255*sizeof(char)); strcpy(buffer2, Singleton::GetInstance()->session_id.toUtf8().data()); qDebug()<<"session:"+Singleton::GetInstance()->session_id; req.sessionId = buffer2; _ns1__GetPhoneNoByConditionResponse res; this->setCursor(Qt::BusyCursor); ui->btn_search->setEnabled(false); if (soap.__ns13__GetPhoneNoByCondition(&req,&res) == SOAP_OK) { int index = 0; int count = res.GetPhoneNoByConditionResult->listOfPhoneNo->__sizePhoneNoItem; totalItem = res.GetPhoneNoByConditionResult->total; totalPage = res.GetPhoneNoByConditionResult->totalPage; currentPage = res.GetPhoneNoByConditionResult->currentPageIndex; ui->tableWidget->clearContents(); resetPhoneNo(); int i_size = count / 3 + 1; for (int i=0; i<i_size; ++i) { for (int j=0; j<3; ++j) { if (index < count){ double money = res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->NoPrice; QString no = QString::fromUtf8(res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->No); QString value = QString::fromUtf8(res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->inNetPolicy); QString area = QString::fromUtf8(res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->area); QString NoSection = QString::fromUtf8(res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->NoSection); phones[i][j].No = no; phones[i][j].price = money; phones[i][j].value = value; phones[i][j].area = area; phones[i][j].NoSection = NoSection; QLabel *label = new QLabel(); label->setTextFormat(Qt::RichText); QString tmp = "<table width=\"280\" height=\"45px\" border=\"0\" style=\"margin-left:5px; margin-right:5px\">"; tmp += "<tr>"; tmp += " <td style=\"text-align:right\">"+NoSection+"</td>"; tmp += " <td rowspan=\"2\" style=\"font-size:36px; color:#00F; text-align:center\">"+no+"</td>"; tmp += " <td style=\"text-align:left\">"+value+"</td>"; tmp += "</tr>"; tmp += "<tr>"; tmp += " <td style=\"color:#F00; text-align:right\">"+QString::number(money)+"</td>"; tmp += " <td style=\"font-size:12px; text-align:left\">"+area+"</td>"; tmp += "</tr>"; tmp += "</table>"; label->setText(tmp); ui->tableWidget->setCellWidget(i,j,label); ++index; //qDebug()<<"设置号码:"+no; } } } } else { qDebug()<<"服务器出错!不能获取号码列表"; } this->setCursor(Qt::ArrowCursor); ui->btn_search->setEnabled(true); QString countPageStr = "共:【"+QString::number(totalPage)+"】页"; ui->txt_rpt_total->setText(countPageStr); QString countStr = "【"+QString::number(totalItem)+"】"; ui->txt_count->setText(countStr); ui->spinBox->setValue(currentPage); ui->spinBox->setMaximum(totalPage); qDebug()<<"获取号码列表处理完成"; }
void GetNoListThread::run() { qDebug()<<"进入获取号码列表的线程"; //TODO 提交服务器查询归属地 BusinessFunctionWebServiceSoap soap; soap_set_mode(soap.soap, SOAP_C_UTFSTRING); _ns1__GetPhoneNoByCondition req; req.pageSize = 60; req.pageIndex = 1; char buffer3[255]; memset(buffer3,0,255*sizeof(char)); QString queryStr = "[分区] is not null and [选号费] is not null and [使用状态]='未使用' "; if (Config::GetInstance()->_client_type == "移动客户端") { queryStr += "and [运营商]='移动' "; } else { queryStr += "and [运营商]<>'移动' "; } std::string condition = NetSecurity::encrypt(queryStr); strcpy(buffer3, condition.data()); qDebug()<<"clientType:"+QString::fromStdString(condition); req.condition = buffer3; char buffer2[255]; memset(buffer2,0,255*sizeof(char)); strcpy(buffer2, Singleton::GetInstance()->session_id.toUtf8().data()); //qDebug()<<"session:"+QString::fromStdString(phoneNo); req.sessionId = buffer2; _ns1__GetPhoneNoByConditionResponse res; if (soap.__ns13__GetPhoneNoByCondition(&req,&res) == SOAP_OK) { int index = 0; int count = res.GetPhoneNoByConditionResult->listOfPhoneNo->__sizePhoneNoItem; if (count > 0) { _ref->ui->tableWidget->clearContents(); int i_size = count / 3 + 1; for (int i=0; i<i_size; ++i) { for (int j=0; j<3; ++j) { double money = res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->NoPrice; QString no = res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->No; QString value = res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->inNetPolicy; QString area = res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->area; QString NoSection = res.GetPhoneNoByConditionResult->listOfPhoneNo->PhoneNoItem[index]->NoSection; _ref->phones[i][j].No = no; _ref->phones[i][j].price = money; _ref->phones[i][j].value = value; _ref->phones[i][j].area = area; _ref->phones[i][j].NoSection = NoSection; QLabel *label = new QLabel(); label->setTextFormat(Qt::RichText); QString tmp = "<table width=\"280\" height=\"45px\" border=\"0\" style=\"margin-left:5px; margin-right:5px\">"; tmp += "<tr>"; tmp += " <td style=\"text-align:right\">k4</td>"; tmp += " <td rowspan=\"2\" style=\"font-size:36px; color:#00F; text-align:center\">13987145"+no+"</td>"; tmp += " <td style=\"text-align:left\">"+value+"</td>"; tmp += "</tr>"; tmp += "<tr>"; tmp += " <td style=\"color:#F00; text-align:right\">"+QString::number(money)+"</td>"; tmp += " <td style=\"font-size:12px; text-align:left\">"+area+"</td>"; tmp += "</tr>"; tmp += "</table>"; label->setText(tmp); _ref->ui->tableWidget->setCellWidget(i,j,label); qDebug()<<"设置号码:"+no; ++count; } } } } else { qDebug()<<"服务器出错!不能获取号码列表"; } qDebug()<<"获取号码列表的线程,处理完成"; }
int main(int argc, char **argv) { struct soap *soap; int server = 0; int text = 0; int port = 0; FILE *fd; double result; char *user; int runs = 1; /* create context */ soap = soap_new(); /* register wsse plugin */ soap_register_plugin_arg(soap, soap_wsse, (void*)token_handler); /* options */ if (argc >= 2) { if (strchr(argv[1], 'c')) soap_set_omode(soap, SOAP_IO_CHUNK); else if (strchr(argv[1], 'y')) soap_set_omode(soap, SOAP_IO_STORE); if (strchr(argv[1], 'i')) soap_set_omode(soap, SOAP_XML_INDENT); if (strchr(argv[1], 'n')) soap_set_omode(soap, SOAP_XML_CANONICAL); if (strchr(argv[1], 'a')) aes = 1; if (strchr(argv[1], 'o')) oaep = 1; if (strchr(argv[1], 'd')) sym = 1; if (strchr(argv[1], 'e')) enc = 1; if (strchr(argv[1], 'f')) addenc = 1; /* if (strchr(argv[1], 'F')) addenca = 1; */ if (strchr(argv[1], 'h')) hmac = 1; if (strchr(argv[1], 'k')) nokey = 1; if (strchr(argv[1], 's')) server = 1; if (strchr(argv[1], 't')) text = 1; if (strchr(argv[1], 'g')) addsig = 1; if (strchr(argv[1], 'b')) nobody = 1; if (strchr(argv[1], 'x')) nohttp = 1; if (strchr(argv[1], 'z')) soap_set_mode(soap, SOAP_ENC_ZLIB); if (isdigit(argv[1][strlen(argv[1])-1])) { runs = argv[1][strlen(argv[1])-1] - '0'; soap_set_mode(soap, SOAP_IO_KEEPALIVE); } } /* soap->actor = "..."; */ /* set only when required */ user = getenv("USER"); if (!user) user = "******"; /* read RSA private key for signing */ if ((fd = fopen("server.pem", "r"))) { rsa_privk = PEM_read_PrivateKey(fd, NULL, NULL, (void*)"password"); fclose(fd); if (!rsa_privk) { fprintf(stderr, "Could not read private RSA key from server.pem\n"); exit(1); } } else fprintf(stderr, "Could not read server.pem\n"); /* read certificate (more efficient is to keep certificate in memory) to obtain public key for encryption and signature verification */ if ((fd = fopen("servercert.pem", "r"))) { cert = PEM_read_X509(fd, NULL, NULL, NULL); fclose(fd); if (!cert) { fprintf(stderr, "Could not read certificate from servercert.pem\n"); exit(1); } } else fprintf(stderr, "Could not read server.pem\n"); rsa_pubk = X509_get_pubkey(cert); if (!rsa_pubk) { fprintf(stderr, "Could not get public key from certificate\n"); exit(1); } /* port argument */ if (argc >= 3) port = atoi(argv[2]); /* need cacert to verify certificates with CA (cacert.pem for testing and cacerts.pem for production, which contains the trusted CA certificates) */ soap->cafile = "cacert.pem"; /* server or client/ */ if (server) { if (port) { /* stand-alone server serving messages over port */ if (!soap_valid_socket(soap_bind(soap, NULL, port, 100))) { soap_print_fault(soap, stderr); exit(1); } printf("Server started at port %d\n", port); while (soap_valid_socket(soap_accept(soap))) { if (hmac) soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else if (nokey) soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0); else soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0); if (sym) { if (aes) soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key)); else soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key)); } else if (enc) soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); if (soap_serve(soap)) { soap_wsse_delete_Security(soap); soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } soap_destroy(soap); soap_end(soap); } soap_print_fault(soap, stderr); exit(1); } else { /* CGI-style server serving messages over stdin/out */ if (hmac) soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else if (nokey) soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0); else soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0); if (sym) { if (aes) soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key)); else soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key)); } else if (enc) soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); if (soap_serve(soap)) { soap_wsse_delete_Security(soap); soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } soap_destroy(soap); soap_end(soap); } } else /* client */ { int run; char endpoint[80]; /* ns1:test data */ struct ns1__add a; struct ns1__sub b; a.a = 123; a.b = 456; b.a = 789; b.b = -99999; /* client sending messages to stdout or over port */ if (port) sprintf(endpoint, "http://localhost:%d", port); else if (nohttp) strcpy(endpoint, ""); else strcpy(endpoint, "http://"); for (run = 0; run < runs; run++) { /* message lifetime of 60 seconds */ soap_wsse_add_Timestamp(soap, "Time", 60); /* add user name with text or digest password */ if (text) soap_wsse_add_UsernameTokenText(soap, "User", user, "userPass"); else soap_wsse_add_UsernameTokenDigest(soap, "User", user, "userPass"); if (sym) { if (aes) { /* symmetric encryption with AES */ soap_wsse_add_EncryptedData_KeyInfo_KeyName(soap, "My AES Key"); if (soap_wsse_encrypt_body(soap, SOAP_MEC_ENC_AES256_CBC, aes_key, sizeof(aes_key))) soap_print_fault(soap, stderr); soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_AES256_CBC, aes_key, sizeof(aes_key)); } else { /* symmetric encryption with DES */ soap_wsse_add_EncryptedData_KeyInfo_KeyName(soap, "My DES Key"); if (soap_wsse_encrypt_body(soap, SOAP_MEC_ENC_DES_CBC, des_key, sizeof(des_key))) soap_print_fault(soap, stderr); soap_wsse_decrypt_auto(soap, SOAP_MEC_DEC_DES_CBC, des_key, sizeof(des_key)); } } else if (addenc || addenca) { /* RSA encryption of the <ns1:add> element */ const char *SubjectKeyId = NULL; /* set to non-NULL to use SubjectKeyIdentifier in Header rather than a full cert key */ /* MUST set wsu:Id of the elements to encrypt */ if (addenc) /* encrypt element <ns1:add> */ { soap_wsse_set_wsu_id(soap, "ns1:add"); if (soap_wsse_add_EncryptedKey_encrypt_only(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL, "ns1:add")) soap_print_fault(soap, stderr); } else /* encrypt element <a> */ { soap_wsse_set_wsu_id(soap, "a"); if (soap_wsse_add_EncryptedKey_encrypt_only(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL, "a")) soap_print_fault(soap, stderr); } soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); } else if (enc) { /* RSA encryption of the SOAP Body */ const char *SubjectKeyId = NULL; /* set to non-NULL to use SubjectKeyIdentifier in Header rather than a full cert key */ if (oaep) { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_AES256_CBC | SOAP_MEC_OAEP, "Cert", cert, SubjectKeyId, NULL, NULL)) soap_print_fault(soap, stderr); } else if (aes) { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_AES256_CBC, "Cert", cert, SubjectKeyId, NULL, NULL)) soap_print_fault(soap, stderr); } else { if (soap_wsse_add_EncryptedKey(soap, SOAP_MEC_ENV_ENC_DES_CBC, "Cert", cert, SubjectKeyId, NULL, NULL)) soap_print_fault(soap, stderr); } soap_wsse_decrypt_auto(soap, SOAP_MEC_ENV_DEC_DES_CBC, rsa_privk, 0); } if (hmac) { /* symmetric signature */ if (nobody) soap_wsse_sign(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else soap_wsse_sign_body(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); /* WS-SecureConversation contect token */ soap_wsse_add_SecurityContextToken(soap, "SCT", contextId); } else { if (nokey) soap_wsse_add_KeyInfo_KeyName(soap, "MyKey"); else { soap_wsse_add_BinarySecurityTokenX509(soap, "X509Token", cert); soap_wsse_add_KeyInfo_SecurityTokenReferenceX509(soap, "#X509Token"); } if (nobody || addsig) /* do not sign body */ soap_wsse_sign(soap, SOAP_SMD_SIGN_RSA_SHA1, rsa_privk, 0); else soap_wsse_sign_body(soap, SOAP_SMD_SIGN_RSA_SHA256, rsa_privk, 0); } /* enable automatic signature verification of server responses */ if (hmac) soap_wsse_verify_auto(soap, SOAP_SMD_HMAC_SHA1, hmac_key, sizeof(hmac_key)); else if (nokey) soap_wsse_verify_auto(soap, SOAP_SMD_VRFY_RSA_SHA1, rsa_pubk, 0); else soap_wsse_verify_auto(soap, SOAP_SMD_NONE, NULL, 0); /* sign the response message in unsigned body? If so, set wsu:Id */ if (addsig) { soap_wsse_set_wsu_id(soap, "ns1:add"); soap_wsse_sign_only(soap, "User ns1:add"); } /* invoke the server. You can choose add, sub, mul, or div operations * that show different security aspects (intentional message rejections) * for demonstration purposes (see server operations below) */ if (!soap_call_ns1__add(soap, endpoint, NULL, 1.0, 2.0, &result)) { if (!soap_wsse_verify_Timestamp(soap)) { const char *servername = soap_wsse_get_Username(soap); if (servername && !strcmp(servername, "server") && !soap_wsse_verify_Password(soap, "serverPass")) printf("Result = %g\n", result); else { fprintf(stderr, "Server authentication failed\n"); soap_print_fault(soap, stderr); } } else { fprintf(stderr, "Server response expired\n"); soap_print_fault(soap, stderr); } } else { soap_print_fault(soap, stderr); soap_print_fault_location(soap, stderr); } /* clean up security header */ soap_wsse_delete_Security(soap); /* disable soap_wsse_verify_auto */ soap_wsse_verify_done(soap); } /* run */ } /* clean up keys */ if (rsa_privk) EVP_PKEY_free(rsa_privk); if (rsa_pubk) EVP_PKEY_free(rsa_pubk); if (cert) X509_free(cert); /* clean up gSOAP engine */ soap_destroy(soap); soap_end(soap); soap_done(soap); free(soap); /* done */ return 0; }
//Main Funtion int main(int argc,char *argv[]) { int status=0; status=nInit(); sprintf(sLogfile,"%s",argv[0]); SOAP_SOCKET m,s; int i=0; struct soap Onlsoap; soap_init(&Onlsoap); Onlsoap.fget = http_get; Onlsoap.fpost = http_post; struct soap * soap_thr[MAX_THR]; pthread_t tid[MAX_THR]; sigset(SIGUSR1, signalHandle); sigset(SIGTERM, signalHandle); sigset(SIGSEGV, signalHandle); // 设置UTF-8编码方式 //soap_set_mode(&Onlsoap, SOAP_C_UTFSTRING); soap_set_mode(&Onlsoap, SOAP_C_MBSTRING); soap_set_namespaces(&Onlsoap, namespaces); // ---------- m = soap_bind(&Onlsoap,NULL,lPort,BACKLOG); //循环直至服务套接字合法 while (!soap_valid_socket(m)) { dzlog_error("Bind port error!"); m = soap_bind(&Onlsoap,NULL,lPort,BACKLOG); sleep(2); } //锁和条件变量初始化 pthread_mutex_init(&queue_cs,NULL); pthread_cond_init(&queue_cv,NULL); //生成服务线程 for(i = 0; i <MAX_THR; i++) { soap_thr[i] = soap_copy(&Onlsoap); dzlog_info("Starting thread %d ",i); pthread_create(&tid[i],NULL,(void*(*)(void*))process_queue,(void*)soap_thr[i]); } for(;;) { s=soap_accept(&Onlsoap); if(!soap_valid_socket(s)) { if (Onlsoap.errnum) { soap_print_fault(&Onlsoap,stderr); continue; } else { dzlog_error("Server timed out."); break; } } dzlog_info("Main Process[%d] accepted connection from IP=%d.%d.%d.%d", getpid(), (Onlsoap.ip >> 24)&0xFF, (Onlsoap.ip >> 16)&0xFF, (Onlsoap.ip >> 8)&0xFF, Onlsoap.ip&0xFF); while(enqueue(s) == SOAP_EOM) sleep(1); } //服务结束后的清理工作 for(i = 0; i < MAX_THR; i++) { while (enqueue(SOAP_INVALID_SOCKET) == SOAP_EOM) { sleep(1); } } for(i=0; i< MAX_THR; i++) { pthread_join(tid[i],NULL); dzlog_debug("terminated[%d] ",i); soap_done(soap_thr[i]); free(soap_thr[i]); } pthread_mutex_destroy(&queue_cs); pthread_cond_destroy(&queue_cv); soap_done(&Onlsoap); DbPoolFree(&conn_pool); zlog_fini(); return 0; }
int main(int argc, const char * argv[]) { struct soap soap; // sqlite3 设置为工作在 Serialized 模式下,因为“心跳线程”会周期操作 token table // 启动 webservice soap_init(&soap); soap_set_mode(&soap, SOAP_C_UTFSTRING); // 如果没有这个,无法正确显示 utf-8 编码的汉字 if (!soap_valid_socket(soap_bind(&soap, 0, 8899, 100))) { fprintf(stderr, "ERR: soap_bind 8899 err\n"); exit(-1); } fprintf(stdout, "start %d\n", 8899); // 启动心跳线程 // FIXME: 在每次 webservice 的请求时,检查 token table 是不是更好些呢?. // 已经修改为,在每次查询时,首先删除超时对象,这样不需要启动独立的工作线程;. #if 0 #ifdef WIN32 CloseHandle(CreateThread(0, 0, heartBeatCheck_run, 0, 0, 0)); #else pthread_t th; pthread_create(&th, 0, heartBeatCheck_run, 0); #endif // os #endif // 0; // 开始处理所有 webservice 请求... while (1) { int n = soap_accept(&soap); if (n < 0) { fprintf(stderr, "ERR: soap_accept err\n"); soap_print_fault(&soap, stderr); if (soap.errnum) { soap_print_fault(&soap, stderr); exit(1); } exit(-1); } #ifdef MULTITHREAD_SERVER { struct soap *ts = soap_copy(&soap); if (ts) { #ifdef WIN32 HANDLE th; CloseHandle(CreateThread(0, 0, _working_proc, ts, 0, 0)); #else pthread_t th; pthread_create(&th, 0, _working_proc, ts); #endif // } } #else soap_serve(&soap); soap_destroy(&soap); soap_end(&soap); #endif // multi thread server } soap_done(&soap); return 0; }