Unverified Commit c2ce6f58 authored by Shawn Webb's avatar Shawn Webb
Browse files

Abstract the message priority sanity checking



We needs this sanity checking in multiple places, so create a new
function internal to libpushover: `pushover_message_priority_sane`.
Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
parent 238bfc88
SHLIB= pushover
SHLIB_MAJOR= 0
SRCS= libpushover.c
SRCS= libpushover.c sanity.c
INCS= libpushover.h
CFLAGS+= -I${.CURDIR} -I/usr/local/include
......
......@@ -197,19 +197,7 @@ pushover_message_set_priority(pushover_message_t *msg,
assert(msg != NULL);
switch (prio) {
case PSH_PRIO_NONE:
case PSH_PRIO_QUIET:
case PSH_PRIO_DEF:
case PSH_PRIO_HIGH:
case PSH_PRIO_CONFIRM:
msg->psh_priority = prio;
break;
default:
return (false);
}
return (true);
return (pushover_message_priority_sane(msg->psh_priority));
}
EXPORTED_SYM
......@@ -226,6 +214,7 @@ pushover_submit_message(pushover_ctx_t *ctx, pushover_message_t *msg)
assert(ctx->psh_token != NULL);
assert(msg->psh_user != NULL);
assert(msg->psh_msg != NULL);
assert(pushover_message_priority_sane(msg->psh_priority));
res = false;
......@@ -236,10 +225,8 @@ pushover_submit_message(pushover_ctx_t *ctx, pushover_message_t *msg)
curl_easy_setopt(curl, CURLOPT_URL, ctx->psh_uri);
post_str = msg_to_str(ctx, msg, curl);
if (post_str == NULL) {
res = false;
if (post_str == NULL)
goto end;
}
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_str);
curl_code = curl_easy_perform(curl);
......
......@@ -47,4 +47,6 @@ bool pushover_message_set_priority(pushover_message_t *,
pushover_priority_t);
bool pushover_submit_message(pushover_ctx_t *, pushover_message_t *);
bool pushover_message_priority_sane(pushover_priority_t);
#endif /* !_LIBPUSHOVER_H */
/*-
* Copyright (c) 2020 HardenedBSD Foundation Corp.
* Author: Shawn Webb <shawn.webb@hardenedbsd.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libpushover.h"
bool
pushover_message_priority_sane(pushover_priority_t prio)
{
switch (prio) {
case PSH_PRIO_NONE:
case PSH_PRIO_QUIET:
case PSH_PRIO_DEF:
case PSH_PRIO_HIGH:
case PSH_PRIO_CONFIRM:
return (true);
default:
return (false);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment