亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mms_uaprof.c

?? 一個非常實用的手機mms開發包,能夠滿足大部分不同品牌和型號手機的開發
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*
 * Mbuni - Open  Source MMS Gateway 
 * 
 * User-Agent profiles handling, content adaptation.
 * 
 * Copyright (C) 2003 - 2005, Digital Solutions Ltd. - http://www.dsmagic.com
 *
 * Paul Bagyenda <bagyenda@dsmagic.com>
 * 
 * This program is free software, distributed under the terms of
 * the GNU General Public License, with a few exceptions granted (see LICENSE)
 */
#include <ctype.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>

#include "mms_uaprof.h"
#include "mms_util.h"

struct MmsUaProfile {
     List *versions;
     unsigned long maxmsgsize;
     struct {
	  long x, y;
     } maxres;
     struct {
	  unsigned char all;
	  unsigned char presentation;
	  List *content, *_hash; /* List of accepted content formats (+ hash keys for fast look-up). */
	  
	  List *charset, *_chash; /* List of accepted charsets. */
	  List *lang;    /* List of accepted languages. */
	  List *enc;     /* List of accepted encodings. */
     } ccppaccept;
};

static Dict *profile_dict; /* Of MmsUaProfile *. */
static Octstr *profile_dir;  /* Directory for storing data. */

/* Hash function -- case insensitive. */
static unsigned long hash_key(Octstr *s)
{
     unsigned long h = 0;
     int i, n;
     char *x;

     if (!s) return 0;
     for (x = octstr_get_cstr(s), i = 0, n = octstr_len(s); i<n; i++)
	  h  += (unsigned long)tolower(x[i]);
     return h;
}


static void destroy_uaprof(MmsUaProfile *prof)
{
     if (prof->versions)
	  gwlist_destroy(prof->versions, 
		       (gwlist_item_destructor_t *)octstr_destroy);
     
     if (prof->ccppaccept.content) {
	  gwlist_destroy(prof->ccppaccept.content, (gwlist_item_destructor_t *)octstr_destroy);
	  gwlist_destroy(prof->ccppaccept._hash, NULL);
     }
     
     if (prof->ccppaccept.charset) {
	  gwlist_destroy(prof->ccppaccept.charset, (gwlist_item_destructor_t *)octstr_destroy);
	  gwlist_destroy(prof->ccppaccept._chash, NULL);
     } if (prof->ccppaccept.lang)
	  gwlist_destroy(prof->ccppaccept.lang, (gwlist_item_destructor_t *)octstr_destroy);
     if (prof->ccppaccept.enc)
	  gwlist_destroy(prof->ccppaccept.enc, (gwlist_item_destructor_t *)octstr_destroy);

     gw_free(prof);
}

static void dump_profile(MmsUaProfile *prof, Octstr *name)
{
     int i;
     Octstr *s;
     
     debug("mms.uaprof", 0, "Dumping profile for %s", octstr_get_cstr(name));
     
     debug("mms.uaprof", 0, "MaxMsgSize: %ld", prof->maxmsgsize);
     debug("mms.uaprof", 0, "MaxRes: %ldx%ld", prof->maxres.x,prof->maxres.y);
     

     s = octstr_create("");
     if (prof->ccppaccept.content)
	  for (i=0; i<gwlist_len(prof->ccppaccept.content); i++)
	       octstr_format_append(s, "%S, ", gwlist_get(prof->ccppaccept.content,i));
     debug("mms.uaprof", 0, "Accept content: %s", octstr_get_cstr(s));     
     octstr_destroy(s);


     s = octstr_create("");
     if (prof->ccppaccept.enc)
	  for (i=0; i<gwlist_len(prof->ccppaccept.enc); i++)
	       octstr_format_append(s, "%S, ", gwlist_get(prof->ccppaccept.enc,i));
     debug("mms.uaprof", 0, "Accept encodings: %s", octstr_get_cstr(s));     
     octstr_destroy(s);

     s = octstr_create("");
     if (prof->ccppaccept.lang)
	  for (i=0; i<gwlist_len(prof->ccppaccept.lang); i++)
	       octstr_format_append(s, "%S, ", gwlist_get(prof->ccppaccept.lang,i));
     debug("mms.uaprof", 0, "Accept language: %s", octstr_get_cstr(s));     
     octstr_destroy(s);

     s = octstr_create("");
     if (prof->ccppaccept.charset)
	  for (i=0; i<gwlist_len(prof->ccppaccept.charset); i++)
	       octstr_format_append(s, "%S, ", gwlist_get(prof->ccppaccept.charset,i));
     debug("mms.uaprof", 0, "Accept charset: %s", octstr_get_cstr(s));     
     octstr_destroy(s);

     s = octstr_create("");
     if (prof->versions)
	  for (i=0; i<gwlist_len(prof->versions); i++)
	       octstr_format_append(s, "%S, ", gwlist_get(prof->versions,i));
     debug("mms.uaprof", 0, "Mms Version: %s", octstr_get_cstr(s));     
     octstr_destroy(s);
     
}

