lnk commit front code

This commit is contained in:
lnk
2025-01-16 16:17:01 +08:00
commit 1776a2bf0d
587 changed files with 257079 additions and 0 deletions

2
cfg_parse/CVS/Entries Normal file
View File

@@ -0,0 +1,2 @@
/cfg_parser.cpp/1.20/Tue Jan 22 07:41:32 2019//
D

View File

@@ -0,0 +1 @@
/cfg_parser.cpp////*////

View File

@@ -0,0 +1 @@
/cfg_parser.cpp////*////

View File

@@ -0,0 +1,2 @@
/cfg_parser.cpp/1.19/Fri Jan 18 02:42:35 2019//
D

1
cfg_parse/CVS/Repository Normal file
View File

@@ -0,0 +1 @@
jspqfe/src/pt61850netd_pqfe/source/cfg_parse

1
cfg_parse/CVS/Root Normal file
View File

@@ -0,0 +1 @@
:ext:lizhongming@10.0.0.2:/JoyProject

0
cfg_parse/CVS/Template Normal file
View File

View File

@@ -0,0 +1,866 @@
/*
* Description: Simple Producer demo
*/
#include <fstream> // 用于 std::ifstream
#include <sstream> // 用于 std::stringstream
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include "../mms/db_interface.h"
#include "../include/rocketmq/CProducer.h"
#include "../include/rocketmq/CMessage.h"
#include "../include/rocketmq/CSendResult.h"
#include "../include/rocketmq/SimpleProducer.h"
//测试300数据用lnk20241202
#include <ctime>
#include <QThread>
//测试300数据用
//lnk20241209添加队列选择
#include "../include/rocketmq/MQSelector.h"
#include "../include/rocketmq/MQMessageQueue.h"
//#include <atomic>
#include <vector>
#include <stdexcept>
//lnk20241209添加队列选择
#include <cstring>
// 引入提供的消费者接口头文件
#include "../include/rocketmq/CPushConsumer.h"
#include "../include/rocketmq/CCommon.h"
#include "../include/rocketmq/CMessageExt.h"
#include <map>
#include <pthread.h> // 用于互斥锁(在 C++98 中没有 std::mutex
#include <utility> // for std::pair
using namespace std;
extern std::string G_ROCKETMQ_PRODUCER;//rocketmq producer
extern std::string G_ROCKETMQ_IPPORT;//rocketmq ip+port
extern std::string G_ROCKETMQ_TOPIC;//topie
extern std::string G_ROCKETMQ_TAG;//tag
extern std::string G_ROCKETMQ_KEY;//key
#ifdef __cplusplus
extern "C" {
#endif
extern std::string G_MQCONSUMER_TOPIC_SET; // C++ 中的全局变量声明
#ifdef __cplusplus
}
#endif
extern int QUEUENUM;
extern int g_front_seg_index;
extern char subdir[128];
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//消费者连接秘钥
extern std::string G_MQCONSUMER_ACCESSKEY;
extern std::string G_MQCONSUMER_SECRETKEY;
extern std::string G_MQCONSUMER_CHANNEL;
// 前向声明 RocketMQConsumer 类
class RocketMQConsumer;
// 全局映射CPushConsumer* -> RocketMQConsumer*
std::map<CPushConsumer*, RocketMQConsumer*> g_consumerMap;//
pthread_mutex_t g_consumerMapMutex = PTHREAD_MUTEX_INITIALIZER;
class RocketMQConsumer {
public:
// 构造函数:初始化消费者并启动
RocketMQConsumer(const std::string& consumerName, const std::string& nameServer, const std::string& groupId);
// 禁用拷贝和赋值
RocketMQConsumer(const RocketMQConsumer&) {}
RocketMQConsumer& operator=(const RocketMQConsumer&) { return *this; }
// 订阅主题和标签,并注册回调
void subscribe(const std::string& topic, const std::string& tag, MessageCallBack callback);
// 启动消费者
void start();
//修改消费模式
void setConsumerMessageModel(const std::string& topic);
// 析构函数:关闭并销毁消费者
~RocketMQConsumer();
private:
CPushConsumer* consumer_; // C 接口消费者指针
//MessageCallBack messageCallback_; // 函数指针用于回调
std::map<std::pair<std::string, std::string>, MessageCallBack> callbacks_; // 订阅到回调的映射
// 静态消息处理回调
static int messageHandler(CPushConsumer* consumer, CMessageExt* msg);
// 实例消息处理函数
int handleMessage(CMessageExt* msg);
};
// 构造函数实现
RocketMQConsumer::RocketMQConsumer(const std::string& consumerName, const std::string& nameServer, const std::string& groupId)
: consumer_(NULL)//, messageCallback_(NULL)
{
// 创建消费者
consumer_ = CreatePushConsumer(consumerName.c_str());
if (consumer_ == NULL) {
std::cout << "error CreatePushConsumer"<< std::endl;
throw std::runtime_error("Failed to create push consumer.");
}
SetPushConsumerSessionCredentials(consumer_,G_MQCONSUMER_ACCESSKEY.c_str(),G_MQCONSUMER_SECRETKEY.c_str(),G_MQCONSUMER_CHANNEL.c_str());
// 设置 NameServer 地址
if (SetPushConsumerNameServerAddress(consumer_, nameServer.c_str()) != 0) {
DestroyPushConsumer(consumer_);
std::cout << "error setting nameServer"<< std::endl;
throw std::runtime_error("Failed to set NameServer address.");
}
// 设置消费者组ID
if (SetPushConsumerGroupID(consumer_, groupId.c_str()) != 0) {
DestroyPushConsumer(consumer_);
std::cout << "error setting groupId"<< std::endl;
throw std::runtime_error("Failed to set Consumer Group ID.");
}
// 设置消费模式为广播模式
if (SetPushConsumerMessageModel(consumer_, BROADCASTING) != 0) {
DestroyPushConsumer(consumer_);
std::cout << "error setting messagemodel"<< std::endl;
}
//调试用
std::string consumerlog = "./mqconsumer/" + consumerName +".log";
if ( (SetPushConsumerLogPath(consumer_,consumerlog.c_str()) || SetPushConsumerLogFileNumAndSize(consumer_,10,100) || SetPushConsumerLogLevel(consumer_,E_LOG_LEVEL_DEBUG) ) != 0) {//记录消费日志
DestroyPushConsumer(consumer_);
std::cout << "error setting logpath"<< std::endl;
}
std::cout << "logpath:" << consumerlog << std::endl;
// 注册消息回调
if (RegisterMessageCallback(consumer_, RocketMQConsumer::messageHandler) != 0) {
DestroyPushConsumer(consumer_);
std::cout << "error setting Callback"<< std::endl;
throw std::runtime_error("Failed to register message callback.");
}
// 将消费者实例添加到全局映射
pthread_mutex_lock(&g_consumerMapMutex);
g_consumerMap[consumer_] = this;
pthread_mutex_unlock(&g_consumerMapMutex);
std::cout << "RocketMQ Consumer initialized and started." << std::endl;
}
// 启动消费者
void RocketMQConsumer::start()
{
if (StartPushConsumer(consumer_) != 0) {
pthread_mutex_lock(&g_consumerMapMutex);
g_consumerMap.erase(consumer_);
pthread_mutex_unlock(&g_consumerMapMutex);
DestroyPushConsumer(consumer_);
throw std::runtime_error("Failed to start push consumer.");
}
else{
std::cout << "RocketMQ Consumer started." << std::endl;
}
}
void RocketMQConsumer::subscribe(const std::string& topic, const std::string& tag, MessageCallBack callback)
{
if (Subscribe(consumer_, topic.c_str(), tag.c_str()) != 0) {
throw std::runtime_error("Failed to subscribe to topic/tag.");
}
std::cout << "Subscribed to topic: " << topic << ", tag: " << tag << std::endl;
// 使用 std::pair 作为键
std::pair<std::string, std::string> key(topic, tag);
callbacks_[key] = callback;
}
// 静态消息处理回调实现
int RocketMQConsumer::messageHandler(CPushConsumer* consumer, CMessageExt* msg)
{
RocketMQConsumer* instance = NULL;
//调试用
std::cout << "messagehandler" << std::endl;
// 查找对应的消费者实例
pthread_mutex_lock(&g_consumerMapMutex);
std::map<CPushConsumer*, RocketMQConsumer*>::iterator it = g_consumerMap.find(consumer);
if (it != g_consumerMap.end()) {
instance = it->second;
}
pthread_mutex_unlock(&g_consumerMapMutex);
if (instance) {
return instance->handleMessage(msg);
} else {
std::cerr << "Consumer instance not found for callback." << std::endl;
return E_RECONSUME_LATER; // 默认返回重试状态
}
}
int RocketMQConsumer::handleMessage(CMessageExt* msg)
{
// 检查 msg 和 consumer_ 是否为 NULL
if (!msg || !consumer_) {
std::cerr << "Received null message or consumer." << std::endl;
return E_RECONSUME_LATER;
}
// 获取消息的主题和标签
std::string topic = GetMessageTopic(msg); // 假设存在此函数
std::string tag = GetMessageTags(msg); // 假设存在此函数
// 打印调试信息
std::cout << "Handling message for topic: " << topic << ", tag: " << tag << std::endl;
// 使用 std::pair 作为键
std::pair<std::string, std::string> key(topic, tag);
// 查找对应的回调函数
std::map<std::pair<std::string, std::string>, MessageCallBack>::iterator it = callbacks_.find(key);
if (it != callbacks_.end()) {
// 调用对应的回调函数
//调试
std::cout << "callback Handling message " <<std::endl;
return it->second(consumer_, msg);
} else {
//调试
std::cout << "there is no callback " <<std::endl;
// 如果没有找到对应的回调,执行默认处理
const char* body = GetMessageBody(msg);
const char* msgKey = GetMessageKeys(msg);
if (body) {
std::cout << "Received message body: " << body << std::endl;
} else {
std::cout << "Received message with empty body." << std::endl;
}
if (msgKey) {
std::cout << "Message Key: " << msgKey << std::endl;
} else {
std::cout << "Message Key: N/A" << std::endl;
}
return E_CONSUME_SUCCESS;
}
}
// 析构函数实现
RocketMQConsumer::~RocketMQConsumer()
{
if (consumer_) {
// 关闭消费者
ShutdownPushConsumer(consumer_);
// 从全局映射中移除
pthread_mutex_lock(&g_consumerMapMutex);
g_consumerMap.erase(consumer_);
pthread_mutex_unlock(&g_consumerMapMutex);
// 销毁消费者
DestroyPushConsumer(consumer_);
consumer_ = NULL;
std::cout << "RocketMQ Consumer shutdown and destroyed." << std::endl;
}
}
// 在 RocketMQConsumer 类中新增函数用来设置消费模式
void RocketMQConsumer::setConsumerMessageModel(const std::string& topic)
{
if (topic == G_MQCONSUMER_TOPIC_SET) {
// 设置为普通消费模式
if (SetPushConsumerMessageModel(consumer_, CLUSTERING) != 0) {
std::cout << "Error setting message model to CLUSTERING for topic: " << topic << std::endl;
} else {
std::cout << "Set consumer to CLUSTERING for topic: " << topic << std::endl;
}
} else {
// 默认设置为广播消费模式
if (SetPushConsumerMessageModel(consumer_, BROADCASTING) != 0) {
std::cout << "Error setting message model to BROADCASTING for topic: " << topic << std::endl;
} else {
std::cout << "Set consumer to BROADCASTING for topic: " << topic << std::endl;
}
}
}
// 全局消费者实例
RocketMQConsumer* g_consumer = NULL;
// 初始化消费者函数
void InitializeConsumer(
const std::string& consumerName,
const std::string& nameServer,
const std::vector<Subscription>& subscriptions) // 接收多个订阅
{
if (g_consumer == NULL) {
std::cout << "create new consumer!" << std::endl;
try {
g_consumer = new RocketMQConsumer(consumerName, nameServer,consumerName);//用消费名作为消费组不同进程不同的消费者同时消费topic的同一条消息
for (size_t i = 0; i < subscriptions.size(); ++i) {
g_consumer->setConsumerMessageModel(subscriptions[i].topic);//初始化时根据topic设置消费模式
g_consumer->subscribe(subscriptions[i].topic, subscriptions[i].tag, subscriptions[i].callback);
}
g_consumer->start();
}
catch (const std::exception& e) {
std::cerr << "Failed to initialize consumer: " << e.what() << std::endl;
throw; // 重新抛出异常
}
}
}
// 关闭并销毁消费者函数
void ShutdownAndDestroyConsumer()
{
if (g_consumer != NULL) {
delete g_consumer;
g_consumer = NULL;
}
}
// 消费消息的接口函数
void rocketmq_consumer_receive(
const std::string& consumerName,
const std::string& nameServer,
const std::vector<Subscription>& subscriptions) // 接收多个订阅
{
if (g_consumer == NULL) {
try {
//InitializeConsumer(consumerName, nameServer, topic, tag, callback);//初始化后mq库内部来完成消息的获取
InitializeConsumer(consumerName, nameServer, subscriptions); // 初始化后MQ库内部开始获取消息
}
catch (...) {
std::cerr << "Cannot consume message because consumer initialization failed." << std::endl;
return;
}
}
// 消费逻辑已通过回调处理,无需额外操作
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//封装生产者类
#if 1
// 全局或静态变量,用于维护当前队列索引
static int currentQueueId = 0;
// 队列选择器回调函数:轮询选择队列 ID
int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
if (queueNum == 0) {
throw std::runtime_error("No available queues");
}
int queueId = currentQueueId % queueNum;
currentQueueId++;
if (currentQueueId >= 1024 - queueNum) {
currentQueueId = 0;
}
return queueId;
}
// 封装生产者的类
class RocketMQProducer {
public:
RocketMQProducer(const std::string& producerName, const std::string& nameServer)
: producer_(NULL)
{
// 创建生产者
producer_ = CreateProducer(producerName.c_str());
if (producer_ == NULL) {
throw std::runtime_error("Failed to create producer.");
}
// 设置 nameserver 地址
SetProducerNameServerAddress(producer_, nameServer.c_str());
// 启动生产者
StartProducer(producer_);
std::cout << "rocketmq_Producer initialized and started." << std::endl;
}
// 禁用拷贝和赋值
RocketMQProducer(const RocketMQProducer&) = delete;
RocketMQProducer& operator=(const RocketMQProducer&) = delete;
// 发送消息
void sendMessage(const char* strbody, const char* topic, const std::string& tags, const std::string& keys) {
CSendResult result;
CMessage* msg = NULL;
try {
// 创建消息并设置属性
msg = CreateMessage(topic);
if (msg == NULL) {
throw std::runtime_error("Failed to create message.");
}
SetMessageTags(msg, tags.c_str());
SetMessageKeys(msg, keys.c_str());
SetMessageBody(msg, strbody);
// 假设队列数量和 Broker 名称是固定的
int queueNum = QUEUENUM; // 配置的队列数量例如5
// 发送消息
int sendResult = SendMessageOnewayOrderly(
producer_,
msg,
RoundRobinSelector, // 队列选择器回调函数
&queueNum // 传递给选择器的额外参数(队列数量)
);
if (sendResult == 0) { // 假设返回 0 表示成功
std::cout << "Message sent successfully." << std::endl;
} else {
std::cout << "Failed to send message." << std::endl;
}
// 销毁消息
DestroyMessage(msg);
msg = NULL; // 防止重复销毁
}
catch (const std::runtime_error& e) {
std::cerr << "Runtime error during message sending: " << e.what() << std::endl;
// 如果消息已经创建,确保销毁它
if (msg != NULL) {
DestroyMessage(msg);
}
// 可以在这里添加更多的错误处理逻辑,比如重试、记录日志等
}
catch (const std::exception& e) {
std::cerr << "Exception during message sending: " << e.what() << std::endl;
if (msg != NULL) {
DestroyMessage(msg);
}
}
catch (...) {
std::cerr << "Unknown error during message sending." << std::endl;
if (msg != NULL) {
DestroyMessage(msg);
}
}
}
// 析构函数中关闭并销毁生产者
~RocketMQProducer() {
if (producer_) {
ShutdownProducer(producer_);
DestroyProducer(producer_);
std::cout << "rocketmq_Producer shutdown and destroyed." << std::endl;
}
}
private:
CProducer* producer_;
};
// 全局生产者实例
RocketMQProducer* g_producer = NULL;
// 初始化生产者(在程序启动时调用一次)
void InitializeProducer()
{
if (g_producer == NULL) {
try {
g_producer = new RocketMQProducer(G_ROCKETMQ_PRODUCER, G_ROCKETMQ_IPPORT);
}
catch (const std::exception& e) {
std::cerr << "Failed to initialize producer: " << e.what() << std::endl;
// 根据需求决定是否终止程序或采取其他措施
throw; // 重新抛出异常
}
}
}
// 关闭并销毁生产者(在程序结束时调用一次)
void ShutdownAndDestroyProducer()
{
if (g_producer != NULL) {
delete g_producer;
g_producer = NULL;
}
}
// 发送消息的接口函数
void rocketmq_producer_send(const char* strbody, const char* topic)
{
if (g_producer == NULL) {
try {
InitializeProducer();
}
catch (...) {
std::cerr << "Cannot send message because producer initialization failed." << std::endl;
return;
}
}
// 假设 tags 和 keys 是固定的,可以根据需要修改
std::string tags = G_ROCKETMQ_TAG;
std::string keys = G_ROCKETMQ_KEY;
try {
g_producer->sendMessage(strbody, topic, tags, keys);
}
catch (const std::exception& e) {
std::cerr << "Failed to send message: " << e.what() << std::endl;
// 处理发送失败的情况,例如记录日志或重试
}
}
#endif
//lnk20241209队列轮询
#if 0
// 全局或静态变量,用于维护当前队列索引
static int currentQueueId = 0;
// 队列选择器回调函数:轮询选择队列 ID
int RoundRobinSelector(int queueNum, CMessage* msg, void* arg) {
if (queueNum == 0) {
throw std::runtime_error("No available queues");
}
// 选择当前队列 ID并更新索引
int queueId = currentQueueId % queueNum;
currentQueueId++;
// 防止溢出,重置索引
if (currentQueueId >= 1024 - queueNum) {
currentQueueId = 0;
}
return queueId;
}
void StartSendMessage_queue(CProducer* producer, const char* strbody, const char* topic)
{
CSendResult result;
// 创建消息并设置一些属性
CMessage* msg = CreateMessage(topic);
SetMessageTags(msg, G_ROCKETMQ_TAG.c_str());
SetMessageKeys(msg, G_ROCKETMQ_KEY.c_str());
SetMessageBody(msg, strbody);
// 动态获取队列数量和 Broker 名称
int queueNum = QUEUENUM; // 假设这个是配置的队列数量比如5
// 使用 SendMessageOnewayOrderly 发送消息,传递回调函数
int sendResult = SendMessageOnewayOrderly(
producer,
msg,
RoundRobinSelector, // 传递符合 QueueSelectorCallback 签名的函数
&queueNum // 传递给选择器的额外参数(队列数量)
);
if (sendResult == 0) { // 假设返回 0 表示成功
std::cout << "Message sent successfully: " << std::endl;
} else {
std::cout << "Failed to send message: " << std::endl;
}
// 销毁消息
DestroyMessage(msg);
}
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// producer_send0测试用
void StartSendMessage(CProducer* producer)
{
CSendResult result;
// create message and set some values for it
CMessage* msg = CreateMessage(G_ROCKETMQ_TOPIC.c_str());
SetMessageTags(msg, G_ROCKETMQ_TAG.c_str());
SetMessageKeys(msg, G_ROCKETMQ_KEY.c_str());
for (int i = 0; i < 10; i++)
{
// construct different body
string strMessageBody = "this is body number";
SetMessageBody(msg, strMessageBody.c_str());
// send message
SendMessageSync(producer, msg, &result);
cout << "send message[" << i << "], result status:" << result.sendStatus << ", msgBody:" << strMessageBody << endl;
usleep(1000);
}
// destroy message
DestroyMessage(msg);
}
//producer_send 测试用
void StartSendMessage(CProducer* producer,const char* strbody)
{
CSendResult result;
// create message and set some values for it
CMessage* msg = CreateMessage(G_ROCKETMQ_TOPIC.c_str());
SetMessageTags(msg, G_ROCKETMQ_TAG.c_str());
SetMessageKeys(msg, G_ROCKETMQ_KEY.c_str());
SetMessageBody(msg, strbody);
// send message
SendMessageSync(producer, msg, &result);
cout << "result status:" << result.sendStatus << ", msgBody:" << strbody << endl;
// destroy message
DestroyMessage(msg);
}
//测试用 固定消息体
void producer_send0()
{
cout << "Producer Initializing....." << endl;
// create producer and set some values for it
CProducer* producer = CreateProducer(G_ROCKETMQ_PRODUCER.c_str());
SetProducerNameServerAddress(producer, G_ROCKETMQ_IPPORT.c_str());
// start producer
StartProducer(producer);
cout << "Producer start....." << endl;
// send message
StartSendMessage(producer);
// shutdown producer
ShutdownProducer(producer);
// destroy producer
DestroyProducer(producer);
cout << "Producer Shutdown!" << endl;
}
//测试用 可控制消息体
void producer_send(const char* strbody)
{
cout << "Producer Initializing....." << endl;
// create producer and set some values for it
CProducer* producer = CreateProducer(G_ROCKETMQ_PRODUCER.c_str());
SetProducerNameServerAddress(producer, G_ROCKETMQ_IPPORT.c_str());
// start producer
StartProducer(producer);
cout << "Producer start....." << endl;
// send message
StartSendMessage(producer, strbody);
// shutdown producer
ShutdownProducer(producer);
// destroy producer
DestroyProducer(producer);
cout << "Producer Shutdown!" << endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
#if 0
void rocketmq_StartSendMessage(CProducer* producer,const char* strbody,const char* topic)
{
CSendResult result;
// create message and set some values for it
CMessage* msg = CreateMessage(topic);
//多前置区分消息tag一个进程
SetMessageTags(msg, G_ROCKETMQ_TAG.c_str());
SetMessageKeys(msg, G_ROCKETMQ_KEY.c_str());
SetMessageBody(msg, strbody);
// send message
SendMessageSync(producer, msg, &result);
//cout << "rocketmq_result status:" << result.sendStatus << ", msgBody:" << strbody << endl;
// destroy message
DestroyMessage(msg);
}
void rocketmq_producer_send(const char* strbody,const char* topic)
{
cout << "rocketmq_Producer Initializing....." << endl;
// create producer and set some values for it
CProducer* producer = CreateProducer(G_ROCKETMQ_PRODUCER.c_str());
if (producer == NULL) {
std::cerr << "Failed to create producer." << std::endl;
return;
}
// nameserver
SetProducerNameServerAddress(producer, G_ROCKETMQ_IPPORT.c_str());
// start producer
StartProducer(producer);
cout << "rocketmq_Producer start....." << endl;
// send message
//rocketmq_StartSendMessage(producer,strbody,topic);
//根据队列发消息
StartSendMessage_queue(producer,strbody,topic);
// shutdown producer
ShutdownProducer(producer);
// destroy producer
DestroyProducer(producer);
cout << "rocketmq_Producer Shutdown!" << endl;
}
#endif
extern "C" {
extern std::string G_MQCONSUMER_TOPIC_RT;
void rocketmq_test_rt()
{
Ckafka_data_t data;
data.monitor_id = 123123;
data.strTopic = QString::fromStdString(G_MQCONSUMER_TOPIC_RT);
std::ifstream file("rt.txt"); // 文件中存储长字符串
std::stringstream buffer;
buffer << file.rdbuf(); // 读取整个文件内容
data.strText = QString::fromStdString(buffer.str());
data.mp_id = 123123;
my_rocketmq_send(data);
}
extern std::string G_MQCONSUMER_TOPIC_UD;
void rocketmq_test_ud()//用来测试台账更新
{
Ckafka_data_t data;
data.monitor_id = 123123;
data.strTopic = QString::fromStdString(G_MQCONSUMER_TOPIC_UD);
std::ifstream file("ud.txt"); // 文件中存储长字符串
std::stringstream buffer;
buffer << file.rdbuf(); // 读取整个文件内容
data.strText = QString::fromStdString(buffer.str());
data.mp_id = 123123;
my_rocketmq_send(data);
}
void rocketmq_test_set()//用来测试进程控制脚本
{
Ckafka_data_t data;
data.monitor_id = 123123;
data.strTopic = QString::fromStdString(G_MQCONSUMER_TOPIC_SET);
std::ifstream file("set.txt"); // 文件中存储长字符串
std::stringstream buffer;
buffer << file.rdbuf(); // 读取整个文件内容
data.strText = QString::fromStdString(buffer.str());
data.mp_id = 123123;
my_rocketmq_send(data);
}
extern std::string G_MQCONSUMER_TOPIC_RC;
void rocketmq_test_rc()
{
Ckafka_data_t data;
data.monitor_id = 123123;
data.strTopic = QString::fromStdString(G_MQCONSUMER_TOPIC_RC);
std::ifstream file("rc.txt"); // 文件中存储长字符串
std::stringstream buffer;
buffer << file.rdbuf(); // 读取整个文件内容
data.strText = QString::fromStdString(buffer.str());
data.mp_id = 123123;
my_rocketmq_send(data);
}
}
std::string to_string(long long value) {
std::stringstream ss;
ss << value;
return ss.str();
}
void rocketmq_test_300(int mpnum,int front_index) {
Ckafka_data_t data;
data.strTopic = QString::fromStdString(G_ROCKETMQ_TOPIC);
data.mp_id = "0";
// 读取文件内容
std::ifstream file("long_string.txt"); // 文件中存储长字符串
std::stringstream buffer;
buffer << file.rdbuf();
std::string file_contents = buffer.str(); // 获取文件内容
std::string base_strText = file_contents;
// 获取当前时间作为开始时间
std::time_t t = std::time(NULL);//获取当前的系统时间(自 1970 年 1 月 1 日以来的秒数,通常称为 UNIX 时间戳)
std::tm* time_info = std::localtime(&t);//将 std::time_t表示当前的 UNIX 时间戳转换为本地时间std::tm 结构)
time_info->tm_sec = 0; // 清零秒位
//time_info->tm_msec = 0; // 清零毫秒位(如果需要更精确,使用高精度时间)
// 获取当前的时间戳(秒)
std::time_t base_time_t = std::mktime(time_info);//将 std::tm 结构(本地时间)转换回 std::time_t时间戳
// 计算每条消息的时间戳,精确到分钟,毫秒和秒清零
long long current_time_ms = static_cast<long long>(base_time_t) * 1000; // 每分钟递增,单位毫秒
// 设定总的消息数量
int total_messages = mpnum;
// 循环发送 300 条消息
for (int i = 0; i < total_messages; ++i) {
// 修改 Monitor 值
data.monitor_id = front_index *10000 + 1 + i;
data.mp_id = QString::number(data.monitor_id);
std::string modified_time = to_string(current_time_ms); // 时间转换为整数类型Unix时间戳
// 替换消息中的 Monitor 和 TIME 字段(只匹配字段名,不匹配具体数值)
std::string modified_strText = base_strText;
// 替换 Monitor 字段
size_t monitor_pos = modified_strText.find("\"Monitor\"");
if (monitor_pos != std::string::npos) {
size_t colon_pos = modified_strText.find(":", monitor_pos);
size_t quote_pos = modified_strText.find("\"", colon_pos);
size_t end_quote_pos = modified_strText.find("\"", quote_pos + 1);
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, to_string(data.monitor_id));
}
}
// 替换 TIME 字段
size_t time_pos = modified_strText.find("\"TIME\"");
if (time_pos != std::string::npos) {
size_t colon_pos = modified_strText.find(":", time_pos);
size_t quote_pos = colon_pos;
size_t end_quote_pos = modified_strText.find(",", quote_pos + 1);
if (colon_pos != std::string::npos && quote_pos != std::string::npos && end_quote_pos != std::string::npos) {
modified_strText.replace(quote_pos + 1, end_quote_pos - quote_pos - 1, modified_time);
}
}
// 更新数据
data.strText = QString::fromStdString(modified_strText);
// 发送数据
my_rocketmq_send(data);
// 输出调试信息
std::cout << "Sent message " << (i + 1) << " with Monitor " << data.monitor_id << " and TIME " << modified_time << std::endl;
// 等待下一条消息的发送固定为1分钟
//QThread::sleep(60); // 每次发送间隔1分钟
}
std::cout << "Finished sending " << total_messages << " messages." << std::endl;
}

