Loading plugins/media/backend.h +3 −0 Original line number Diff line number Diff line Loading @@ -45,7 +45,10 @@ namespace blogi { void save(const std::string key,const std::vector<char> value) override; void load(const std::string key,std::vector<char> &value) override; private: void _reconnect(); redisContext *_RedisCTX; std::string _host; int _port; std::string _pw; }; }; plugins/media/media.cpp +10 −26 Original line number Diff line number Diff line Loading @@ -238,17 +238,8 @@ namespace blogi { Args->database->exec(&sql,res); sql.clear(); try{ _store->save(cfuuid,mediafile); }catch(libhttppp::HTTPException &e){ if(Args->config->getRedisPassword()){ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort(),Args->config->getRedisPassword()); }else{ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort()); } throw e; } } Loading Loading @@ -550,7 +541,7 @@ namespace blogi { libhttppp::HttpResponse curres; curres.setVersion(HTTPVERSION(1.1)); std::vector<char> value; try{ if(n>0){ _store->load(suuid,value); curres.setContentType(res[0][0]); Loading @@ -559,14 +550,7 @@ namespace blogi { curres.setState(HTTP404); curres.send(req,nullptr,0); } }catch(libhttppp::HTTPException &e){ if(Args->config->getRedisPassword()){ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort(),Args->config->getRedisPassword()); }else{ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort()); } throw e; } curres.send(req, value.data(), value.size()); return true; Loading plugins/media/redis.cpp +34 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ #include "backend.h" blogi::RedisStore::RedisStore(const char *host,int port,const char *password){ _host=host; _port=port; _RedisCTX=redisConnect(host,port); if (_RedisCTX->err) { Loading @@ -41,21 +43,25 @@ blogi::RedisStore::RedisStore(const char *host,int port,const char *password){ } if(password){ _pw=password; redisReply *reply = (redisReply*)redisCommand(_RedisCTX, "AUTH %s", password); if (reply->type == REDIS_REPLY_ERROR) { libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; } _pw=password; freeReplyObject(reply); } } void blogi::RedisStore::save(const std::string key, const std::vector<char> value){ libhttppp::HTTPException exp; redisReply* reply = (redisReply*) redisCommand(_RedisCTX,"SET %s %b",key.c_str(),value.data(),value.size()); if (reply && reply->type==REDIS_REPLY_ERROR) { _reconnect(); freeReplyObject(reply); libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; Loading @@ -64,6 +70,9 @@ void blogi::RedisStore::save(const std::string key, const std::vector<char> valu freeReplyObject(reply); reply = (redisReply*) redisCommand(_RedisCTX, "save"); if (reply && reply->type==REDIS_REPLY_ERROR) { _reconnect(); freeReplyObject(reply); libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; Loading @@ -77,6 +86,29 @@ void blogi::RedisStore::load(const std::string key,std::vector<char> &value) { std::copy(reply->str,reply->str+reply->len,std::inserter<std::vector<char>>(value,value.begin())); }else{ freeReplyObject(reply); _reconnect(); libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; } freeReplyObject(reply); } void blogi::RedisStore::_reconnect(){ _RedisCTX=redisConnect(_host.c_str(),_port); if (_RedisCTX->err) { libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; } if(!_pw.empty()){ redisReply *reply = (redisReply*)redisCommand(_RedisCTX, "AUTH %s", _pw.c_str()); if (reply->type == REDIS_REPLY_ERROR) { libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; Loading @@ -84,3 +116,4 @@ void blogi::RedisStore::load(const std::string key,std::vector<char> &value) { freeReplyObject(reply); } } Loading
plugins/media/backend.h +3 −0 Original line number Diff line number Diff line Loading @@ -45,7 +45,10 @@ namespace blogi { void save(const std::string key,const std::vector<char> value) override; void load(const std::string key,std::vector<char> &value) override; private: void _reconnect(); redisContext *_RedisCTX; std::string _host; int _port; std::string _pw; }; };
plugins/media/media.cpp +10 −26 Original line number Diff line number Diff line Loading @@ -238,17 +238,8 @@ namespace blogi { Args->database->exec(&sql,res); sql.clear(); try{ _store->save(cfuuid,mediafile); }catch(libhttppp::HTTPException &e){ if(Args->config->getRedisPassword()){ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort(),Args->config->getRedisPassword()); }else{ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort()); } throw e; } } Loading Loading @@ -550,7 +541,7 @@ namespace blogi { libhttppp::HttpResponse curres; curres.setVersion(HTTPVERSION(1.1)); std::vector<char> value; try{ if(n>0){ _store->load(suuid,value); curres.setContentType(res[0][0]); Loading @@ -559,14 +550,7 @@ namespace blogi { curres.setState(HTTP404); curres.send(req,nullptr,0); } }catch(libhttppp::HTTPException &e){ if(Args->config->getRedisPassword()){ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort(),Args->config->getRedisPassword()); }else{ _store = new RedisStore(Args->config->getRedisHost(),Args->config->getRedisPort()); } throw e; } curres.send(req, value.data(), value.size()); return true; Loading
plugins/media/redis.cpp +34 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,8 @@ #include "backend.h" blogi::RedisStore::RedisStore(const char *host,int port,const char *password){ _host=host; _port=port; _RedisCTX=redisConnect(host,port); if (_RedisCTX->err) { Loading @@ -41,21 +43,25 @@ blogi::RedisStore::RedisStore(const char *host,int port,const char *password){ } if(password){ _pw=password; redisReply *reply = (redisReply*)redisCommand(_RedisCTX, "AUTH %s", password); if (reply->type == REDIS_REPLY_ERROR) { libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; } _pw=password; freeReplyObject(reply); } } void blogi::RedisStore::save(const std::string key, const std::vector<char> value){ libhttppp::HTTPException exp; redisReply* reply = (redisReply*) redisCommand(_RedisCTX,"SET %s %b",key.c_str(),value.data(),value.size()); if (reply && reply->type==REDIS_REPLY_ERROR) { _reconnect(); freeReplyObject(reply); libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; Loading @@ -64,6 +70,9 @@ void blogi::RedisStore::save(const std::string key, const std::vector<char> valu freeReplyObject(reply); reply = (redisReply*) redisCommand(_RedisCTX, "save"); if (reply && reply->type==REDIS_REPLY_ERROR) { _reconnect(); freeReplyObject(reply); libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; Loading @@ -77,6 +86,29 @@ void blogi::RedisStore::load(const std::string key,std::vector<char> &value) { std::copy(reply->str,reply->str+reply->len,std::inserter<std::vector<char>>(value,value.begin())); }else{ freeReplyObject(reply); _reconnect(); libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; } freeReplyObject(reply); } void blogi::RedisStore::_reconnect(){ _RedisCTX=redisConnect(_host.c_str(),_port); if (_RedisCTX->err) { libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; } if(!_pw.empty()){ redisReply *reply = (redisReply*)redisCommand(_RedisCTX, "AUTH %s", _pw.c_str()); if (reply->type == REDIS_REPLY_ERROR) { libhttppp::HTTPException exp; exp[libhttppp::HTTPException::Error] << "media plugin err: " << _RedisCTX->errstr; throw exp; Loading @@ -84,3 +116,4 @@ void blogi::RedisStore::load(const std::string key,std::vector<char> &value) { freeReplyObject(reply); } }