text: #include "midms-common.h"
  #include <jwt.h>
  #include <errno.h>
  #include <unistd.h>
  
  /* --------------------------------------------------------------------------
   * ---- OPTIONS -------------------------------------------------------------
   * -------------------------------------------------------------------------- */
  
  WEAK cstr *MIDMS_JWT_DOMAIN_EVAR = "MIDMS_JWT_DOMAIN";
  WEAK ok midms_common_get_domain (cstr **out) {
      static char *domain = NULL; char *e;
      if (domain) {
          
      } else if ((e = getenv(MIDMS_JWT_DOMAIN_EVAR))) {
          domain = strdup(e);
          if (domain == NULL) {
              return ERR("Can't allocate memory: %s", strerror(errno));
          }
      } else {
          e = malloc(256);
          if (e == NULL) {
              return ERR("Can't allocate memory: %s", strerror(errno));
          }
          if (gethostname(e, 255) == -1) {
              free(e);
              return ERR("Can't allocate memory: %s", strerror(errno));
          }
          e[255] = '\0';
          domain = e;
      }
      *out = domain;
      return true;
  }
  
  
  /* --------------------------------------------------------------------------
   * ---- FUNCTIONS -----------------------------------------------------------
   * -------------------------------------------------------------------------- */
  
  WEAK void jwt_set (jwt *jwt, cstr key[], cstr val[]) {
      jwt_add_grant(jwt, key, val);
  }
  WEAK ok jwt_get (jwt *jwt, cstr key[], cstr **val) {
      cstr *s = jwt_get_grant(jwt, key);
      if (!s) {
          return ERR("No `%s` field in JWT", key);
      }
      *val = s;
      return true;
  }
  WEAK ok jwt_print (jwt *jwt, char **out) {
      *out = jwt_encode_str(jwt);
      if (*out == NULL) {
          return ERR("Failed encoding the JWT : %s", strerror(errno));
      }
      return true;
  }
  