00001 /* $Id: encode_expires.c 5192 2008-11-13 10:18:48Z eliasbaixas $ 00002 * 00003 * Copyright (C) 2006-2007 VozTelecom Sistemas S.L 00004 * 00005 * This file is part of Kamailio, a free SIP server. 00006 * 00007 * Kamailio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version 00011 * 00012 * Kamailio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 /* 00023 * ===================================================================================== 00024 * 00025 * Filename: encode_expires.c 00026 * 00027 * Description: functions to [en|de]code expires header 00028 * 00029 * Version: 1.0 00030 * Created: 22/11/05 00:05:54 CET 00031 * Revision: none 00032 * Compiler: gcc 00033 * 00034 * Author: Elias Baixas (EB), elias@conillera.net 00035 * Company: VozTele.com 00036 * 00037 * ===================================================================================== 00038 */ 00039 00040 #define _GNU_SOURCE 00041 #include <stdio.h> 00042 #include <netinet/in.h> 00043 #include <string.h> 00044 #include "../../parser/parse_expires.h" 00045 00046 /* 00047 * Encodes expires headers (content = delta-seconds) 00048 * 4: network-byte-order value 00049 * 2: hdr-based pointer to begin of value string + value string length 00050 */ 00051 int encode_expires(char *hdrstart,int hdrlen,exp_body_t *body,unsigned char *where) 00052 { 00053 int i; 00054 00055 i=htonl(body->val); 00056 memcpy(where,&i,4); 00057 where[4]=(unsigned char)(body->text.s-hdrstart); 00058 where[5]=(unsigned char)(body->text.len); 00059 return 6; 00060 } 00061 00062 int print_encoded_expires(FILE *fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix) 00063 { 00064 int i; 00065 memcpy(&i,payload,4); 00066 i=ntohl(i); 00067 fprintf(fd,"%sEXPIRES VALUE=%d==%.*s\n",prefix,i,payload[5],&hdr[payload[4]]); 00068 return 1; 00069 } 00070 00071
1.5.6