189
cfg_parse/base64.cpp Normal file
View File

@@ -0,0 +1,189 @@
/**
* @file: $RCSfile: base64.cpp,v $
* @brief: base64 include
*
* @version: $Revision: 1.00 $
* @date: $Date: 2024/09/24 18:34:00 $
* @author: $Author: caizhouyu $
* @state: $State: Exp $
*
* @latest: $Id: base64.cpp,v 1.00 2023/10/24 18:34:00 caizhouyu Exp $
*
*/
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "../mms/db_interface.h"
#include "../json/cjson.h"//WW 2023-08-27<32><37><EFBFBD><EFBFBD>json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "../include/curl/curl.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
// Base64 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const char base64_chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
//base64 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static const unsigned char base64_decode_table[] = {
//ÿ<><C3BF>16<31><36>
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //1 - 16
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //17 - 32
0,0,0,0,0,0,0,0,0,0,0,62,0,0,0,63, //33 - 48
52,53,54,55,56,57,58,59,60,61,0,0,0,0,0,0, //49 - 64
0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14, //65 - 80
15,16,17,18,19,20,21,22,23,24,25,0,0,0,0,0, //81 - 96
0,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, //97 - 112
41,42,43,44,45,46,47,48,49,50,51,0,0,0,0,0 //113 - 128
};
/**
* @brief base64_decode base64<36><34><EFBFBD><EFBFBD>
* @param indata <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param inlen <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С
* @param outdata <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param outlen <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С
* @return int 0<><30><EFBFBD>ɹ<EFBFBD> -1<><31><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
* ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĴ<DDB5>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
*/
int base64_decode(const char* indata, int inlen, char* outdata, long* outlen)
{
if (indata == NULL || inlen <= 0 || (outdata == NULL && outlen == NULL)) {
return -1;
}
if (inlen < 4 || inlen % 4 != 0) { //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>Ȳ<EFBFBD><C8B2><EFBFBD>4<EFBFBD>ı<EFBFBD><C4B1><EFBFBD> //inlen < 4 ||
return -1;
}
int i, j;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int len = inlen / 4 * 3;
if (indata[inlen - 1] == '=') {
len--;
}
if (indata[inlen - 2] == '=') {
len--;
}
if (outdata != NULL) {
for (i = 0, j = 0; i < inlen; i += 4, j += 3) {
outdata[j] = (base64_decode_table[(unsigned char)indata[i]] << 2) | (base64_decode_table[(unsigned char)indata[i + 1]] >> 4);
outdata[j + 1] = (base64_decode_table[(unsigned char)indata[i + 1]] << 4) | (base64_decode_table[(unsigned char)indata[i + 2]] >> 2);
outdata[j + 2] = (base64_decode_table[(unsigned char)indata[i + 2]] << 6) | (base64_decode_table[(unsigned char)indata[i + 3]]);
}
}
if (outlen != NULL) {
*outlen = len;
}
return 0;
}
// Base64 <20><><EFBFBD><EFBFBD><EBBAAF>
char* base64_encode_char(const unsigned char* data, size_t input_length, size_t* output_length) {
*output_length = 4 * ((input_length + 2) / 3); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>
char* encoded_data = (char*)malloc(*output_length + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ棬+1 Ϊ '\0'
if (encoded_data == NULL) return NULL;
for (int i = 0, j = 0; i < input_length;) {
uint32_t octet_a = i < input_length ? data[i++] : 0;
uint32_t octet_b = i < input_length ? data[i++] : 0;
uint32_t octet_c = i < input_length ? data[i++] : 0;
uint32_t triple = (octet_a << 16) | (octet_b << 8) | octet_c;
encoded_data[j++] = base64_chars[(triple >> 18) & 0x3F];
encoded_data[j++] = base64_chars[(triple >> 12) & 0x3F];
encoded_data[j++] = (i * 2 / 3) < *output_length ? base64_chars[(triple >> 6) & 0x3F] : '=';
encoded_data[j++] = (i * 2 + 1 / 3) < *output_length ? base64_chars[triple & 0x3F] : '=';
}
encoded_data[*output_length] = '\0'; // <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return encoded_data;
}
/// <summary>
/// <20>ж<EFBFBD><D0B6>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊpower{}<7D><>ʽ
/// </summary>
/// <param name="str"><3E><><EFBFBD><EFBFBD>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD></param>
/// <param name="output"><3E><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD></param>
/// <param name="output_size"><3E>ֶγ<D6B6><CEB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
/// <param name="extracted_length"><3E><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD></param>
/// <returns></returns>
bool extract_if_power(const char* str, char* output, size_t output_size, size_t* extracted_length) {
const char* prefix = "power{";
size_t prefix_length = strlen(prefix);
// <20><><EFBFBD><EFBFBD>ǰ׺
if (strncmp(str, prefix, prefix_length) != 0) {
return false; // ǰ׺<C7B0><D7BA>ƥ<EFBFBD><C6A5>
}
// <20><><EFBFBD>ұպϵĻ<CFB5><C4BB><EFBFBD><EFBFBD><EFBFBD>
const char* close_brace = strchr(str + prefix_length, '}');
if (close_brace == NULL) {
return false; // û<><C3BB><EFBFBD>ҵ<EFBFBD><D2B5>պϵĻ<CFB5><C4BB><EFBFBD><EFBFBD><EFBFBD>
}
// <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
size_t content_length = close_brace - (str + prefix_length);
if (content_length >= output_size) {
return false; // <20><><EFBFBD><EFBFBD>̫<EFBFBD><CCAB><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
strncpy(output, str + prefix_length, content_length);
output[content_length] = '\0'; // <20><><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>ֹ<EFBFBD><D6B9>
printf("text: %s,length:%d\n", output, content_length); // ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
*extracted_length = content_length;
return true; // <20><>ȡ<EFBFBD>ɹ<EFBFBD>
}
//int testbase64(char ** decoded_text) {
// unsigned char text[] = "power{SGVsbG8sIFdvcmxkIWV3ZA==}";
// size_t encoded_length, decoded_length;
// char encoded_text[100];
// if (extract_if_power((char*)text, encoded_text, sizeof(encoded_text), &encoded_length)) {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// long decodedLen = strlen(encoded_text) * 3 / 4;
// * decoded_text = (char*)malloc(decodedLen + 1);
// // <20><><EFBFBD><EFBFBD>Base64<36><34><EFBFBD><EFBFBD>
// int success = base64_decode(encoded_text, strlen(encoded_text), *decoded_text, &decodedLen);
// if (decoded_text) {
// printf("Decoded: %s\n", (char*)decoded_text); // ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
// free(decoded_text); // ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD>ϲ<EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>decoded_text<78><74>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>unsigned char*
// // <20><>ʵ<EFBFBD><CAB5>Ӧ<EFBFBD><D3A6><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊchar*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9>
// }
// }
// else {
// printf(" no Decoded: %s\n", text); // ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
// }
//
// // ע<><EFBFBD><E2A3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>decoded_text<78><74>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD>׼ȷ<D7BC>ģ<EFBFBD><C4A3><EFBFBD>Ϊdecoded_text<78><74>unsigned char*<2A>ҿ<EFBFBD><D2BF>ܲ<EFBFBD><DCB2><EFBFBD>null<6C><6C>ֹ<EFBFBD><D6B9><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
// // <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD>decoded_textת<74><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
// return 0;
//}
#ifdef __cplusplus
}
#endif

14282
cfg_parse/cfg_parser.cpp Normal file

File diff suppressed because it is too large Load Diff

132
cfg_parse/datahub.cpp Normal file
View File

@@ -0,0 +1,132 @@
/**
* @file: $RCSfile: datahub.cpp,v $
* @brief: $aliyun datahub include
*
* @version: $Revision: 1.00 $
* @date: $Date: 2023/10/10 18:34:00 $
* @author: $Author: wangwei $
* @state: $State: Exp $
*
* @latest: $Id: datahub.cpp,v 1.00 2023/10/10 18:34:00 wangwei Exp $
*
*/
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "../mms/db_interface.h"
#include "../json/cjson.h"//WW 2023-08-27<32><37><EFBFBD><EFBFBD>json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "../include/curl/curl.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
size_t req_reply_datahub(void* ptr, size_t size, size_t nmemb, void* stream)
{
//<2F><>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cookie<69><65><EFBFBD><EFBFBD>Ϣ
string* str = (string*)stream;
(*str).append((char*)ptr, size * nmemb);
//printf(">>>GetDevice in reply %s\n", (char*)ptr);
//GetCJson(ptr);
return size * nmemb;
}
void SendWebAPI_Datahub(const string strUrl,char* topic,char* data)
{
// curl<72><6C>ʼ<EFBFBD><CABC>
CURL* curl = curl_easy_init();
// curl<72><6C><EFBFBD><EFBFBD>ֵ
CURLcode res;
if (curl)
{
//<2F><><EFBFBD><EFBFBD>curl<72><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
struct curl_slist* header_list = NULL;
header_list = curl_slist_append(header_list, "Content-Type:application/json;");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧͷ<D3A6><CDB7><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊpost<73><74><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_POST, 1);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
cJSON* json_root = cJSON_CreateObject();
//cJSON_AddItemToObject(json_root, "topic", cJSON_CreateString("ems_pq_mmxu_stat"));
//cJSON_AddItemToObject(json_root, "data", cJSON_CreateString("{\"DATA_TYPE\": \"04\",\"Monitor\": \"4563\",\"Value\": {\"FLAG\": 1,\"TIME\": 1512097260000,\"VOLTAGE\": {\"MAG\": 56.23,\"DUR\": 23,\"STARTTIME\": 1512097260000,\"ENDTIME\": 1512097283000,\"DISKIND\": \"01\",\"WAVEFILE\": \"PQMonitor_PQM1_000001_20230707_103916_596\",\"PHASIC\": \"unknow\"}}}"));
cJSON_AddItemToObject(json_root, "topic", cJSON_CreateString(topic));
cJSON_AddItemToObject(json_root, "data", cJSON_CreateString(data));
char* szjson = cJSON_Print(json_root);
//printf(">>>json %s\n", szjson);
//string strjson = szjson;
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
//CURLOPT_VERBOSE<53><45>ֵΪ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ϸ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD><EFBFBD><EBBAAF>
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_datahub);
string resPost0;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
printf(">>>Testaliyun datahub Post in curl post\n");
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
res = curl_easy_perform(curl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (res != CURLE_OK) {
printf("aliyun datahub failed res code: ");
}
else {
printf("aliyun datahub success,string %s", resPost0.c_str());
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>webapi<70><69><EFBFBD><EFBFBD>ֵ<EFBFBD>ж<EFBFBD>
}
curl_slist_free_all(header_list);
free(szjson);
cJSON_Delete(json_root);
}
else
{
printf(">>> token curl init failed");
}
curl_easy_cleanup(curl);
}
void DataHub_Send_Datahub(char* topic,char* data)
{
SendWebAPI_Datahub("http://127.0.0.1:8091/powerQuality/PQDATAHUB",topic,data);
}
#ifdef __cplusplus
}
#endif

10191
cfg_parse/httplib.h Normal file

File diff suppressed because it is too large Load Diff

247
cfg_parse/httprun.cpp Normal file
View File

@@ -0,0 +1,247 @@
#include <thread>
#include <iostream>
#include "httplib.h"
#include <string>
#include "../json/cjson.h"
//#include <mutex>
//#include <queue>
//std::mutex data_mutex; // 用来保护 receivedData 变量
//#include <atomic>
//std::atomic<bool> isrunning(false); // 使用原子变量保证 isrunning 的内存可见性
//std::queue<std::string> receivedData; // 用于存储接收到的数据
bool isrunning = true; //用于线程同步
std::string receivedData;
//std::queue<std::string> receivedData2; // 用于存储接收到的数据
bool isrunning2 = true; //用于线程同步
std::string receivedData2;
extern std::string HTTP_IP;
extern int HTTP_PORT;
//设置回复消息体
std::string recall_success = "{\"code\":\"A0000\", \"msg\":\"数据补招执行成功\", \"data\":null}";
std::string recall_fail = "{\"code\":\"A0002\", \"msg\":\"数据补招执行失败\", \"data\":null}";
std::string rtdata_success = "{\"code\":\"A0000\", \"msg\":\"3s数据执行成功\", \"data\":null}";
std::string rtdata_fail = "{\"code\":\"A0002\", \"msg\":\"3s数据执行失败\", \"data\":null}";
// 处理补招请求的函数
std::string HandleRecall_http(const httplib::Request& req, httplib::Response& res) {
// 打印请求的查询参数
//std::cout << "Query parameters: " << std::endl;
//std::lock_guard<std::mutex> lock(data_mutex);
if(isrunning == true){ //收到前置信号,收到信息可以处理消息
if (req.body.empty()) { //消息体为空
std::cout << "req.body.empty" << std::endl;
res.status = 400;
res.set_content(recall_fail, "application/json");
return recall_fail;
}
// 消息体不为空,解析 JSON 数据
cJSON* json_root = cJSON_Parse(req.body.c_str());
//解析失败或者消息体不为数组
if (json_root == NULL || json_root->type != cJSON_Array) {
std::cout << "json_root NULL or json_roottype not cJSON_Array" << std::endl;
res.status = 400;
res.set_content(recall_fail, "application/json");
cJSON_Delete(json_root);
return recall_fail;
}
bool is_valid = true;//默认消息体正常
//检查数组每个成员
for (cJSON* item = json_root->child; item != NULL; item = item->next) {
// 检查每个对象是否包含 monitorId、dataType、timeInterval 且不为空
cJSON* monitorId = cJSON_GetObjectItem(item, "monitorId");
cJSON* dataType = cJSON_GetObjectItem(item, "dataType");
cJSON* timeInterval = cJSON_GetObjectItem(item, "timeInterval");
//调试用
std::cout << "!timeInterval" << !timeInterval << " " << (timeInterval->type != cJSON_Array) << " "<< (timeInterval->child == NULL) << std::endl;
if (!timeInterval || //元素必须不为空
timeInterval->type != cJSON_Array || timeInterval->child == NULL) { // timeInterval 必须为非空数组
is_valid = false; //不满足结构则消息体不正常
break;
}
}
// 清理 JSON 数据
cJSON_Delete(json_root);
// 设置响应内容
if (is_valid) {
res.status = 200; //消息体正常返回补招执行成功
res.set_content(recall_success, "application/json");
receivedData = req.body; //提供给前置获取消息体处理
isrunning = false; //停止处理http收到的消息直到收到前置的信号
return recall_success;
} else {
std::cout << "json not right" << std::endl;
res.status = 400;
res.set_content(recall_fail, "application/json");
return recall_fail;
}
}
return req.body; // 返回接收到的未处理的 JSON暂时没有任何地方使用
}
// 处理实时数据请求的函数
std::string HandleRtdata_http(const httplib::Request& req, httplib::Response& res) {
if(isrunning2 == true){ //收到前置信号,收到信息可以处理消息
if (req.body.empty()) { //消息体为空
std::cout << "req.body.empty" << std::endl;
res.status = 400;
res.set_content(rtdata_fail, "application/json");
return rtdata_fail;
}
// 消息体不为空,解析 JSON 数据
cJSON* json_root = cJSON_Parse(req.body.c_str());
//解析失败或者消息体不为数组
if (json_root == NULL || json_root->type != cJSON_Array) {
std::cout << "json_root NULL or json_roottype not cJSON_Array" << std::endl;
res.status = 400;
res.set_content(rtdata_fail, "application/json");
cJSON_Delete(json_root);
return rtdata_fail;
}
bool is_valid = true;//默认消息体正常
//检查数组每个成员
for (cJSON* item = json_root->child; item != NULL; item = item->next) {
// 检查每个对象不为空
cJSON* DevSeries = cJSON_GetObjectItem(item, "DevSeries");
cJSON* Line = cJSON_GetObjectItem(item, "Line");
cJSON* RealData = cJSON_GetObjectItem(item, "RealData");
cJSON* SOEData = cJSON_GetObjectItem(item, "SOEData");
cJSON* Limit = cJSON_GetObjectItem(item, "Limit");
cJSON* Count = cJSON_GetObjectItem(item, "Count");
if (!DevSeries || !Line || !RealData || !SOEData || !Limit || !Count) {
is_valid = false; //不满足结构则消息体不正常
break;
}
}
// 清理 JSON 数据
cJSON_Delete(json_root);
// 设置响应内容
if (is_valid) {
res.status = 200; //消息体正常返回补招执行成功
res.set_content(rtdata_success, "application/json");
receivedData2 = req.body;
isrunning2 = false; //停止处理http收到的消息直到收到前置的信号
return rtdata_success;
} else {
std::cout << "json not right" << std::endl;
res.status = 400;
res.set_content(rtdata_fail, "application/json");
return rtdata_fail;
}
}
return req.body; // 返回接收到的未处理的 JSON暂时没有任何地方使用
}
//处理台账更新请求函数
std::string Handleupdate_http(const httplib::Request& req, httplib::Response& res){
}
// 获取接收到的字符串
//extern "C" std::string getReceivedData() {
extern "C" const char* getReceivedData(int fun) {
if(1 == fun){
/*if (!receivedData.empty()) {
std::string msg = receivedData.front(); // 获取队列中的第一条消息
receivedData.pop(); // 从队列中移除这条消息
return msg.c_str();
}
return "recall queue empty";*/
return receivedData.c_str();
}
if(2 == fun){
/*if (!receivedData2.empty()) {
std::string msg = receivedData2.front(); // 获取队列中的第一条消息
receivedData2.pop(); // 从队列中移除这条消息
return msg.c_str();
}
return "rtdata queue empty";*/
return receivedData2.c_str();
}
return "all queue empty";
}
// 收取信号 1是补招2是实时数据
extern "C" void threadmsgweb(int fun) {
if(1 == fun){
isrunning = true;
}
if(2 == fun){
isrunning2 = true;
}
}
// 发送信号
extern "C" bool threadmsghttp(int fun) {
if(1 == fun){
return isrunning;
}
if(2 == fun){
return isrunning2;
}
return true;
}
// 启动 HTTP 服务器的函数
extern "C" void httprun() {
//std::cout << "WebhttpThread::run() is called ...... " << std::endl;
// 创建 HTTP 服务器对象
httplib::Server svr;
// 监听路径 /powerQuality/recall绑定处理函数
svr.Post("/powerQuality/recall", HandleRecall_http); // 使用 POST 方法处理请求
// 监听路径 /powerQuality/rtdata绑定处理函数
svr.Post("/powerQuality/rtdata", HandleRtdata_http); // 使用 POST 方法处理请求
// 监听路径 /powerQuality/update绑定处理函数
svr.Post("/powerQuality/update", Handleupdate_http); // 使用 POST 方法处理请求
// 监听端口 10004
//std::cout << "Server started at http://0.0.0.0:10004" << std::endl;
if (!svr.listen(HTTP_IP, HTTP_PORT)) { // 监听所有 IP
std::cerr << "Error: Unable to start server on port 10004" << std::endl;
}
//std::cout << "WebhttpThread::run() is end ...... " << std::endl;
}

