Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge middleware into main #609

Merged
merged 33 commits into from
Oct 20, 2021

Conversation

ArnoStiefvater
Copy link
Member

What:

Why:

How:

Checklist:

  • Tests
  • PR merge commit message adjusted

ArnoStiefvater and others added 30 commits July 13, 2021 13:52
Remove feature guards.
Add function for single message publish.
Getters and setters.
Reset function.
Init mqtt_t on publish if mqtt_t is NULL.
Hide mqtt_t.
Fix mqtt_reset().
Merge Master into Middleware branch
[middleware] Add function for mqtt init status
To retrieve messages

1. mqtt_subscribe
1. mqtt_retrieve_message
1. mqtt_unsubscribe

are implemented.

Since at least in openvas most retrieving functionalities are done a in
request/response fashion `mqtt_retrieve_message` is written in a
blocking way instead of using the callback functionality of paho.

With that we have fine granular control over threads and processes and
can decide how we want to treat message retrieval in more abstract
libraries.

There is a small example on how to use the mqtt_* api retrieve
messages:

```
\#include <gvm/util/mqtt.h>
\#include <signal.h>
\#include <stdio.h>
\#include <stdlib.h>
\#define TOPIC "#"

void
signalhandler (int signum)
{
  printf ("Caught %d, reset mqtt\n", signum);
  mqtt_unsubscribe (TOPIC);
  mqtt_reset ();
  exit (0);
}

int
main ()
{
  signal (SIGINT, signalhandler);

  int rc;
  if ((rc = mqtt_init ("localhost:9138")) != 0)
    {
      printf ("init returned %d, quitting\n", rc);
      goto exit;
    }

  if ((rc = mqtt_subscribe (TOPIC)) != 0)
    {
      printf ("subscribe returned %d, quitting\n", rc);
      goto exit;
    }

  while (1)
    {
      char *topic;
      int topic_len;
      char *payload;
      int payload_len;
      if ((rc =
             mqtt_retrieve_message (&topic, &topic_len, &payload, &payload_len))
          == -1)
        {
          printf ("unable to retrieve message, quitting\n");
          goto exit;
        }
      if (rc == 0)
        printf ("[%d] Got message: %s on topic %s\n", payload_len,
                payload != NULL ? payload : "N/A",
                topic != NULL ? topic : "N/A");
      else
        rc = 0;
      if (payload != NULL)
        free (payload);
      if (topic != NULL)
        free (topic);
    }
exit:
  mqtt_unsubscribe (TOPIC);
  mqtt_reset ();
  return rc;
}
```

to compile it please install libgvm and build it via:

```
gcc $(pkg-config --cflags glib-2.0) main.c -lgvm_util -lgvm_base $(pkg-config --libs glib-2.0)
```
Because it is now handle as script preference.
The timeout is not stored under the redis key `nvt:<OID>` anymore.
The timeout must be get from script preferences.
It was currently not used by libs or scanner.
Handle script timeout as script preference
Avoid warning/error when the compiler uses the -Werror=strict-prototypes flag
@ArnoStiefvater ArnoStiefvater marked this pull request as ready for review October 19, 2021 11:53
@ArnoStiefvater ArnoStiefvater requested a review from a team as a code owner October 19, 2021 11:53
@ArnoStiefvater ArnoStiefvater merged commit 204273d into greenbone:main Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants