encode_content_type.c

Go to the documentation of this file.
00001 /* $Id: encode_content_type.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_content_type.c
00026  * 
00027  *     Description:  [en|de]code content type
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 <netinet/in.h>
00043 #include <string.h>
00044 #include "../../parser/parse_content.h"
00045 #include "encode_content_type.h"
00046 
00047 int encode_content_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where)
00048 {
00049    return encode_mime_type(hdrstart,hdrlen,bodi,where);
00050 }
00051 
00052 int print_encoded_content_type(FILE* fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
00053 {
00054    unsigned int type;
00055    memcpy(&type,payload,sizeof(unsigned int));
00056    return print_encoded_mime_type(fd,hdr,hdrlen,&type,paylen,prefix);
00057 }
00058 
00059 int encode_accept(char *hdrstart,int hdrlen,unsigned int *bodi,char *where)
00060 {
00061    int i;
00062 
00063    for(i=0;bodi[i]!=0;i++){
00064       encode_mime_type(hdrstart,hdrlen,bodi[i],&where[1+i*sizeof(unsigned int)]);
00065    }
00066    where[0]=(unsigned char)i;
00067 
00068    return 1+i*sizeof(unsigned int);
00069 }
00070 
00071 int print_encoded_accept(FILE* fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
00072 {
00073    int i;
00074    unsigned int type;
00075    for(i=0;i<payload[0];i++){
00076       memcpy(&type,&payload[1+i*sizeof(unsigned int)],sizeof(unsigned int));
00077       print_encoded_mime_type(fd,hdr,hdrlen,&type,4,prefix);
00078    }
00079    return 1;
00080 
00081 }
00082 
00083 int encode_mime_type(char *hdrstart,int hdrlen,unsigned int bodi,char *where)
00084 {
00085    unsigned int type;
00086 
00087    type=htonl(bodi);
00088    memcpy(where,&type,sizeof(unsigned int));
00089 
00090    return sizeof(int);
00091 }
00092 
00093 int print_encoded_mime_type(FILE *fd,char *hdr,int hdrlen,unsigned int* payload,int paylen,char *prefix)
00094 {
00095    unsigned int type;
00096    char *chtype,*chsubtype;
00097 
00098    type=ntohl(*payload);
00099 
00100    switch(type>>16){
00101       case TYPE_TEXT:
00102     chtype="text";
00103     break;
00104       case TYPE_MESSAGE:
00105     chtype="message";
00106     break;
00107       case TYPE_APPLICATION:
00108     chtype="application";
00109     break;
00110       case TYPE_MULTIPART:
00111     chtype="multipart";
00112     break;
00113       case TYPE_ALL:
00114     chtype="all";
00115     break;
00116       case TYPE_UNKNOWN:
00117     chtype="unknown";
00118     break;
00119       default:
00120    chtype="(didn't know this type existed)";
00121    break;
00122    }
00123 
00124    switch(type&0xFF){
00125       case SUBTYPE_PLAIN:
00126     chsubtype="SUBTYPE_PLAIN";
00127     break;
00128       case SUBTYPE_CPIM:
00129     chsubtype="SUBTYPE_CPIM";
00130     break;
00131       case SUBTYPE_SDP:
00132     chsubtype="SUBTYPE_SDP";
00133     break;
00134       case SUBTYPE_CPLXML:
00135     chsubtype="SUBTYPE_CPLXML";
00136     break;
00137       case SUBTYPE_PIDFXML:
00138     chsubtype="SUBTYPE_PIDFXML";
00139     break;
00140       case SUBTYPE_RLMIXML:
00141     chsubtype="SUBTYPE_RLMIXML";
00142     break;
00143       case SUBTYPE_RELATED:
00144     chsubtype="SUBTYPE_RELATED";
00145     break;
00146       case SUBTYPE_LPIDFXML:
00147     chsubtype="SUBTYPE_LPIDFXML";
00148     break;
00149       case SUBTYPE_XPIDFXML:
00150     chsubtype="SUBTYPE_XPIDFXML";
00151     break;
00152       case SUBTYPE_WATCHERINFOXML:
00153     chsubtype="SUBTYPE_WATCHERINFOXML";
00154     break;
00155       case SUBTYPE_EXTERNAL_BODY:
00156     chsubtype="SUBTYPE_EXTERNAL_BODY";
00157     break;
00158       case SUBTYPE_XML_MSRTC_PIDF:
00159     chsubtype="SUBTYPE_XML_MSRTC_PIDF";
00160     break;
00161       case SUBTYPE_ALL:
00162     chsubtype="SUBTYPE_ALL";
00163     break;
00164       case SUBTYPE_UNKNOWN:
00165     chsubtype="SUBTYPE_UNKNOWN";
00166     break;
00167       default:
00168     chsubtype="(didnt know this subtype existed)";
00169    }
00170 
00171    fprintf(fd,"%sTYPE:[%s]\n",prefix,chtype);
00172    fprintf(fd,"%sSUBTYPE:[%s]\n",prefix,chsubtype);
00173    return 0;
00174 }

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