742
cfg_parse/nacos.cpp Normal file
View File

@@ -0,0 +1,742 @@
/**
* @file: $RCSfile: nacos.cpp,v $
* @brief: $aliyun datahub include
*
* @version: $Revision: 1.00 $
* @date: $Date: 2023/10/24 18:34:00 $
* @author: $Author: wangwei $
* @state: $State: Exp $
*
* @latest: $Id: nacos.cpp,v 1.00 2023/10/24 18:34:00 caizhouyu Exp $
*
*/
using namespace std;
#include <stdio.h>
/*lnk10-12*/
#include <iostream>
#include <stdlib.h>
#include <string>
#include "../mms/db_interface.h"
#include "../json/cjson.h"//WW 2023-08-27<32><37><EFBFBD><EFBFBD>json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "../include/curl/curl.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
size_t req_reply_nacos(void* ptr, size_t size, size_t nmemb, void* stream)
{
//((std::string*)userp)->append((char*)contents, size * nmemb);
//<2F><>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cookie<69><65><EFBFBD><EFBFBD>Ϣ
string* str = (string*)stream;
(*str).append((char*)ptr, size * nmemb);
//printf(">>>GetDevice in reply %s\n", (char*)ptr);
//GetCJson(ptr);
return size * nmemb;
}
void read_nacos_param(const char* ptr, char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret) {
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse((char*)ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error %s\n", cJSON_GetErrorPtr());
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || json_node->valuestring == NULL || json_node->valuestring == "/0" || json_node->valuestring == "" || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || json_node->valuestring == NULL || json_node->valuestring == "/0" || json_node->valuestring == "" || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "postgres_uid"); //<2F><>ȡresult
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
strcpy(postgres_uid, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "postgres_pwd"); //<2F><>ȡresult
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
//***postgres_pwd = json_node->valuestring;
strcpy(postgres_pwd, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "web_clientid"); //<2F><>ȡresult
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
strcpy(web_clientid, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "web_clientsecret"); //<2F><>ȡresult
if (json_node != NULL && strcmp(json_node->valuestring, "null") != 0) {
strcpy(web_clientsecret, json_node->valuestring);
}
}
}
cJSON_Delete(json);
}
void releaseMemory(char** ptr) {
if (*ptr != NULL) {
free(*ptr); // <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
}
}
void SendWebAPI_Nacos(const string strUrl, const char* code, char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret)
{
// curl<72><6C>ʼ<EFBFBD><CABC>
CURL* curl = curl_easy_init();
// curl<72><6C><EFBFBD><EFBFBD>ֵ
CURLcode res;
if (curl)
{
//<2F><><EFBFBD><EFBFBD>curl<72><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
struct curl_slist* header_list = NULL;
header_list = curl_slist_append(header_list, "Content-Type:application/json;");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧͷ<D3A6><CDB7><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊpost<73><74><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_POST, 1);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
cJSON* json_root = cJSON_CreateObject();
cJSON_AddItemToObject(json_root, "code", cJSON_CreateString(code));
char* szjson = cJSON_Print(json_root);
printf(">>>json %s\n", szjson);
//string strjson = szjson;
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
//CURLOPT_VERBOSE<53><45>ֵΪ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ϸ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD><EFBFBD><EBBAAF>
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_nacos);
string resPost0;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
printf(">>>Test nacos Post in curl post\n");
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
res = curl_easy_perform(curl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (res != CURLE_OK) {
printf("nacos failed res code: ");
}
else {
printf("nacos success,string %s", resPost0.c_str());
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>webapi<70><69><EFBFBD><EFBFBD>ֵ<EFBFBD>ж<EFBFBD>
read_nacos_param(resPost0.c_str(), postgres_uid, postgres_pwd, web_clientid, web_clientsecret);
}
curl_slist_free_all(header_list);
free(szjson);
cJSON_Delete(json_root);
}
else
{
printf(">>> nacos curl init failed");
}
curl_easy_cleanup(curl);
}
void SendWebAPI_Nacos_Ptr(const string strUrl, const char* code, char** ptr)
{
// curl<72><6C>ʼ<EFBFBD><CABC>
CURL* curl = curl_easy_init();
// curl<72><6C><EFBFBD><EFBFBD>ֵ
CURLcode res;
if (curl)
{
char url[100];
sprintf(url, "%s?code=%s", strUrl.c_str(), code);
printf(">>>json %s\n", url);
// <20><><EFBFBD><EFBFBD>URL
curl_easy_setopt(curl, CURLOPT_URL, url);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD><EFBFBD><EBBAAF>
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_nacos);
string resPost0;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
res = curl_easy_perform(curl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (res != CURLE_OK) {
printf("nacos failed res code: ");
}
else {
printf(">>> nacos return str:%s \n", resPost0.c_str());
//*ptr = strdup(resPost0.c_str());
*ptr = (char*)malloc(strlen(resPost0.c_str()) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B9BB><EFBFBD>ڴ<EFBFBD><DAB4>ռ<EFBFBD>
if (*ptr != NULL) {
strcpy(*ptr, resPost0.c_str());
}
else {
printf("Memory allocation failed!\n");
}
//printf(">>>json %s\n", *ptr);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>webapi<70><69><EFBFBD><EFBFBD>ֵ<EFBFBD>ж<EFBFBD>
}
//free(url);
}
else
{
printf(">>> nacos curl init failed");
}
curl_easy_cleanup(curl);
}
void Nacos_GetParam(char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret)
{
SendWebAPI_Nacos("http://127.0.0.1:8091/powerQuality/PQNACOS", "200", postgres_uid, postgres_pwd, web_clientid, web_clientsecret);
}
void Nacos_GetParam_Ptr(const char* code, char** ptr)
{
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", code, ptr);
}
void Read_Nacos_Param_Postgres(char** database_ip, char** database_port, char** postgres_database, char** postgres_username, char** postgres_password, char** postgres_schema, char** postgres_dnsname, char** postgres_tableprefix) {
char* ptr=NULL;
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "postgres", &ptr);
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error %s\n", cJSON_GetErrorPtr());
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "ip"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*database_ip != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*database_ip);
}
*database_ip = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*database_ip, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "port"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*database_port != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*database_port);
}
*database_port = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*database_port, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "database"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*postgres_database != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*postgres_database);
}
*postgres_database = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*postgres_database, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "username"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
//***postgres_pwd = json_node->valuestring;
if (*postgres_username != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*postgres_username);
}
*postgres_username = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*postgres_username, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "password"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*postgres_password != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*postgres_password);
}
*postgres_password = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*postgres_password, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "schema"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*postgres_schema != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*postgres_schema);
}
*postgres_schema = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*postgres_schema, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "dnsname"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*postgres_dnsname != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*postgres_dnsname);
}
*postgres_dnsname = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*postgres_dnsname, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "tablePrefix"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*postgres_tableprefix != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*postgres_tableprefix);
}
*postgres_tableprefix = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*postgres_tableprefix, json_node->valuestring);
}
}
}
if (ptr) {
free(ptr);
}
cJSON_Delete(json);
}
void Read_Nacos_Param_Kafka(char** broker_list, char** topic_stat, char** topic_pst, char** topic_plt, char** topic_event, char** topic_alarm, char** topic_sng,char** protocol ,char** mechanisms, char** service_name, char** principal, char** domain_name) {
char* ptr = NULL;
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "kafka", &ptr);
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error %s\n", cJSON_GetErrorPtr());
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "brokerList"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*broker_list != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*broker_list);
}
*broker_list = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*broker_list, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "hisTopic"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*topic_stat != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*topic_stat);
}
*topic_stat = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*topic_stat, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "pstTopic"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*topic_pst != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*topic_pst);
}
*topic_pst = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*topic_pst, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "pltTopic"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*topic_plt != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*topic_plt);
}
*topic_plt = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*topic_plt, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "eventTopic"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*topic_event != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*topic_event);
}
*topic_event = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*topic_event, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "almTopic"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*topic_alarm != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*topic_alarm);
}
*topic_alarm = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*topic_alarm, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "sngTopic"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*topic_sng != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*topic_sng);
}
*topic_sng = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*topic_sng, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "protocol"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*protocol != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*protocol);
}
*protocol = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*protocol, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "mechanisms"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*mechanisms != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*mechanisms);
}
*mechanisms = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*mechanisms, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "serviceName"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*service_name != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*service_name);
}
*service_name = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*service_name, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "principal"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*principal != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*principal);
}
*principal = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*principal, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "domainName"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*domain_name != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*domain_name);
}
*domain_name = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*domain_name, json_node->valuestring);
}
}
}
cJSON_Delete(json);
}
void Read_Nacos_Param_Web(char** client_id, char** client_secret, char** token_url, char** device_url, char** grant_type) {
char* ptr = NULL;
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "web", &ptr);
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error %s\n", cJSON_GetErrorPtr());
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "clientId"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*client_id != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*client_id);
}
*client_id = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*client_id, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "clientSecret"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*client_secret != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*client_secret);
}
*client_secret = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*client_secret, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "tokenUrl"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*token_url != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*token_url);
}
*token_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*token_url, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "deviceUrl"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
//***postgres_pwd = json_node->valuestring;
if (*device_url != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*device_url);
}
*device_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*device_url, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "grantType"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*grant_type != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*grant_type);
}
*grant_type = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*grant_type, json_node->valuestring);
}
}
}
cJSON_Delete(json);
}
void Read_Nacos_Param_Flag(int* file_flag, int* send_flag, int* front_inst, char** front_ip) {
char* ptr = NULL;
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "flag", &ptr);
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error: %s\n", ptr);
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "fileFlag"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
*file_flag= atoi(json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "sendFlag"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
*send_flag = atoi(json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "frontInst"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
*front_inst = atoi(json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "frontIP"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
//***postgres_pwd = json_node->valuestring;
if (*front_ip != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*front_ip);
}
*front_ip = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*front_ip, json_node->valuestring);
}
}
}
cJSON_Delete(json);
}
void Read_Nacos_Param_Recall(int* recall_len, int* recall_sta, int* recall_daily) {
char* ptr = NULL;
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "recall", &ptr);
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error %s\n", cJSON_GetErrorPtr());
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "recall_lenth"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
*recall_len = atoi(json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "recall_start"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
*recall_sta = atoi(json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "recall_dailytime"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
*recall_daily = atoi(json_node->valuestring);
}
}
}
cJSON_Delete(json);
}
void Read_Nacos_Param_Uds(char** uds_upload_url, char** uds_download_url, char** uds_delete_url) {
char* ptr = NULL;
SendWebAPI_Nacos_Ptr("http://127.0.0.1:8091/powerQuality/getProperties", "uds", &ptr);
//cout << ">>>GetDevice in reply" << (char*)ptr;
int flag = 1;
cJSON* json = cJSON_Parse(ptr); //json<6F><6E>ʽ<EFBFBD><CABD><EFBFBD>л<EFBFBD>
cJSON* json_node;
cJSON* json_param;
if (json == NULL) {
printf("nacos error %s\n", cJSON_GetErrorPtr());
}
else {
json_node = cJSON_GetObjectItem(json, "status"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "000000") != 0) {
printf("status error :%s\n", cJSON_GetErrorPtr());
flag = 0;
}
json_node = cJSON_GetObjectItem(json, "errors"); //<2F><>ȡresult
if (json_node == NULL || strcmp(json_node->valuestring, "success") != 0) {
printf("errors get falie: %s\n", cJSON_GetErrorPtr());
flag = 0;
}
if (flag) {
printf("read nacos success\n");
json_param = cJSON_GetObjectItem(json, "param"); //<2F><>ȡresult
json_node = cJSON_GetObjectItem(json_param, "udsUploadUrl"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*uds_upload_url != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*uds_upload_url);
}
*uds_upload_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*uds_upload_url, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "udsDownloadUrl"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*uds_download_url != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*uds_download_url);
}
*uds_download_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*uds_download_url, json_node->valuestring);
}
json_node = cJSON_GetObjectItem(json_param, "UdsDeleteUrl"); //<2F><>ȡresult
if (json_node && json_node->type == cJSON_String) {
if (*uds_delete_url != NULL) {
// <20><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
free(*uds_delete_url);
}
*uds_delete_url = (char*)malloc(strlen(json_node->valuestring) + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
strcpy(*uds_delete_url, json_node->valuestring);
}
}
}
cJSON_Delete(json);
}
#ifdef __cplusplus
}
#endif

