/*
* Copyright 2010 Nathan Phillip Brink
*
* This file is a part of DistRen.
*
* DistRen is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DistRen 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with DistRen. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _DISTREN_REQUEST_H
#define _DISTREN_REQUEST_H
#include "common/protocol.h"
/**
* @file functions to initialize various requests that the server and
* client may both use.
*/
/**
* Free any request made with one of the functions below
*/
int distren_request_free_with_data(struct distren_request *req, void *data);
/**
* Initialize a VERSION request.
*
* @param req pointer to where the poitner to the new req should be stored..
* @param data pointer to where the newly allocated data's address should go.
* @param servertype the ORing of different DISTREN_SERVERTYPE_* constants.
* @param package_string the PACKAGE_STRING constant.
*/
int distren_request_version(struct distren_request **req, void **data, uint32_t servertype, const char *package_string);
/**
* Parses a DISTREN_REQUEST_VERSION packet.
*
* @param req the request to parse.
* @param data the request's data.
* @param version where the result should be stored.
* @return 0 on success, 1 if the packet is invalid (if the length of package_version is longer than 32-bytes, for example).
*/
int distren_request_parse_version(struct distren_request *req, void *data, struct distren_request_version *version);
/**
* Initialize a PING or PONG request.
*
* @param data a place to allocate storage for the data associated with this request
* @param is_ping 1 if this is a DISTREN_REQUEST_PING or 0 if this is a DISTREN_REQUEST_PONG
* @param poing_cookie chocolate chip, chocolate chunk, or oatmeal chocolate chip
* @param poing_data_len bytes in the poing_cookie
* @return the length of the data allocated for this request
*/
uint32_t distren_request_poing(struct distren_request **req, void **data, short is_ping, const void *poing_cookie, size_t poing_data_len);
#endif /* _DISTREN_REQUEST_H */