encode_allow.c

Go to the documentation of this file.
00001 /* $Id: encode_allow.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_allow.c
00026  * 
00027  *     Description:  [en|de]code allow header
00028  * 
00029  *         Version:  1.0
00030  *         Created:  21/11/05 20:40:25 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 <string.h>
00043 #include <netinet/in.h>
00044 #include <arpa/inet.h>
00045 #include "../../parser/parse_allow.h"
00046 #include "../../parser/msg_parser.h"
00047 #include "encode_allow.h"
00048 
00049 char *mismetodos[]={"UNDEF","INVITE","CANCEL","ACK","BYE","INFO","OPTIONS","UPDATE","REGISTER","MESSAGE","SUBSCRIBE","NOTIFY","PRACK","REFER","OTHER"};
00050 
00051 /**
00052  * Encodes allow header.
00053  *
00054  * TODO: Does not support the UNDEFINED header type !!!
00055  */
00056 int encode_allow(char *hdrstart,int hdrlen,unsigned int *bodi,char *where)
00057 {
00058    unsigned int i;
00059    memcpy(&i,bodi,4);
00060    i=htonl(i);
00061    memcpy(where,&i,4);
00062    return 4;
00063 }
00064 
00065 int print_encoded_allow(FILE *fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
00066 {
00067    unsigned int i,j=0,body;
00068 
00069    memcpy(&body,payload,4);
00070    body=ntohl(body);
00071    fprintf(fd,"%sMETHODS=",prefix);
00072    if(body==0)
00073       fprintf(fd,"UNKNOWN");
00074    for(i=0;i<32;j=(0x01<<i),i++){
00075       if(body & (j<15))
00076     fprintf(fd,",%s",mismetodos[i]);
00077    }
00078    fprintf(fd,"\n");
00079    return 1;
00080 }

Generated on Tue May 22 16:00:27 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6