306
cfg_parse/obs_huaweiyun.cpp Normal file
View File

@@ -0,0 +1,306 @@
/**
* @file: $RCSfile: obs_huaweiyun.cpp,v $
* @brief: $huaweiyun obs include
*
* @version: $Revision: 1.00 $
* @date: $Date: 2023/09/04 18:34:00 $
* @author: $Author: wangwei $
* @state: $State: Exp $
*
* @latest: $Id: obs_huaweiyun.cpp,v 1.00 2023/09/04 18:34:00 wangwei Exp $
*
*/
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "../mms/db_interface.h"
#include "../json/cjson.h"//WW 2023-08-27<32><37><EFBFBD><EFBFBD>json<6F><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#include "../include/curl/curl.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
char ACCESS_KEY_ID_OBS[2048] = { "J9GS9EA79PZ60OK23LWP" };
char SECRET_ACCESS_KEY[2048] = { "BirGrAFDSLxU8ow5fffyXgZRAmMRb1R1AdqCI60d" };
char HOST_NAME[2048] = { "obs.cn-east-3.myhuaweicloud.com" };
char BUCKET_NAME_OBS[2048] = { "test-8601" };
size_t req_reply_device(void* ptr, size_t size, size_t nmemb, void* stream)
{
//<2F><>ע<EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cookie<69><65><EFBFBD><EFBFBD>Ϣ
string* str = (string*)stream;
(*str).append((char*)ptr, size * nmemb);
//printf(">>>GetDevice in reply %s\n", (char*)ptr);
//GetCJson(ptr);
return size * nmemb;
}
void SendWebAPI_Test(const string strUrl)
{
// curl<72><6C>ʼ<EFBFBD><CABC>
CURL* curl = curl_easy_init();
// curl<72><6C><EFBFBD><EFBFBD>ֵ
CURLcode res;
if (curl)
{
//<2F><><EFBFBD><EFBFBD>curl<72><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
struct curl_slist* header_list = NULL;
header_list = curl_slist_append(header_list, "Content-Type:application/json;");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧͷ<D3A6><CDB7><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊpost<73><74><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_POST, 1);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
cJSON* json_root = cJSON_CreateObject();
cJSON* json_param = cJSON_CreateObject();
cJSON_AddItemToObject(json_root, "code", cJSON_CreateString("putObject"));
cJSON_AddItemToObject(json_root, "param", json_param);
//param<61><6D>
cJSON_AddItemToObject(json_param, "object_name", cJSON_CreateString("comtrade/pq/Device.xml"));
cJSON_AddItemToObject(json_param, "localfile_name", cJSON_CreateString("/FeProject/etc/Device_Config.xml"));
char* szjson = cJSON_Print(json_root);
printf(">>>json %s\n", szjson);
//string strjson = szjson;
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
//CURLOPT_VERBOSE<53><45>ֵΪ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ϸ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD><EFBFBD><EBBAAF>
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_device);
string resPost0;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
printf(">>>TestHuaweiyun Obs Post in curl post\n");
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
res = curl_easy_perform(curl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (res != CURLE_OK) {
printf("Huaweiyun Obs failed res code: " );
}
else {
printf("Huaweiyun Obs success,string %s",resPost0.c_str());
}
curl_slist_free_all(header_list);
free(szjson);
cJSON_Delete(json_root);
}
else
{
printf(">>> token curl init failed");
}
curl_easy_cleanup(curl);
}
void TestOBS()
{
SendWebAPI_Test("http://127.0.0.1:8091/powerQuality/PQOBS");
}
void SendWebAPI(const string strUrl, char* localpath, char* cloudpath,const char* code)
{
// curl<72><6C>ʼ<EFBFBD><CABC>
CURL* curl = curl_easy_init();
// curl<72><6C><EFBFBD><EFBFBD>ֵ
CURLcode res;
if (curl)
{
//<2F><><EFBFBD><EFBFBD>curl<72><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
struct curl_slist* header_list = NULL;
header_list = curl_slist_append(header_list, "Content-Type:application/json;");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧͷ<D3A6><CDB7><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊpost<73><74><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_POST, 1);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
cJSON* json_root = cJSON_CreateObject();
cJSON* json_param = cJSON_CreateObject();
cJSON_AddItemToObject(json_root, "code", cJSON_CreateString(code));
cJSON_AddItemToObject(json_root, "param", json_param);
//param<61><6D>
cJSON_AddItemToObject(json_param, "object_name", cJSON_CreateString(cloudpath));
cJSON_AddItemToObject(json_param, "localfile_name", cJSON_CreateString(localpath));
char* szjson = cJSON_Print(json_root);
printf(">>>json %s\n", szjson);
//string strjson = szjson;
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
//CURLOPT_VERBOSE<53><45>ֵΪ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ϸ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD><EFBFBD><EBBAAF>
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_device);
string resPost0;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
printf(">>>TestHuaweiyun Obs Post in curl post\n");
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
res = curl_easy_perform(curl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (res != CURLE_OK) {
printf("Huaweiyun Obs failed res code: ");
}
else {
printf("Huaweiyun Obs success,string %s", resPost0.c_str());
}
curl_slist_free_all(header_list);
free(szjson);
cJSON_Delete(json_root);
}
else
{
printf(">>> token curl init failed");
}
curl_easy_cleanup(curl);
}
void OBSFile(char* localpath,char* cloudpath,const char* code)
{
SendWebAPI("http://127.0.0.1:8091/powerQuality/PQOBS",localpath,cloudpath,code);
}
void SendWebAPI_del(const string strUrl, char* cloudpath, const char* code)
{
// curl<72><6C>ʼ<EFBFBD><CABC>
CURL* curl = curl_easy_init();
// curl<72><6C><EFBFBD><EFBFBD>ֵ
CURLcode res;
if (curl)
{
//<2F><><EFBFBD><EFBFBD>curl<72><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
struct curl_slist* header_list = NULL;
header_list = curl_slist_append(header_list, "Content-Type:application/json;");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧͷ<D3A6><CDB7><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊpost<73><74><EFBFBD><EFBFBD>
curl_easy_setopt(curl, CURLOPT_POST, 1);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>URL<52><4C>ַ
curl_easy_setopt(curl, CURLOPT_URL, strUrl.c_str());
//<2F><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
cJSON* json_root = cJSON_CreateObject();
cJSON* json_param = cJSON_CreateObject();
cJSON_AddItemToObject(json_root, "code", cJSON_CreateString(code));
cJSON_AddItemToObject(json_root, "param", json_param);
//param<61><6D>
cJSON_AddItemToObject(json_param, "object_name", cJSON_CreateString(cloudpath));
cJSON_AddNullToObject(json_param, "localfile_name");
//cJSON_AddItemToObject(json_param, "localfile_name", cJSON_CreateString(localpath));
char* szjson = cJSON_Print(json_root);
printf(">>>json %s\n", szjson);
//string strjson = szjson;
//char* pszEncodeSecret = curl_easy_escape(curl, strclientsecret.c_str(), strclientsecret.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, szjson);
//<2F><><EFBFBD><EFBFBD>ssl<73><6C>֤
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
//CURLOPT_VERBOSE<53><45>ֵΪ1ʱ<31><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ϸ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>Ϣ
curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>պ<EFBFBD>д<EFBFBD><EFBFBD><EBBAAF>
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, req_reply_device);
string resPost0;
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&resPost0);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
//<2F><><EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1>
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
printf(">>>TestHuaweiyun Obs Post in curl post\n");
// <20><><EFBFBD><EFBFBD>post<73><74><EFBFBD><EFBFBD>
res = curl_easy_perform(curl);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
if (res != CURLE_OK) {
printf("Huaweiyun Obs failed res code: ");
}
else {
printf("Huaweiyun Obs success,string %s", resPost0.c_str());
}
curl_slist_free_all(header_list);
free(szjson);
cJSON_Delete(json_root);
}
else
{
printf(">>> token curl init failed");
}
curl_easy_cleanup(curl);
}
void OBSFile_del(char* cloudpath, const char* code)
{
SendWebAPI_del("http://127.0.0.1:8091/powerQuality/PQOBS", cloudpath, code);
}
#ifdef __cplusplus
}
#endif

