@@ -36,8 +36,6 @@ limitations under the License.
3636#include < libsinsp/plugin_filtercheck.h>
3737#include < libscap/strl.h>
3838
39- using namespace std ;
40-
4139static constexpr const char * s_not_init_err = " plugin capability used before init" ;
4240
4341static constexpr const char * s_init_twice_err = " plugin has been initialized twice" ;
@@ -147,7 +145,7 @@ bool sinsp_plugin::init(const std::string& config, std::string& errstr) {
147145 }
148146
149147 if (!m_handle->api .init ) {
150- errstr = string (" init api symbol not found" );
148+ errstr = std:: string (" init api symbol not found" );
151149 return false ;
152150 }
153151
@@ -250,8 +248,8 @@ void sinsp_plugin::resolve_dylib_field_arg(Json::Value root, filtercheck_field_i
250248 const Json::Value& isRequired = root.get (" isRequired" , Json::Value::null);
251249 if (!isRequired.isNull ()) {
252250 if (!isRequired.isBool ()) {
253- throw sinsp_exception (string (" error in plugin " ) + m_name + " : field " + tf. m_name +
254- " isRequired property is not boolean" );
251+ throw sinsp_exception (std:: string (" error in plugin " ) + m_name + " : field " +
252+ tf. m_name + " isRequired property is not boolean" );
255253 }
256254
257255 if (isRequired.asBool () == true ) {
@@ -265,8 +263,8 @@ void sinsp_plugin::resolve_dylib_field_arg(Json::Value root, filtercheck_field_i
265263 const Json::Value& isIndex = root.get (" isIndex" , Json::Value::null);
266264 if (!isIndex.isNull ()) {
267265 if (!isIndex.isBool ()) {
268- throw sinsp_exception (string (" error in plugin " ) + m_name + " : field " + tf. m_name +
269- " isIndex property is not boolean" );
266+ throw sinsp_exception (std:: string (" error in plugin " ) + m_name + " : field " +
267+ tf. m_name + " isIndex property is not boolean" );
270268 }
271269
272270 if (isIndex.asBool () == true ) {
@@ -281,8 +279,8 @@ void sinsp_plugin::resolve_dylib_field_arg(Json::Value root, filtercheck_field_i
281279 const Json::Value& isKey = root.get (" isKey" , Json::Value::null);
282280 if (!isKey.isNull ()) {
283281 if (!isKey.isBool ()) {
284- throw sinsp_exception (string (" error in plugin " ) + m_name + " : field " + tf. m_name +
285- " isKey property is not boolean" );
282+ throw sinsp_exception (std:: string (" error in plugin " ) + m_name + " : field " +
283+ tf. m_name + " isKey property is not boolean" );
286284 }
287285
288286 if (isKey.asBool () == true ) {
@@ -297,7 +295,7 @@ void sinsp_plugin::resolve_dylib_field_arg(Json::Value root, filtercheck_field_i
297295 if ((tf.m_flags & filtercheck_field_flags::EPF_ARG_REQUIRED) &&
298296 !(tf.m_flags & filtercheck_field_flags::EPF_ARG_INDEX ||
299297 tf.m_flags & filtercheck_field_flags::EPF_ARG_KEY)) {
300- throw sinsp_exception (string (" error in plugin " ) + m_name + " : field " + tf.m_name +
298+ throw sinsp_exception (std:: string (" error in plugin " ) + m_name + " : field " + tf.m_name +
301299 " arg has isRequired true, but none of isKey nor isIndex is true" );
302300 }
303301 return ;
@@ -447,14 +445,14 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string& errstr) {
447445 //
448446 const char * sfields = m_handle->api .get_fields ();
449447 if (sfields == NULL ) {
450- throw sinsp_exception (string (" error in plugin " ) + name () +
448+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
451449 " : get_fields returned a null string" );
452450 }
453- string json (sfields);
451+ std:: string json (sfields);
454452
455453 Json::Value root;
456454 if (Json::Reader ().parse (json, root) == false || root.type () != Json::arrayValue) {
457- throw sinsp_exception (string (" error in plugin " ) + name () +
455+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
458456 " : get_fields returned an invalid JSON" );
459457 }
460458
@@ -466,23 +464,23 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string& errstr) {
466464 tf.m_flags = EPF_NO_PTR_STABILITY;
467465
468466 const Json::Value& jvtype = root[j][" type" ];
469- string ftype = jvtype.asString ();
467+ std:: string ftype = jvtype.asString ();
470468 if (ftype == " " ) {
471- throw sinsp_exception (string (" error in plugin " ) + name () +
469+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
472470 " : field JSON entry has no type" );
473471 }
474472 const Json::Value& jvname = root[j][" name" ];
475- string fname = jvname.asString ();
473+ std:: string fname = jvname.asString ();
476474 if (fname == " " ) {
477- throw sinsp_exception (string (" error in plugin " ) + name () +
475+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
478476 " : field JSON entry has no name" );
479477 }
480478 const Json::Value& jvdisplay = root[j][" display" ];
481- string fdisplay = jvdisplay.asString ();
479+ std:: string fdisplay = jvdisplay.asString ();
482480 const Json::Value& jvdesc = root[j][" desc" ];
483- string fdesc = jvdesc.asString ();
481+ std:: string fdesc = jvdesc.asString ();
484482 if (fdesc == " " ) {
485- throw sinsp_exception (string (" error in plugin " ) + name () +
483+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
486484 " : field JSON entry has no desc" );
487485 }
488486
@@ -493,15 +491,15 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string& errstr) {
493491 if (s_pt_lut.find (ftype) != s_pt_lut.end ()) {
494492 tf.m_type = s_pt_lut.at (ftype);
495493 } else {
496- throw sinsp_exception (string (" error in plugin " ) + name () +
494+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
497495 " : invalid field type " + ftype);
498496 }
499497
500498 const Json::Value& jvIsList = root[j].get (" isList" , Json::Value::null);
501499 if (!jvIsList.isNull ()) {
502500 if (!jvIsList.isBool ()) {
503- throw sinsp_exception (string (" error in plugin " ) + name () + " : field " + fname +
504- " isList property is not boolean " );
501+ throw sinsp_exception (std:: string (" error in plugin " ) + name () + " : field " +
502+ fname + " isList property is not boolean " );
505503 }
506504
507505 if (jvIsList.asBool ()) {
@@ -514,8 +512,8 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string& errstr) {
514512 const Json::Value& jvoutput = root[j].get (" addOutput" , Json::Value::null);
515513 if (!jvoutput.isNull ()) {
516514 if (!jvoutput.isBool ()) {
517- throw sinsp_exception (string (" error in plugin " ) + name () + " : field " + fname +
518- " addOutput property is not boolean " );
515+ throw sinsp_exception (std:: string (" error in plugin " ) + name () + " : field " +
516+ fname + " addOutput property is not boolean " );
519517 }
520518
521519 if (jvoutput.asBool ()) {
@@ -530,14 +528,15 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string& errstr) {
530528 const Json::Value& jvProperties = root[j].get (" properties" , Json::Value::null);
531529 if (!jvProperties.isNull ()) {
532530 if (!jvProperties.isArray ()) {
533- throw sinsp_exception (string (" error in plugin " ) + name () + " : field " + fname +
534- " properties property is not array " );
531+ throw sinsp_exception (std:: string (" error in plugin " ) + name () + " : field " +
532+ fname + " properties property is not array " );
535533 }
536534
537535 for (const auto & prop : jvProperties) {
538536 if (!prop.isString ()) {
539- throw sinsp_exception (string (" error in plugin " ) + name () + " : field " +
540- fname + " properties value is not string " );
537+ throw sinsp_exception (std::string (" error in plugin " ) + name () +
538+ " : field " + fname +
539+ " properties value is not string " );
541540 }
542541
543542 const std::string& str = prop.asString ();
@@ -564,12 +563,12 @@ bool sinsp_plugin::resolve_dylib_symbols(std::string& errstr) {
564563 auto fields_size = m_fields.size ();
565564 if (fields_size == 0 ) {
566565 throw sinsp_exception (
567- string (" error in plugin " ) + name () +
566+ std:: string (" error in plugin " ) + name () +
568567 " : plugins with extraction capability must export at least one field" );
569568 }
570569
571570 // populate fields info
572- m_fields_info.m_name = name () + string (" (plugin)" );
571+ m_fields_info.m_name = name () + std:: string (" (plugin)" );
573572 m_fields_info.m_fields = &m_fields[0 ];
574573 m_fields_info.m_nfields = fields_size;
575574 m_fields_info.m_flags = filter_check_info::FL_NONE;
@@ -715,17 +714,17 @@ void sinsp_plugin::validate_config(std::string& config) {
715714 break ;
716715 default :
717716 ASSERT (false );
718- throw sinsp_exception (string (" error in plugin " ) + name () +
717+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
719718 " : get_init_schema returned an unknown schema type " +
720- to_string (schema_type));
719+ std:: to_string (schema_type));
721720 }
722721 }
723722}
724723
725724void sinsp_plugin::validate_config_json_schema (std::string& config, std::string& schema) {
726725 Json::Value schemaJson;
727726 if (!Json::Reader ().parse (schema, schemaJson) || schemaJson.type () != Json::objectValue) {
728- throw sinsp_exception (string (" error in plugin " ) + name () +
727+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
729728 " : get_init_schema did not return a json object" );
730729 }
731730
@@ -735,7 +734,7 @@ void sinsp_plugin::validate_config_json_schema(std::string& config, std::string&
735734 }
736735 Json::Value configJson;
737736 if (!Json::Reader ().parse (config, configJson)) {
738- throw sinsp_exception (string (" error in plugin " ) + name () +
737+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
739738 " : init config is not a valid json" );
740739 }
741740
@@ -752,12 +751,12 @@ void sinsp_plugin::validate_config_json_schema(std::string& config, std::string&
752751 // report only the top-most error
753752 if (validationResults.popError (error)) {
754753 throw sinsp_exception (
755- string (" error in plugin " ) + name () + " init config: In " +
754+ std:: string (" error in plugin " ) + name () + " init config: In " +
756755 std::accumulate (error.context .begin (), error.context .end (), std::string (" " )) +
757756 " , " + error.description );
758757 }
759758 // validation failed with no specific error
760- throw sinsp_exception (string (" error in plugin " ) + name () +
759+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
761760 " init config: failed parsing with provided schema" );
762761 }
763762}
@@ -995,7 +994,7 @@ std::string sinsp_plugin::event_to_string(sinsp_evt* evt) const {
995994 throw sinsp_exception (" can't format unknown non-plugin event to string" );
996995 }
997996
998- string ret = " " ;
997+ std:: string ret = " " ;
999998 const auto data_param = evt->get_param (1 );
1000999 const auto data = data_param->data ();
10011000 const auto data_len = data_param->len ();
@@ -1032,23 +1031,24 @@ std::vector<sinsp_plugin::open_param> sinsp_plugin::list_open_params() const {
10321031 std::vector<sinsp_plugin::open_param> list;
10331032 if (m_state && m_handle->api .list_open_params ) {
10341033 ss_plugin_rc rc;
1035- string jsonString = str_from_alloc_charbuf (m_handle->api .list_open_params (m_state, &rc));
1034+ std::string jsonString =
1035+ str_from_alloc_charbuf (m_handle->api .list_open_params (m_state, &rc));
10361036 if (rc != SS_PLUGIN_SUCCESS) {
1037- throw sinsp_exception (string (" error in plugin " ) + name () +
1037+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
10381038 " : list_open_params has error " + get_last_error ());
10391039 }
10401040
10411041 if (jsonString.size () > 0 ) {
10421042 Json::Value root;
10431043 if (Json::Reader ().parse (jsonString, root) == false || root.type () != Json::arrayValue) {
1044- throw sinsp_exception (string (" error in plugin " ) + name () +
1044+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
10451045 " : list_open_params returned a non-array JSON" );
10461046 }
10471047 for (Json::Value::ArrayIndex i = 0 ; i < root.size (); i++) {
10481048 open_param param;
10491049 param.value = root[i][" value" ].asString ();
10501050 if (param.value == " " ) {
1051- throw sinsp_exception (string (" error in plugin " ) + name () +
1051+ throw sinsp_exception (std:: string (" error in plugin " ) + name () +
10521052 " : list_open_params has entry with no value" );
10531053 }
10541054 param.desc = root[i][" desc" ].asString ();
0 commit comments