/* Helper function: find a node. Uses breadth first search */
static xmlNodePtr find_node(xmlNodePtr start, char *name, char *id, int level, int maxlevel)
{
     xmlNodePtr node, x, list;

     
     if (level >= maxlevel) return NULL;
     
     /* First search at top level. */
     for (list=start; list; list=list->next)
	  if (list->type == XML_COMMENT_NODE)
	       continue;
	  else if (xmlStrcasecmp(list->name, (const xmlChar *)name) == 0) {
	       if (!id)
		    return list;
	       else {
		    unsigned char *s;
		    if ((s= xmlGetProp(list,(unsigned char *)"ID")) != NULL && 
			xmlStrcasecmp(s,(unsigned char *)id) == 0) {
			 xmlFree(s);
			 return list;
		    }
		    if (s) xmlFree(s);
	       }
	  }
     /* Then recurse...*/
     for (list = start; list; list=list->next)     
	  for (node = list->xmlChildrenNode; node; node = node->next)
	       if (xmlStrcasecmp(node->name, (const xmlChar *)name) == 0) {
		    if (!id)
			 return node;
		    else {
			 unsigned char *s;
			 if ((s = xmlGetProp(node,(unsigned char *)"ID")) != NULL && 
			     xmlStrcasecmp(s,(unsigned char *)id) == 0) {
			      xmlFree(s);
			      return node; 
			 }
			 if (s) xmlFree(s);
		    }
	       } else if (node->type != XML_COMMENT_NODE && 
			  (x = find_node(node, name,id, level+1,maxlevel)) != NULL) 
		    return x;     
     return NULL;
}

MmsUaProfile *mms_make_ua_profile(List *req_headers)
{
     MmsUaProfile *prof = NULL;
     Octstr *s, *ua;
     List *l;
     int i, n;
     static int uacounter;
     
     /* Check cache first, if not, then construct. */
     if ((ua = http_header_value(req_headers, octstr_imm("User-Agent"))) == NULL)
	  ua = octstr_format("dummy-ua-%d", uacounter++);
     
     if ((prof = dict_get(profile_dict, ua)) != NULL) 
	  goto done;
          
     prof = gw_malloc(sizeof *prof);
     memset(prof, 0, sizeof *prof);
     
     /* Put in some defaults. then read then check accepts. */
     prof->maxres.x = 640;
     prof->maxres.y = 480;
     prof->maxmsgsize = 100*1024;
     prof->versions = gwlist_create();


     gwlist_append(prof->versions, octstr_imm("1.0")); /* Assume 1.0 for now. */
     
     /* Get accepted charsets. */
     s = http_header_value(req_headers, octstr_imm("Accept-Charset"));
     
     if (s && (l = http_header_split_value(s)) != NULL) {
	  prof->ccppaccept.charset = l;
	  prof->ccppaccept._chash = gwlist_create();
	  for (i = 0, n = gwlist_len(l); i<n; i++)
	       gwlist_append(prof->ccppaccept._chash, (void *)hash_key(gwlist_get(l, i)));	  
     }
     if (s) octstr_destroy(s);


     /* Get accepted encodings. */
     s = http_header_value(req_headers, octstr_imm("Accept-Encoding"));
     
     if (s && (l = http_header_split_value(s)) != NULL)
	  prof->ccppaccept.enc = l;     

     if (s) octstr_destroy(s);



     /* Get accepted language. */
     s = http_header_value(req_headers, octstr_imm("Accept-Language"));   
     if (s && (l = http_header_split_value(s)) != NULL)
	  prof->ccppaccept.lang = l;     

     if (s) octstr_destroy(s);
     
     s = http_header_value(req_headers, octstr_imm("Accept"));   
     if (s && (l = http_header_split_value(s)) != NULL) {
	  prof->ccppaccept.content = l;
	  prof->ccppaccept._hash = gwlist_create();
	  
	  for (i = 0, n = l ? gwlist_len(l) : 0; i<n; i++) {
	       Octstr *x = gwlist_get(l, i);
	       if (octstr_str_compare(x, "*/*") == 0)
		    prof->ccppaccept.all = 1;
	       else if (octstr_case_compare(x, octstr_imm(PRES_TYPE)) == 0)
		    prof->ccppaccept.presentation = 1;
	       
	       gwlist_append(prof->ccppaccept._hash, (void *)hash_key(x));
	  }
     }
     
     if (s) octstr_destroy(s);
 
     /* Put it in with the UA string as the key. */
     if (dict_put_once(profile_dict, ua, prof) != 1)
	  warning(0, "mms_uaprof: Duplicate cache entry(%s)?\n", 
		  octstr_get_cstr(ua));
     
     /* Done. Dump it while debugging. */
 done:

#if 1
     dump_profile(prof, ua ? ua : octstr_imm("<from http headers>"));
#endif
     
     if (ua)
	  octstr_destroy(ua);
     return prof;     
}

static MmsUaProfile *parse_uaprofile(Octstr *xml)
{
     char *s = octstr_get_cstr(xml);
     xmlDocPtr doc = xmlParseMemory(s, octstr_len(xml));
     xmlNodePtr node, xnode;
     MmsUaProfile *prof = NULL;
     
     if (!doc || !doc->xmlChildrenNode) 
	  goto done;

     node = find_node(doc->xmlChildrenNode, "Description", "MmsCharacteristics",0,3);
     
     prof = gw_malloc(sizeof *prof);
     memset(prof, 0, sizeof *prof);
     
     /* Put in some defaults. then read the file. */
     prof->versions = NULL;
     prof->maxres.x = 640;
     prof->maxres.y = 480;
     prof->maxmsgsize = 100*1024;
     prof->versions = NULL;


     if (!node) 
	  goto done;

     for (xnode = node->xmlChildrenNode; xnode; xnode = xnode->next) {
	  xmlNodePtr child = xnode->xmlChildrenNode, lnode, rdfnode;
	  const unsigned char *xname = xnode->name;
	  unsigned char *childtext = xmlNodeListGetString(doc, child, 1);
	  List *l;
	  
	  /* If there is a Bag, get the list. */
	  if ((rdfnode = find_node(xnode->xmlChildrenNode, "Bag", NULL,0,1)) != NULL) {
	       l = gwlist_create();	       
	       for (lnode = rdfnode->xmlChildrenNode; lnode; lnode = lnode->next)
		    if (xmlStrcasecmp(lnode->name, (const xmlChar *)"li") == 0) {
			 unsigned char *t = xmlNodeListGetString(doc, lnode->xmlChildrenNode,1);
			 if (t) {
			   gwlist_append(l, octstr_create((char *)t));
			   xmlFree(t);
			 }
		    }
	  } else
	       l = NULL;
	  
	  if (xmlStrcasecmp(xname, (const xmlChar *)"MmsMaxMessageSize") == 0) 
	    sscanf((char *)childtext, "%ld", &prof->maxmsgsize);
	  else if (xmlStrcasecmp(xname, (const xmlChar *)"MmsMaxImageResolution") == 0) 
	    sscanf((char *)childtext, "%ldx%ld", &prof->maxres.x, &prof->maxres.y);
	  else if (xmlStrcasecmp(xname, (const xmlChar *)"MmsCcppAcceptCharSet") == 0 ||
		   xmlStrcasecmp(xname, (const xmlChar *)"MmsCcppAccept-CharSet") == 0) {/* Cranky old ones! */
	       int i, n;
	       prof->ccppaccept.charset = l;
	       prof->ccppaccept._chash = gwlist_create();
	       for (i = 0, n = gwlist_len(l); i<n; i++)
		    gwlist_append(prof->ccppaccept._chash, (void *)hash_key(gwlist_get(l, i)));
	  } else if (xmlStrcasecmp(xname, (const xmlChar *)"MmsCcppAcceptLanguage") == 0) 
	       prof->ccppaccept.lang = l;
	  else if (xmlStrcasecmp(xname, (const xmlChar *)"MmsCcppAcceptEncoding") == 0) 
	       prof->ccppaccept.enc = l;
	  else if (xmlStrcasecmp(xname, (const xmlChar *)"MmsVersion") == 0) {
	       if (!l && childtext) { /* SonyEriccson uses old format! */
		    l = gwlist_create();
		    gwlist_append(l, octstr_create((char *)childtext));
	       }
	       prof->versions = l;
	  } else if (xmlStrcasecmp(xname, (const xmlChar *)"MmsCcppAccept") == 0) {
	       int i, n;
	       prof->ccppaccept.content = l;
	       prof->ccppaccept._hash = gwlist_create();
	       
	       for (i = 0, n = l ? gwlist_len(l) : 0; i<n; i++) {
		    Octstr *x = gwlist_get(l, i);
		    if (octstr_str_compare(x, "*/*") == 0)
			 prof->ccppaccept.all = 1;
		    else if (octstr_case_compare(x, octstr_imm(PRES_TYPE)) == 0)
			 prof->ccppaccept.presentation = 1;

		    gwlist_append(prof->ccppaccept._hash, (void *)hash_key(x));
	       }
	  }	  
	  if (childtext) xmlFree(childtext);
     }

 done:
     if (doc) xmlFreeDoc(doc);
     return prof;
}