510
cfg_parse/oss_aliyun.cpp Normal file
View File

@@ -0,0 +1,510 @@
/**
* @file: $RCSfile: oss_aliyun.cpp,v $
* @brief: $aliyun oss include
*
* @version: $Revision: 1.01 $
* @date: $Date: 2023/08/31 23:02:00 $
* @author: $Author: wangwei $
* @state: $State: Exp $
*
* @latest: $Id: oss_aliyun.cpp,v 1.01 2023/08/31 23:02:00 wangwei Exp $
*
*/
using namespace std;
#include "aos_log.h"
#include "aos_util.h"
#include "aos_string.h"
#include "aos_status.h"
#include "oss_auth.h"
#include "oss_util.h"
#include "oss_api.h"
#include "../mms/db_interface.h"
#include <iostream>
char* OSS_ENDPOINT;
char* ACCESS_KEY_ID;
char* ACCESS_KEY_SECRET;
char* BUCKET_NAME;
//const char OSS_ENDPOINT[] = "oss-cn-nanjing.aliyuncs.com";
//const char ACCESS_KEY_ID[] = "LTAI5tER4bgJxT6Ptie7t2X7";
//const char ACCESS_KEY_SECRET[] = "dSYIC5hD3flhTNoLMAxCoKjSPdWFSz";
//const char BUCKET_NAME[] = "cn-pq-test";
const char OBJECT_NAME[] = "comtrade/temp.json";
void init_sample_request_options(oss_request_options_t *options, int is_cname);
void put_object_from_buffer();
void put_object_from_buffer_new(char* File_Name, char* data);
void put_object_from_file();
void put_object_from_file_new(char* File_Name, char* path);
void get_object_to_buffer();
void get_object_to_file();
void get_object_to_file_new(char* File_Name, char* savepath);
void delete_object();
void delete_object_new(char* File_Name);
void TestOSS()
{
apr_file_t *output = NULL;
aos_pool_t *pool = NULL;
apr_status_t ret;
// initialize http io system, call it olny once
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
printf(">>>TestOSS ini Start");
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
return;
}
printf(">>>TestOSS put Start");
// run samples
//put_object_from_buffer();
//put_object_from_file();
put_object_from_buffer();
get_object_to_file();
//get_object_to_buffer();
//get_object_to_file();
//delete_object();
printf(">>>TestOSS put End");
// deinitialize http io system, call it olny once
aos_http_io_deinitialize();
return ;
}
void PutOSS(char* File_Name,char* data) //zw<7A>޸<EFBFBD> 2023-9-7 <20><><EFBFBD><EFBFBD>oss<73>ļ<EFBFBD>
{
apr_file_t* output = NULL;
aos_pool_t* pool = NULL;
apr_status_t ret;
// initialize http io system, call it olny once
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
printf(">>>PutOSS ini Start");
printf(File_Name);
printf(data);
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
return;
}
printf(">>>PutOSS put Start");
put_object_from_file_new(File_Name, data);//ʹ<><CAB9>buffer<65><72><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
printf(">>>PutOSS put End");
// deinitialize http io system, call it olny once
aos_http_io_deinitialize();
return;
}
void GetOSS(char* File_Name,char* savepath) //zw<7A>޸<EFBFBD> 2023-9-7 <20><>ȡoss<73>ļ<EFBFBD>
{
apr_file_t* output = NULL;
aos_pool_t* pool = NULL;
apr_status_t ret;
// initialize http io system, call it olny once
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
printf(">>>GetOSS ini Start");
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
return;
}
printf(">>>GetOSS put Start");
get_object_to_file_new(File_Name,savepath);//ʹ<><CAB9>buffer<65><72><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
printf(">>>GetOSS put End");
// deinitialize http io system, call it olny once
aos_http_io_deinitialize();
return;
}
void DelOSS(char* File_Name)
{
apr_file_t* output = NULL;
aos_pool_t* pool = NULL;
apr_status_t ret;
// initialize http io system, call it olny once
/* <20>ڳ<EFBFBD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD>aos_http_io_initialize<7A><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>*/
printf(">>>DelOSS ini Start");
if (aos_http_io_initialize(NULL, 0) != AOSE_OK) {
return;
}
printf(">>>DelOSS put Start");
delete_object_new(File_Name);//ʹ<><CAB9>buffer<65><72><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
printf(">>>DelOSS put End");
// deinitialize http io system, call it olny once
aos_http_io_deinitialize();
return;
}
void coutTest() {
std:: cout << "OSS_ENDPOINT:" << OSS_ENDPOINT << std::endl;
std::cout << "ACCESS_KEY_ID:" << ACCESS_KEY_ID << std::endl;
std::cout << "ACCESS_KEY_SECRET:" << ACCESS_KEY_SECRET << std::endl;
std::cout << "BUCKET_NAME:" << BUCKET_NAME << std::endl;
}
void init_sample_request_options(oss_request_options_t *options, int is_cname)
{
options->config = oss_config_create(options->pool);
aos_str_set(&options->config->endpoint, OSS_ENDPOINT);
aos_str_set(&options->config->access_key_id, ACCESS_KEY_ID);
aos_str_set(&options->config->access_key_secret, ACCESS_KEY_SECRET);
options->config->is_cname = is_cname;
options->ctl = aos_http_controller_create(options->pool, 0);
}
void put_object_from_buffer()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
oss_request_options_t *options = NULL;
aos_list_t buffer;
aos_buf_t *content = NULL;
char *str = "test oss c sdk";
aos_status_t *s = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
headers = aos_table_make(p, 1);
apr_table_set(headers, "x-oss-meta-author", "oss");
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, OBJECT_NAME);
aos_list_init(&buffer);
content = aos_buf_pack(options->pool, str, strlen(str));
aos_list_add_tail(&content->node, &buffer);
s = oss_put_object_from_buffer(options, &bucket, &object,
&buffer, headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("put object from buffer succeeded\n");
}
else {
printf("put object from buffer failed\n");
}
aos_pool_destroy(p);
}
void put_object_from_buffer_new(char* File_Name,char* data)//zw<7A>޸<EFBFBD> 2023-9-7 oss<73><73><EFBFBD><EFBFBD>
{
aos_pool_t* p = NULL;
aos_string_t bucket;
aos_string_t object;
int is_cname = 0;
aos_table_t* headers = NULL;
aos_table_t* resp_headers = NULL;
oss_request_options_t* options = NULL;
aos_list_t buffer;
aos_buf_t* content = NULL;
char* str = data;
aos_status_t* s = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
headers = aos_table_make(p, 1);
apr_table_set(headers, "x-oss-meta-author", "oss");
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, File_Name);
aos_list_init(&buffer);
content = aos_buf_pack(options->pool, str, strlen(str));
aos_list_add_tail(&content->node, &buffer);
s = oss_put_object_from_buffer(options, &bucket, &object,
&buffer, headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("put object from buffer succeeded\n");
}
else {
printf("put object from buffer failed\n");
}
aos_pool_destroy(p);
}
void put_object_from_file()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
/* <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>CNAME<4D><45>0<EFBFBD><30>ʾ<EFBFBD><CABE>ʹ<EFBFBD>á<EFBFBD>*/
int is_cname = 0;
aos_table_t *headers = NULL;
aos_table_t *resp_headers = NULL;
oss_request_options_t *options = NULL;
char *filename = "/home/pq/FeProject/etc/Device_Config.xml";
aos_status_t *s = NULL;
aos_string_t file;
/* <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>أ<EFBFBD>pool<6F><6C><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>apr_pool_t<5F><74><EFBFBD><EFBFBD>ʵ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>apr<70><72><EFBFBD>С<EFBFBD>*/
aos_pool_create(&p, NULL);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>options<6E><73><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>endpoint<6E><74>access_key_id<69><64>acces_key_secret<65><74>is_cname<6D><65>curl<72><6C>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>*/
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, OBJECT_NAME);
aos_str_set(&file, filename);
s = oss_put_object_from_file(options, &bucket, &object, &file,
headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("put object from file succeeded\n");
}
else {
printf("put object from file failed, code:%d, error_code:%s, error_msg:%s, request_id:%s\n",
s->code, s->error_code, s->error_msg, s->req_id);
}
aos_pool_destroy(p);
}
void put_object_from_file_new(char* File_Name, char* path)
{
aos_pool_t* p = NULL;
aos_string_t bucket;
aos_string_t object;
/* <20>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>CNAME<4D><45>0<EFBFBD><30>ʾ<EFBFBD><CABE>ʹ<EFBFBD>á<EFBFBD>*/
int is_cname = 0;
aos_table_t* headers = NULL;
aos_table_t* resp_headers = NULL;
oss_request_options_t* options = NULL;
char* filename = path;
aos_status_t* s = NULL;
aos_string_t file;
/* <20><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>أ<EFBFBD>pool<6F><6C><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD>apr_pool_t<5F><74><EFBFBD><EFBFBD>ʵ<EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD>apr<70><72><EFBFBD>С<EFBFBD>*/
aos_pool_create(&p, NULL);
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>options<6E><73><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>endpoint<6E><74>access_key_id<69><64>acces_key_secret<65><74>is_cname<6D><65>curl<72><6C>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>*/
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, File_Name);
aos_str_set(&file, filename);
s = oss_put_object_from_file(options, &bucket, &object, &file,
headers, &resp_headers);
if (aos_status_is_ok(s)) {
printf("put object from file succeeded\n");
}
else {
printf("put object from file failed, code:%d, error_code:%s, error_msg:%s, request_id:%s\n",
s->code, s->error_code, s->error_msg, s->req_id);
}
aos_pool_destroy(p);
}
void get_object_to_buffer()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
int is_cname = 0;
oss_request_options_t *options = NULL;
aos_table_t *headers = NULL;
aos_table_t *params = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *s = NULL;
aos_list_t buffer;
aos_buf_t *content = NULL;
char *buf = NULL;
int64_t len = 0;
int64_t size = 0;
int64_t pos = 0;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, OBJECT_NAME);
aos_list_init(&buffer);
s = oss_get_object_to_buffer(options, &bucket, &object,
headers, params, &buffer, &resp_headers);
if (aos_status_is_ok(s)) {
printf("get object to buffer succeeded\n");
}
else {
printf("get object to buffer failed\n");
}
//get buffer len
aos_list_for_each_entry(aos_buf_t, content, &buffer, node) {
len += aos_buf_size(content);
}
buf = (char*)aos_pcalloc(p, (apr_size_t)(len + 1));
buf[len] = '\0';
//copy buffer content to memory
aos_list_for_each_entry(aos_buf_t, content, &buffer, node) {
size = aos_buf_size(content);
memcpy(buf + pos, content->pos, (size_t)size);
pos += size;
}
aos_pool_destroy(p);
}
void get_object_to_file()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
char *download_filename = "Data/tempbuff.jpg";
aos_string_t object;
int is_cname = 0;
oss_request_options_t *options = NULL;
aos_table_t *headers = NULL;
aos_table_t *params = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *s = NULL;
aos_string_t file;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, OBJECT_NAME);
headers = aos_table_make(p, 0);
aos_str_set(&file, download_filename);
s = oss_get_object_to_file(options, &bucket, &object, headers,
params, &file, &resp_headers);
if (aos_status_is_ok(s)) {
printf("get object to local file succeeded\n");
}
else {
printf("get object to local file failed\n");
}
aos_pool_destroy(p);
}
void get_object_to_file_new(char* File_Name,char* savepath)
{
aos_pool_t* p = NULL;
aos_string_t bucket;
char* download_filename = savepath;
aos_string_t object;
int is_cname = 0;
oss_request_options_t* options = NULL;
aos_table_t* headers = NULL;
aos_table_t* params = NULL;
aos_table_t* resp_headers = NULL;
aos_status_t* s = NULL;
aos_string_t file;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, File_Name);
headers = aos_table_make(p, 0);
aos_str_set(&file, download_filename);
s = oss_get_object_to_file(options, &bucket, &object, headers,
params, &file, &resp_headers);
if (aos_status_is_ok(s)) {
printf("get object to local file succeeded\n");
}
else {
printf("get object to local file failed\n");
}
aos_pool_destroy(p);
}
void delete_object()
{
aos_pool_t *p = NULL;
aos_string_t bucket;
aos_string_t object;
int is_cname = 0;
oss_request_options_t *options = NULL;
aos_table_t *resp_headers = NULL;
aos_status_t *s = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, OBJECT_NAME);
s = oss_delete_object(options, &bucket, &object, &resp_headers);
if (aos_status_is_ok(s)) {
printf("delete object succeed\n");
}
else {
printf("delete object failed\n");
}
aos_pool_destroy(p);
}
void delete_object_new(char* File_Name)
{
aos_pool_t* p = NULL;
aos_string_t bucket;
aos_string_t object;
int is_cname = 0;
oss_request_options_t* options = NULL;
aos_status_t* s = NULL;
aos_pool_create(&p, NULL);
options = oss_request_options_create(p);
init_sample_request_options(options, is_cname);
aos_str_set(&bucket, BUCKET_NAME);
aos_str_set(&object, File_Name);
s = oss_delete_objects_by_prefix(options, &bucket, &object);
if (aos_status_is_ok(s)) {
printf("delete object succeed\n");
}
else {
printf("delete object failed\n");
}
aos_pool_destroy(p);
}

319
cfg_parse/uds_huaweiyun.cpp Normal file

File diff suppressed because one or more lines are too long