| 1 |
tsawada2 |
3 |
/** |
| 2 |
|
|
* $Id: CMRHostTypes.m,v 1.1.1.1 2005-05-11 17:51:19 tsawada2 Exp $ |
| 3 |
|
|
* |
| 4 |
|
|
* CMRHostTypes.m |
| 5 |
|
|
* |
| 6 |
|
|
* Copyright (c) 2003, Takanori Ishikawa. |
| 7 |
|
|
* See the file LICENSE for copying permission. |
| 8 |
|
|
*/ |
| 9 |
|
|
|
| 10 |
|
|
#import "CMRHostTypes.h" |
| 11 |
|
|
#import <SGFoundation/SGFoundation.h> |
| 12 |
|
|
#import "UTILKit.h" |
| 13 |
|
|
|
| 14 |
|
|
|
| 15 |
|
|
|
| 16 |
|
|
const char *CMRGetHostCStringFromBoardURL(NSURL *anURL, const char **pbbs) |
| 17 |
|
|
{ |
| 18 |
|
|
NSMutableData *buffer = nil; |
| 19 |
|
|
|
| 20 |
|
|
const char *path_; |
| 21 |
|
|
const char *host_; |
| 22 |
|
|
size_t bufSize; |
| 23 |
|
|
size_t pathsize; |
| 24 |
|
|
char *p; |
| 25 |
|
|
size_t n; |
| 26 |
|
|
|
| 27 |
|
|
if(pbbs != NULL) *pbbs = NULL; |
| 28 |
|
|
if(NULL == anURL || NULL == (path_ = [[anURL absoluteString] UTF8String])) |
| 29 |
|
|
return NULL; |
| 30 |
|
|
|
| 31 |
|
|
|
| 32 |
|
|
pathsize = strlen(path_) * sizeof(char) + 1; |
| 33 |
|
|
|
| 34 |
|
|
buffer = SGTemporaryData(); |
| 35 |
|
|
bufSize = [buffer length]; |
| 36 |
|
|
if(bufSize < pathsize) |
| 37 |
|
|
[buffer setLength : pathsize]; |
| 38 |
|
|
|
| 39 |
|
|
bufSize = [buffer length]; |
| 40 |
|
|
p = (char*)[buffer mutableBytes]; |
| 41 |
|
|
|
| 42 |
|
|
memset(p, bufSize, '\0'); |
| 43 |
|
|
memmove(p, path_, pathsize); |
| 44 |
|
|
|
| 45 |
|
|
p = (char*)[[anURL scheme] UTF8String]; |
| 46 |
|
|
if(NULL == p) return NULL; |
| 47 |
|
|
n = strlen(p); |
| 48 |
|
|
|
| 49 |
|
|
// http://pc.2ch.net/mac |
| 50 |
|
|
host_ = [buffer mutableBytes]; |
| 51 |
|
|
// ://pc.2ch.net/mac |
| 52 |
|
|
host_ += n; |
| 53 |
|
|
|
| 54 |
|
|
// //pc.2ch.net/mac |
| 55 |
|
|
if(*host_ != ':') return NULL; |
| 56 |
|
|
host_++; |
| 57 |
|
|
|
| 58 |
|
|
// pc.2ch.net/mac |
| 59 |
|
|
while('/' == *host_) |
| 60 |
|
|
host_++; |
| 61 |
|
|
|
| 62 |
|
|
while(1){ |
| 63 |
|
|
p = strrchr(host_, '/'); |
| 64 |
|
|
if(NULL == p) |
| 65 |
|
|
return host_; |
| 66 |
|
|
|
| 67 |
|
|
*p = '\0'; |
| 68 |
|
|
if(*(p +1) != '\0') |
| 69 |
|
|
break; |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
|
if(pbbs != NULL) *pbbs = ++p; |
| 73 |
|
|
|
| 74 |
|
|
return host_; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
NSString *CMRGetHostStringFromBoardURL(NSURL *anURL, NSString **pbbs) |
| 78 |
|
|
{ |
| 79 |
|
|
const char *host_; |
| 80 |
|
|
const char *bbs_ = NULL; |
| 81 |
|
|
|
| 82 |
|
|
host_ = CMRGetHostCStringFromBoardURL(anURL, (pbbs ? &bbs_ : NULL)); |
| 83 |
|
|
|
| 84 |
|
|
if(pbbs != NULL) |
| 85 |
|
|
*pbbs = bbs_ ? [NSString stringWithUTF8String : bbs_] : nil; |
| 86 |
|
|
|
| 87 |
|
|
return [NSString stringWithUTF8String : host_]; |
| 88 |
|
|
} |
| 89 |
|
|
NSString *CMRGetHostStringFromBoardURLNoCopy(NSURL *anURL, NSString **pbbs) |
| 90 |
|
|
{ |
| 91 |
|
|
const char *host_; |
| 92 |
|
|
const char *bbs_ = NULL; |
| 93 |
|
|
|
| 94 |
|
|
host_ = CMRGetHostCStringFromBoardURL(anURL, (pbbs ? &bbs_ : NULL)); |
| 95 |
|
|
if(pbbs != NULL) |
| 96 |
|
|
*pbbs = bbs_ ? [NSString stringWithCStringNoCopy:bbs_] : nil; |
| 97 |
|
|
|
| 98 |
|
|
return [NSString stringWithCStringNoCopy:host_]; |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
/* |
| 102 |
|
|
* read.cgi���p�X�d�l���������������������������� |
| 103 |
|
|
* �������O�q���Aofflaw�A���g�b�vURL�����������������p |
| 104 |
|
|
*/ |
| 105 |
|
|
bool can_readcgi(const char *host) |
| 106 |
|
|
{ |
| 107 |
|
|
const char *p; |
| 108 |
|
|
char *ep; |
| 109 |
|
|
long l; |
| 110 |
|
|
|
| 111 |
|
|
if(NULL == host) return false; |
| 112 |
|
|
|
| 113 |
|
|
if (strstr(host, ".2ch.net")) |
| 114 |
|
|
return !strstr(host, "tako") && !strstr(host, "piza."); |
| 115 |
|
|
if (strstr(host, ".bbspink.com")) |
| 116 |
|
|
return !strstr(host, "www."); |
| 117 |
|
|
/* 64.71.128.0/18 216.218.128.0/17 ���e�X�g */ |
| 118 |
|
|
p = strstr(host, "64.71."); |
| 119 |
|
|
if (p) { |
| 120 |
|
|
l = strtol(p + 6, &ep, 10); |
| 121 |
|
|
if (*ep == '.' && (l & 0xc0) == 128) |
| 122 |
|
|
return true; |
| 123 |
|
|
} |
| 124 |
|
|
p = strstr(host, "216.218."); |
| 125 |
|
|
if (p) { |
| 126 |
|
|
l = strtol(p + 8, &ep, 10); |
| 127 |
|
|
if (*ep == '.' && (l & 0x80) == 128) |
| 128 |
|
|
return true; |
| 129 |
|
|
} |
| 130 |
|
|
return strstr(host, ".he.net") != NULL; |
| 131 |
|
|
} |
| 132 |
|
|
bool is_2channel(const char *host) |
| 133 |
|
|
{ |
| 134 |
|
|
return can_readcgi(host); |
| 135 |
|
|
} |
| 136 |
|
|
// |
| 137 |
|
|
bool is_be2ch(const char *host) |
| 138 |
|
|
{ |
| 139 |
|
|
return host ? strstr(host, "be.2ch.net") != NULL && can_readcgi(host) : true; |
| 140 |
|
|
} |
| 141 |
|
|
bool is_jbbs_shita(const char *host) |
| 142 |
|
|
{ |
| 143 |
|
|
if (host != NULL) { |
| 144 |
|
|
return strstr(host, "jbbs.shitaraba.com") != NULL || |
| 145 |
|
|
strstr(host, "jbbs.livedoor.jp") != NULL || |
| 146 |
|
|
strstr(host, "jbbs.livedoor.com") != NULL; |
| 147 |
|
|
} |
| 148 |
|
|
return false; |
| 149 |
|
|
} |
| 150 |
|
|
|
| 151 |
|
|
bool is_machi(const char *host) |
| 152 |
|
|
{ |
| 153 |
|
|
return host ? strstr(host, ".machi.to") || strstr(host, ".machibbs.com") : false; |
| 154 |
|
|
} |
| 155 |
|
|
|
| 156 |
|
|
bool is_jbbs(const char *host) |
| 157 |
|
|
{ |
| 158 |
|
|
return host ? strstr(host, ".jbbs.net") || is_jbbs_shita(host) : false; |
| 159 |
|
|
} |
| 160 |
|
|
|
| 161 |
|
|
bool is_shitaraba(const char *host) |
| 162 |
|
|
{ |
| 163 |
|
|
return host ? strstr(host, ".shitaraba.com") != NULL && !is_jbbs_shita(host) : false; |
| 164 |
|
|
} |
| 165 |
|
|
|
| 166 |
|
|
bool is_tanteifile(const char *host) |
| 167 |
|
|
{ |
| 168 |
|
|
return host ? strstr(host, "tanteifile2.gasuki.com") : false; |
| 169 |
|
|
} |
| 170 |
|
|
|
| 171 |
|
|
|
| 172 |
|
|
/* |
| 173 |
|
|
* offlaw.cgi���g������������ |
| 174 |
|
|
*/ |
| 175 |
|
|
bool can_offlaw(const char *host) |
| 176 |
|
|
{ |
| 177 |
|
|
return false; |
| 178 |
|
|
// return can_readcgi(host) && strstr(host, "choco."); |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
|
|
|
| 182 |
|
|
/* |
| 183 |
|
|
* �������O�q�����V�`���������� |
| 184 |
|
|
*/ |
| 185 |
|
|
bool kako_salad(const char *host, const char *bbs) |
| 186 |
|
|
{ |
| 187 |
|
|
static char *oldkako_servers[] = { |
| 188 |
|
|
"piza.", |
| 189 |
|
|
"www.bbspink", |
| 190 |
|
|
NULL, |
| 191 |
|
|
}; |
| 192 |
|
|
int i; |
| 193 |
|
|
|
| 194 |
|
|
if (!can_readcgi(host)) |
| 195 |
|
|
return false; |
| 196 |
|
|
|
| 197 |
|
|
for (i = 0; oldkako_servers[i]; i++) { |
| 198 |
|
|
if (strstr(host, oldkako_servers[i])) |
| 199 |
|
|
return false; |
| 200 |
|
|
} |
| 201 |
|
|
|
| 202 |
|
|
if (strstr(host, "mentai.2ch.net")) { |
| 203 |
|
|
//debugout && fprintf(debugout, "kako_salad: bbs=%s\n", bbs); |
| 204 |
|
|
if(strstr(bbs, "mukashi/")) |
| 205 |
|
|
return false; |
| 206 |
|
|
} |
| 207 |
|
|
|
| 208 |
|
|
if (strstr(host, "www.2ch.net")) { |
| 209 |
|
|
//debugout && fprintf(debugout, "kako_salad: bbs=%s\n", bbs); |
| 210 |
|
|
if(strstr(bbs, "tako/") || strstr(bbs, "kitanet/")) |
| 211 |
|
|
return false; |
| 212 |
|
|
} |
| 213 |
|
|
|
| 214 |
|
|
return true; |
| 215 |
|
|
} |
| 216 |
|
|
|
| 217 |
|
|
/* |
| 218 |
|
|
* bbs.cgi���V�^�C�v�������� |
| 219 |
|
|
*/ |
| 220 |
|
|
bool bbs_qb(const char *host) |
| 221 |
|
|
{ |
| 222 |
|
|
#if 0 |
| 223 |
|
|
static char *newbbs_servers[] = { |
| 224 |
|
|
// "qb.", |
| 225 |
|
|
"ex.", |
| 226 |
|
|
"choco.", |
| 227 |
|
|
"comic.", |
| 228 |
|
|
"music.", |
| 229 |
|
|
"teri.", |
| 230 |
|
|
// "cocoa.", |
| 231 |
|
|
"game.", |
| 232 |
|
|
"oyster.", |
| 233 |
|
|
NULL, |
| 234 |
|
|
}; |
| 235 |
|
|
int i; |
| 236 |
|
|
|
| 237 |
|
|
if (!can_readcgi(host)) |
| 238 |
|
|
return false; |
| 239 |
|
|
|
| 240 |
|
|
for (i = 0; newbbs_servers[i]; i++) { |
| 241 |
|
|
if (strstr(host, newbbs_servers[i])) |
| 242 |
|
|
return true; |
| 243 |
|
|
} |
| 244 |
|
|
|
| 245 |
|
|
#endif |
| 246 |
|
|
return false; |
| 247 |
|
|
} |