⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adbanner.c

📁 打魔兽战网的都知道他是什么
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 1999  Ross Combs (rocombs@cs.nmsu.edu) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#define ADBANNER_INTERNAL_ACCESS#include "common/setup_before.h"#include <stdio.h>#ifdef HAVE_STDDEF_H# include <stddef.h>#else# ifndef NULL#  define NULL ((void *)0)# endif#endif#ifdef STDC_HEADERS# include <stdlib.h>#else# ifdef HAVE_MALLOC_H#  include <malloc.h># endif#endif#ifdef HAVE_STRING_H# include <string.h>#else# ifdef HAVE_STRINGS_H#  include <strings.h># endif#endif#ifdef HAVE_ASSERT_H# include <assert.h>#endif#include "compat/strrchr.h"#include "compat/strdup.h"#include "compat/strcasecmp.h"#include <errno.h>#include "compat/strerror.h"#include "common/tag.h"#include "common/bn_type.h"#include "common/eventlog.h"#include "common/list.h"#include "common/util.h"#include "common/xalloc.h"#include "connection.h"#include "adbanner.h"#include "common/setup_after.h"static t_list * adbannerlist_init_head=NULL;static t_list * adbannerlist_start_head=NULL;static t_list * adbannerlist_norm_head=NULL;static unsigned int adbannerlist_init_count=0;static unsigned int adbannerlist_start_count=0;static unsigned int adbannerlist_norm_count=0;static t_adbanner * adbanner_create(unsigned int id, unsigned int next_id, unsigned int delay, bn_int tag, char const * filename, char const * link, char const * client);static int adbanner_destroy(t_adbanner const * ad);static int adbannerlist_insert(t_list * head, unsigned int * count, char const * filename, unsigned int delay, char const * link, unsigned int next_id, char const * client);static t_adbanner * adbannerlist_find_adbanner_by_id(t_list const * head, unsigned int id, t_clienttag clienttag);static t_adbanner * adbannerlist_get_random(t_list const * head, t_clienttag client);static t_adbanner * adbanner_create(unsigned int id, unsigned int next_id, unsigned int delay, bn_int tag, char const * filename, char const * link, char const * client){    t_adbanner * ad;        if (!filename)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL filename");	return NULL;    }    if (!link)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL link");	return NULL;    }    if (!client)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL client");	return NULL;    }        ad = xmalloc(sizeof(t_adbanner));        ad->id           = id;    ad->extensiontag = bn_int_get(tag);    ad->delay        = delay;    ad->next         = next_id;    ad->filename = xstrdup(filename);    ad->link = xstrdup(link);    if (strcasecmp(client,"NULL")==0)    	ad->client = 0;    else	ad->client = clienttag_str_to_uint(client);    /* I'm aware that this statement looks stupid */    if (ad->client && (!tag_check_client(ad->client)))    {    	eventlog(eventlog_level_error,__FUNCTION__,"banner with invalid clienttag \"%s\"encountered",client);	xfree((void *)ad->link);	xfree((void *)ad->filename); /* avoid warning */	xfree(ad);	return NULL;    }    eventlog(eventlog_level_debug,__FUNCTION__,"created ad id=0x%08x filename=\"%s\" extensiontag=0x%04x delay=%u link=\"%s\" next_id=0x%08x client=\"%s\"",ad->id,ad->filename,ad->extensiontag,ad->delay,ad->link,ad->next,ad->client?client:"");    return ad;}static int adbanner_destroy(t_adbanner const * ad){    if (!ad)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ad");	return -1;    }        xfree((void *)ad->filename); /* avoid warning */    xfree((void *)ad->link); /* avoid warning */    xfree((void *)ad); /* avoid warning */        return 0;}extern t_adbanner * adbanner_get(t_connection const * c, unsigned int id){  t_adbanner * banner;  t_clienttag ctag = conn_get_clienttag(c);  banner = adbannerlist_find_adbanner_by_id(adbannerlist_init_head,id,ctag);  if (!banner) banner = adbannerlist_find_adbanner_by_id(adbannerlist_start_head,id,ctag);  if (!banner) banner = adbannerlist_find_adbanner_by_id(adbannerlist_norm_head,id,ctag);  return banner;}extern t_adbanner * adbanner_pick(t_connection const * c, unsigned int prev_id){    t_adbanner const * prev;    unsigned int       next_id;    t_clienttag ctag;        if (!c)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");	return NULL;    }    ctag = conn_get_clienttag(c);    /* eventlog(eventlog_level_debug,__FUNCTION__,"prev_id=%u init_count=%u start_count=%u norm_count=%u",prev_id,adbannerlist_init_count,adbannerlist_start_count,adbannerlist_norm_count); */    /* if this is the first ad, randomly choose an init sequence (if there is one) */    if (prev_id==0 && adbannerlist_init_count>0)        return adbannerlist_get_random(adbannerlist_init_head,ctag);//        return list_get_data_by_pos(adbannerlist_init_head,((unsigned int)rand())%adbannerlist_init_count);    /* eventlog(eventlog_level_debug,__FUNCTION__,"not sending init banner"); */        /* find the previous adbanner */    if ((prev = adbannerlist_find_adbanner_by_id(adbannerlist_init_head,prev_id,ctag)))	next_id = prev->next;    else if ((prev = adbannerlist_find_adbanner_by_id(adbannerlist_start_head,prev_id,ctag)))	next_id = prev->next;    else if ((prev = adbannerlist_find_adbanner_by_id(adbannerlist_norm_head,prev_id,ctag)))	next_id = prev->next;    else	next_id = 0;        /* return its next ad if there is one */    if (next_id)    {	t_adbanner * curr;		if ((curr = adbannerlist_find_adbanner_by_id(adbannerlist_init_head,next_id,ctag)))	    return curr;	if ((curr = adbannerlist_find_adbanner_by_id(adbannerlist_start_head,next_id,ctag)))	    return curr;	if ((curr = adbannerlist_find_adbanner_by_id(adbannerlist_norm_head,next_id,ctag)))	    return curr;		eventlog(eventlog_level_error,__FUNCTION__,"could not locate next requested ad with id 0x%06x",next_id);    }    /* eventlog(eventlog_level_debug,__FUNCTION__,"not sending next banner"); */        /* otherwise choose another starting point randomly */    if (adbannerlist_start_count>0)	return adbannerlist_get_random(adbannerlist_start_head,ctag);    /* eventlog(eventlog_level_debug,__FUNCTION__,"not sending start banner... nothing to return"); */    return NULL; /* nothing else to return */}extern unsigned int adbanner_get_id(t_adbanner const * ad){    if (!ad)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ad");	return 0;    }    return ad->id;}extern unsigned int adbanner_get_extensiontag(t_adbanner const * ad){    if (!ad)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ad");	return 0;    }    return ad->extensiontag;}extern char const * adbanner_get_filename(t_adbanner const * ad){    if (!ad)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ad");	return NULL;    }    return ad->filename;}extern char const * adbanner_get_link(t_adbanner const * ad){    if (!ad)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ad");	return NULL;    }    return ad->link;}extern t_clienttag adbanner_get_client(t_adbanner const * ad){    if (!ad)    {	eventlog(eventlog_level_error,__FUNCTION__,"got NULL ad");	return CLIENTTAG_UNKNOWN_UINT;    }    return ad->client;}static t_adbanner * adbannerlist_find_adbanner_by_id(t_list const * head, unsigned int id, t_clienttag clienttag){    t_elem const * curr;    t_adbanner *   temp;    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -