13b6c3722Schristos /* 23b6c3722Schristos * pythonmod_utils.h: utils header file 33b6c3722Schristos * 43b6c3722Schristos * Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz) 53b6c3722Schristos * Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz) 63b6c3722Schristos * 73b6c3722Schristos * This software is open source. 83b6c3722Schristos * 93b6c3722Schristos * Redistribution and use in source and binary forms, with or without 103b6c3722Schristos * modification, are permitted provided that the following conditions 113b6c3722Schristos * are met: 123b6c3722Schristos * 133b6c3722Schristos * * Redistributions of source code must retain the above copyright notice, 143b6c3722Schristos * this list of conditions and the following disclaimer. 153b6c3722Schristos * 163b6c3722Schristos * * Redistributions in binary form must reproduce the above copyright notice, 173b6c3722Schristos * this list of conditions and the following disclaimer in the documentation 183b6c3722Schristos * and/or other materials provided with the distribution. 193b6c3722Schristos * 203b6c3722Schristos * * Neither the name of the organization nor the names of its 213b6c3722Schristos * contributors may be used to endorse or promote products derived from this 223b6c3722Schristos * software without specific prior written permission. 233b6c3722Schristos * 243b6c3722Schristos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 253b6c3722Schristos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 263b6c3722Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 273b6c3722Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 283b6c3722Schristos * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 293b6c3722Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 303b6c3722Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 313b6c3722Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 323b6c3722Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 333b6c3722Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 343b6c3722Schristos * POSSIBILITY OF SUCH DAMAGE. 353b6c3722Schristos */ 363b6c3722Schristos /** 373b6c3722Schristos * \file 383b6c3722Schristos * Utility functions for the python module that perform stores and loads and 393b6c3722Schristos * conversions. 403b6c3722Schristos */ 413b6c3722Schristos #ifndef PYTHONMOD_UTILS_H 423b6c3722Schristos #define PYTHONMOD_UTILS_H 433b6c3722Schristos 443b6c3722Schristos #include "util/module.h" 453b6c3722Schristos struct delegpt_addr; 46d0eba39bSchristos struct sldns_buffer; 473b6c3722Schristos 483b6c3722Schristos /** 49*7a540f2bSchristos * Store the reply_info and query_info pair in message cache 50*7a540f2bSchristos * (qstate->msg_cache). 513b6c3722Schristos * 523b6c3722Schristos * @param qstate: module environment 533b6c3722Schristos * @param qinfo: query info, the query for which answer is stored. 543b6c3722Schristos * @param msgrep: reply in dns_msg 553b6c3722Schristos * @param is_referral: If true, then the given message to be stored is a 563b6c3722Schristos * referral. The cache implementation may use this as a hint. 573b6c3722Schristos * It will store only the RRsets, not the message. 583b6c3722Schristos * @return 0 on alloc error (out of memory). 593b6c3722Schristos */ 60*7a540f2bSchristos int storeQueryInCache(struct module_qstate* qstate, struct query_info* qinfo, 61*7a540f2bSchristos struct reply_info* msgrep, int is_referral); 623b6c3722Schristos 633b6c3722Schristos 643b6c3722Schristos /** 653b6c3722Schristos * Invalidate the message associated with query_info stored in message cache. 663b6c3722Schristos * 67*7a540f2bSchristos * This function invalidates the record in message cache associated with the 68*7a540f2bSchristos * given query only if such a record exists. 693b6c3722Schristos * 703b6c3722Schristos * @param qstate: module environment 713b6c3722Schristos * @param qinfo: query info, the query for which answer is stored. 723b6c3722Schristos */ 73*7a540f2bSchristos void invalidateQueryInCache(struct module_qstate* qstate, 74*7a540f2bSchristos struct query_info* qinfo); 753b6c3722Schristos 763b6c3722Schristos /** 77*7a540f2bSchristos * Create response according to the ldns packet content. 783b6c3722Schristos * 793b6c3722Schristos * This function fills qstate.return_msg up with data of a given packet 803b6c3722Schristos * 813b6c3722Schristos * @param qstate: module environment 823b6c3722Schristos * @param pkt: a sldns_buffer which contains sldns_packet data 833b6c3722Schristos * @return 0 on failure, out of memory or parse error. 843b6c3722Schristos */ 85d0eba39bSchristos int createResponse(struct module_qstate* qstate, struct sldns_buffer* pkt); 863b6c3722Schristos 873b6c3722Schristos /** 88*7a540f2bSchristos * Convert reply->addr to string. 893b6c3722Schristos * @param reply: comm reply with address in it. 903b6c3722Schristos * @param dest: destination string. 913b6c3722Schristos * @param maxlen: length of string buffer. 923b6c3722Schristos */ 933b6c3722Schristos void reply_addr2str(struct comm_reply* reply, char* dest, int maxlen); 943b6c3722Schristos 95*7a540f2bSchristos /** 96*7a540f2bSchristos * Convert target->addr to string. 97*7a540f2bSchristos * @param target: delegpt_addr with address in it. 98*7a540f2bSchristos * @param dest: destination string. 99*7a540f2bSchristos * @param maxlen: length of string buffer. 100*7a540f2bSchristos */ 101*7a540f2bSchristos void delegpt_addr_addr2str(struct delegpt_addr* target, char *dest, 102*7a540f2bSchristos int maxlen); 1033b6c3722Schristos 1043b6c3722Schristos #endif /* PYTHONMOD_UTILS_H */ 105