/**
 * EscalateModuleHandleNext:
 * @self: PAM module that's receiving messages from the helper process.
 * @error: (out)(allow-none): Error return location or #NULL.
 *
 * Returns: #TRUE if a message was read and handled without an error.
 */
gboolean EscalateModuleHandleNext(EscalateModule *self, GError **error) {
  EscalateMessage *message = NULL;
  gboolean result = FALSE;

  message = EscalateSubprocessRecv(self->child, error);
  if (!message)
    goto done;

  switch (EscalateMessageGetType(message)) {
    case ESCALATE_MESSAGE_TYPE_CONV_MESSAGE:
      result = EscalateModuleHandleConversation(self, message, error);
      break;
    case ESCALATE_MESSAGE_TYPE_FINISH:
      result = EscalateModuleHandleFinish(self, message, error);
      break;
    default:
      g_set_error(error, ESCALATE_MODULE_ERROR,
                  ESCALATE_MODULE_ERROR_MESSAGE_TYPE,
                  "Unexpected message type: %d",
                  EscalateMessageGetType(message));
      break;
  }

done:
  if (message)
    EscalateMessageUnref(message);
  return result;
}
/**
 * EscalateHelperRecv:
 * @self: #EscalateHelper instance.
 * @type: Only accept a message with this type.
 * @error: (out)(allow-none): Error return location or #NULL.
 *
 * Returns: New #EscalateMessage instance, or #NULL on error.
 */
static EscalateMessage *EscalateHelperRecv(EscalateHelper *self,
                                           EscalateMessageType type,
                                           GError **error) {
  EscalateMessage *message = EscalateMessageRead(self->reader, error);
  if (!message)
    return NULL;

  if (EscalateMessageGetType(message) == type)
    return message;

  g_set_error(error, ESCALATE_HELPER_ERROR,
              ESCALATE_HELPER_ERROR_UNEXPECTED_MESSAGE_TYPE,
              "Expected message type %d but got %d instead", type,
              EscalateMessageGetType(message));
  EscalateMessageUnref(message);
  return NULL;
}