李国帅 编于2006-7-10 14:22
1、头文件osip_accept.h
--------------------
/*
版权声明
*/
#ifndef _OSIP_ACCEPT_H_------------------------------------唯一性标示
#define _OSIP_ACCEPT_H_
#include <osipparser2/headers/osip_content_type.h>----------包含的其他头文件
/**
* @file osip_accept.h--------------------------------------头文件名称
* @brief oSIP osip_accept header definition.---------------头文件说明
*/
/**
* @defgroup oSIP_ACCEPT oSIP accept header definition.-----定义宏
* @ingroup oSIP_HEADERS------------------------------------包含关系
* @{
*/
/**
* Structure for accept headers.----------------typedef结构体含义
* @var osip_accept_t---------------------------变量
*/
typedef osip_content_type_t osip_accept_t;
#ifdef __cplusplus------------------------------编译器适应
extern "C"
{
#endif
/**
* Allocate an Accept element.-----------------函数定义功能
* @param header The element to work on.-------参数说明
*/
#define accept_init(header) osip_content_type_init(header)-函数声明
/**
* Get a string representation of an Accept element.
* @param header The element to work on.
* @param dest A pointer on the new allocated string.
*/
int osip_accept_to_str(const osip_accept_t * header, char **dest);
#ifdef __cplusplus------------------------------编译器适应
}
#endif
/** @} */
#endif
|
----------------------
2、定义文件
/*
版权说明
*/
#include <stdlib.h>//------------系统头文件
#include <stdio.h>
#include <osipparser2/osip_port.h>//---------自定义头文件
/* returns the content_type header as a string. *///------------函数功能
/* INPUT : osip_content_type_t *content_type | content_type header. */
//------------------------------应该输入那些参数
/* returns null on error. *///-------- - 返回值含义
int osip_accept_to_str(const osip_accept_t * accept, char **dest)
{
//---------------------------- - 对于所有不需要或不能改变的变量都应该使用const标识
char *buf; //------------------临时变量
char *tmp;
size_t len;
*dest = NULL;
if (accept == NULL)//--------------任何参数传入后都应该检查它的有效性
return -1;// -------------------- - 根据传入参数的有效性区别对待
if ((accept->type == NULL) && (accept->subtype == NULL))
{
/* Empty header ! */
buf = (char *)osip_malloc(2);
buf[0] = ' ';
buf[1] = '\0';
*dest = buf;
return 0;
}
/* try to guess a long enough length *///----------- 段落注释
len = strlen(accept->type) + strlen(accept->subtype) + 4 /* for '/', ' ', ';' and '\0' *///------------------行注释
+ 10 * osip_list_size(accept->gen_params);
buf = (char *)osip_malloc(len); //----------------所有的指针必须有其空间
tmp = buf;
sprintf(tmp, "%s/%s", accept->type, accept->subtype);
tmp = tmp + strlen(tmp);
{
int pos = 0;
osip_generic_param_t *u_param;
#if 0//---------------------------对于不再使用但是又有必有保留以后使用的
if (!osip_list_eol(accept->gen_params, pos))
{
/* needed for cannonical form! (authentication issue of rfc2543) */
sprintf(tmp, " ");
tmp++;
}
#endif
while (!osip_list_eol(accept->gen_params, pos))
{
size_t tmp_len;
u_param = (osip_generic_param_t *)osip_list_get(accept->gen_params, pos);
if (u_param->gvalue == NULL)//------------要为所有的函数调用判断是否成功
{
osip_free(buf);
return -1;
}
tmp_len = strlen(buf) + 4 + strlen(u_param->gname)
+ strlen(u_param->gvalue) + 1;
if (len < tmp_len)
{
buf = osip_realloc(buf, tmp_len);
len = tmp_len;
tmp = buf + strlen(buf);
}
sprintf(tmp, "; %s=%s", u_param->gname, u_param->gvalue);
tmp = tmp + strlen(tmp);
pos++;
}
}
*dest = buf;
return 0;
}
|
|
附件1:规范的版权声明
/* * Copyright (c) 2001,XXX有限公司网络应用事业部 * All rights reserved. * * 文件名称:filename.h * 文件标识:见配置管理计划书 * 摘 要:简要描述本文件的内容 * * 当前版本:1.1 * 作 者:输入作者(或修改者)名字 * 完成日期:2001年7月20日 * * 取代版本:1.0 * 原作者 :输入原作者(或修改者)名字 * 完成日期:2001年5月10日 */ |
附件2:精简格式
实际的文件不太需要这么多,并且参照其他分成两部分,版权说明和文件说明
/* * Copyright (c) 2006,XXX技术有限公司 * All rights reserved. * 作 者:peter * / /* * 文件名称: * 完成日期:2006年7月7日 * 摘 要: */ |