/* * This file is part of uIRC. (https://git.redxen.eu/caskd/uIRC) * Copyright (c) 2019, 2020 Alex-David Denes * * uIRC is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * uIRC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with uIRC. If not, see . */ #include "../errors.h" // ERR_UIRC_* #include "../types.h" // IRC_Tag #include "assemblers.h" // Assm_user() #include // assert() #include // bool #include // size_t #include // NULL signed long uirc_assembler_tag(char* buf, const IRC_Tag* t, size_t len) { assert(buf != NULL); assert(t != NULL); assert(t->key != NULL); char* const sv = buf; int res; if (t->clientbound) { if (len > 1) { *(buf++) = '+'; len--; } else return UIRC_ERR_BUFFER_FULL; } if (len < 1) return UIRC_ERR_BUFFER_FULL; if ((res = snprintf(buf, len, "%s", t->key)) >= 0) { buf += (size_t) res; len -= (size_t) res; } else return UIRC_ERR_BUFFER_ERR; if (t->value != NULL) { if (len < 1) return UIRC_ERR_BUFFER_FULL; if ((res = snprintf(buf, len, "=%s", t->value)) >= 0) { buf += (size_t) res; len -= (size_t) res; } else return UIRC_ERR_BUFFER_ERR; } return buf - sv; }