static int replace_slash(int ch)
{
     return (ch == '/') ? '$' : ch;
}

static int unreplace_slash(int ch)
{
     return (ch == '$') ? '/' : ch;
}

static int mms_load_ua_profile_cache(char *dir)
{

     DIR *dirp;
     struct dirent *dp;
     dirp = opendir(dir);
     
     if (!dirp) {
	  error(0, "mms_uaprof: Failed to open UA prof cache directory %s", 
		dir);
	  return -1;
     }

     while ((dp = readdir(dirp)) != NULL) {
	  Octstr *fname;
	  Octstr *xml = NULL;
	  MmsUaProfile *prof = NULL;
	  Octstr *key = NULL;
	  
	  
	  if (strcmp(dp->d_name, ".") == 0 || 
	      strcmp(dp->d_name, "..") == 0) /* A directory, skip. */
	       continue;
	  
	  fname = octstr_format("%.255s/%.254s", dir, dp->d_name);
	  
	  xml = octstr_read_file(octstr_get_cstr(fname));
	  octstr_destroy(fname);
	  if (!xml) {
	       error(0, "mms_uaprof: Failed to read UA prof doc %s in %s (%s)\n", 
		     dp->d_name, dir, strerror(errno));
	       continue;
	  }
	  
	  prof = parse_uaprofile(xml);
	  if (!prof) {
	       error(0, "mms_uaprof: Failed to parse UA prof doc %s in %s\n", dp->d_name, dir);
	       goto loop;
	  }

	  key = octstr_create(dp->d_name);
	  octstr_convert_range(key, 0, octstr_len(key), unreplace_slash);

	  if (dict_put_once(profile_dict, key, prof) != 1)
	       warning(0, "mms_uaprof: Duplicate cache entry(%s)?\n", 
		       octstr_get_cstr(key));
#if 1
	  dump_profile(prof, key);
#endif
     loop:
	  if (xml) octstr_destroy(xml);	  	  
	  if (key) octstr_destroy(key);
     }
     closedir(dirp);

     return 0;
}


static MmsUaProfile *profile_fetch(Octstr *profile_url)
{
     Octstr *body = NULL;
     List *h, *rh = NULL;
     int status;
     MmsUaProfile *prof;

     gw_assert(profile_dict);
     
     debug("mms.uaprof", 0, "Entered fetcher");  

     if ((prof = dict_get(profile_dict, profile_url)) != NULL) 
	  return prof;

     h = http_create_empty_headers();
     http_header_add(h, "User-Agent", MM_NAME "/" MMSC_VERSION);	       
     
     status = mms_url_fetch_content(HTTP_METHOD_GET, profile_url, h, octstr_imm(""), &rh, &body);   
     if (http_status_class(status) == HTTP_STATUS_SUCCESSFUL) {
	  prof = parse_uaprofile(body);
	  
	  debug("mms.uaprof", 0, "Fetcher got %s", octstr_get_cstr(profile_url));	  
	  if (prof) {
	       if (dict_put_once(profile_dict, profile_url, prof) != 1)
		    warning(0, "mms_uaprof: Duplicate ua profile fetched? (%s)?\n", 
			    octstr_get_cstr(profile_url));
	       else {
		    Octstr *fname;
		    FILE *f;
		    octstr_convert_range(profile_url, 0, octstr_len(profile_url), replace_slash);
		    fname = octstr_format("%.255s/%.254s", octstr_get_cstr(profile_dir), 
					  octstr_get_cstr(profile_url));
		    
		    f = fopen(octstr_get_cstr(fname), "w");
		    
		    if (f) {
			 octstr_print(f, body);
			 fclose(f);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一区二区精品久久911| 一本久久精品一区二区| 欧美一区欧美二区| 喷白浆一区二区| 日韩一区二区在线观看视频播放| 日韩精品成人一区二区三区| 日韩一区二区三区四区五区六区| 免费观看成人av| 欧美韩日一区二区三区| 97久久超碰精品国产| 亚洲va欧美va天堂v国产综合| 欧美一区二区播放| 成人网男人的天堂| 一级精品视频在线观看宜春院| 欧美日韩精品欧美日韩精品一| 久久精品国产秦先生| 国产日韩欧美激情| 91丨porny丨蝌蚪视频| 性做久久久久久| 亚洲精品一区二区精华| jlzzjlzz国产精品久久| 日韩电影在线一区| 国产精品视频yy9299一区| 在线免费不卡电影| 国产剧情av麻豆香蕉精品| 亚洲欧美一区二区三区孕妇| 91精品国产手机| 粉嫩嫩av羞羞动漫久久久| 亚洲国产一区在线观看| 精品精品欲导航| 色婷婷精品久久二区二区蜜臀av| 免费精品99久久国产综合精品| 国产人伦精品一区二区| 欧美日韩国产高清一区二区| 国产精品一品视频| 午夜精品福利在线| 国产精品国产三级国产普通话三级| 欧洲亚洲国产日韩| 成人永久免费视频| 久久精品国产精品亚洲红杏| 亚洲乱码国产乱码精品精可以看| 欧美mv和日韩mv国产网站| 一本久道中文字幕精品亚洲嫩| 国产中文字幕精品| 亚洲国产综合人成综合网站| 国产精品久久久久aaaa樱花| 精品国产精品一区二区夜夜嗨| 在线观看亚洲精品| 国产91精品在线观看| 日韩成人精品视频| 亚洲一区在线视频观看| 国产精品久久久久久久久晋中| 欧美一级欧美三级| 欧美无乱码久久久免费午夜一区| 成人动漫在线一区| 国产在线观看一区二区| 丝瓜av网站精品一区二区| 一级精品视频在线观看宜春院| 亚洲国产成人午夜在线一区| 精品国产1区二区| 欧美一区二区视频在线观看2022| 91国模大尺度私拍在线视频| 97久久精品人人澡人人爽| 成人午夜大片免费观看| 国产91精品入口| 国产麻豆视频精品| 国模一区二区三区白浆| 美女视频黄久久| 日本不卡不码高清免费观看| 五月天亚洲婷婷| 亚洲电影视频在线| 亚洲狠狠爱一区二区三区| 一区二区免费视频| 亚洲国产成人va在线观看天堂| 国产精品国产成人国产三级 | 欧美高清精品3d| 色成人在线视频| 色婷婷av一区二区三区之一色屋| 色综合中文字幕国产 | 久久丝袜美腿综合| 精品国产一区久久| 久久久久久久久久久黄色| 久久久www成人免费无遮挡大片| 久久综合狠狠综合久久综合88| 精品国产制服丝袜高跟| 国产丝袜在线精品| 成人免费在线播放视频| 自拍av一区二区三区| 亚洲制服丝袜av| 日日夜夜一区二区| 精品一区二区日韩| 豆国产96在线|亚洲| 99麻豆久久久国产精品免费 | 日韩一区二区麻豆国产| 日韩三级视频在线观看| 国产日韩欧美精品一区| 自拍偷拍欧美精品| 亚洲h在线观看| 久久99久久久久久久久久久| 国模无码大尺度一区二区三区| 国产精品一二一区| 成人av免费网站| 欧美在线视频全部完| 日韩区在线观看| 中文字幕二三区不卡| 亚洲一区二区三区爽爽爽爽爽| 日本视频免费一区| 成人妖精视频yjsp地址| 91电影在线观看| 精品日本一线二线三线不卡| 国产精品国产三级国产专播品爱网| 亚洲欧美日本韩国| 蜜桃在线一区二区三区| 99re8在线精品视频免费播放| 欧美日韩精品一区二区三区四区| 欧美成人激情免费网| 综合网在线视频| 久久精品国产99国产精品| 91天堂素人约啪| 日韩一卡二卡三卡国产欧美| 中文字幕不卡在线播放| 视频一区欧美日韩| 99re热这里只有精品免费视频| 欧美一区二区三区免费大片| 国产精品三级电影| 日韩精品电影一区亚洲| 成人av电影观看| 欧美成人bangbros| 亚洲成人免费视| 成人激情图片网| 日韩一级成人av| 亚洲精选视频免费看| 韩国成人福利片在线播放| 欧美日韩一区二区不卡| 国产精品乱码人人做人人爱| 人人精品人人爱| 色美美综合视频| 国产日韩欧美a| 精品一区二区三区日韩| 精品国产伦一区二区三区免费| 一区二区三区美女视频| 高清国产午夜精品久久久久久| 欧美一区二区二区| 肉丝袜脚交视频一区二区| 日本韩国一区二区三区视频| 国产日产欧美一区二区三区| 久久精品久久精品| 7799精品视频| 一区二区在线观看视频在线观看| 国产精品1024| 久久一区二区三区国产精品| 美女性感视频久久| 欧美精品一二三区| 亚洲国产精品影院| 91福利在线播放| 依依成人综合视频| 97久久精品人人爽人人爽蜜臀| 中文字幕av一区二区三区高 | 91视频国产观看| 中文字幕一区二区三区在线播放| 国产成人亚洲精品青草天美| 精品久久久久久久久久久久久久久久久 | 精品午夜一区二区三区在线观看| 欧美日韩在线电影| 亚洲精品视频自拍| 日本韩国欧美一区| 一区二区三区视频在线看| 成人av午夜影院| 欧美激情一区二区在线| www.一区二区| 亚洲视频在线一区| 色婷婷av一区二区三区大白胸 | 国产三级久久久| 成人免费视频视频| 欧美国产日韩精品免费观看| 国产九色sp调教91| 久久久精品蜜桃| 99免费精品在线观看| 亚洲综合在线五月| 欧美日韩久久久久久| 麻豆成人91精品二区三区| 精品久久久久久久久久久久久久久| 国内成人精品2018免费看| 欧美国产精品v| 色欲综合视频天天天| 亚洲国产精品精华液网站| 欧美一区二区在线播放| 国产成人免费高清| 亚洲欧美另类综合偷拍| 欧美日韩国产精选| 国产呦萝稀缺另类资源| 国产精品久久福利| 欧美少妇一区二区| 久久成人久久爱| 中文字幕一区二区三区在线播放| 欧美色图天堂网| 国产一区二区女| 亚洲精品国产精华液| 日韩一区二区在线看| 成人黄色av电影|