| 1 |
// |
| 2 |
// CMRHostTypes.h |
| 3 |
// BathyScaphe |
| 4 |
// |
| 5 |
// Updated by Tsutomu Sawada on 10/03/07. |
| 6 |
// Copyright 2005-2015 BathyScaphe Project. All rights reserved. |
| 7 |
// encoding="UTF-8" |
| 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) { |
| 28 |
*pbbs = NULL; |
| 29 |
} |
| 30 |
if (NULL == anURL || NULL == (path_ = [[anURL absoluteString] UTF8String])) { |
| 31 |
return NULL; |
| 32 |
} |
| 33 |
|
| 34 |
pathsize = strlen(path_) * sizeof(char) + 1; |
| 35 |
|
| 36 |
buffer = SGTemporaryData(); |
| 37 |
bufSize = [buffer length]; |
| 38 |
if (bufSize < pathsize) { |
| 39 |
[buffer setLength:pathsize]; |
| 40 |
} |
| 41 |
bufSize = [buffer length]; |
| 42 |
p = (char*)[buffer mutableBytes]; |
| 43 |
|
| 44 |
memset(p, bufSize, '\0'); |
| 45 |
memmove(p, path_, pathsize); |
| 46 |
|
| 47 |
p = (char*)[[anURL scheme] UTF8String]; |
| 48 |
if (NULL == p) { |
| 49 |
return NULL; |
| 50 |
} |
| 51 |
n = strlen(p); |
| 52 |
|
| 53 |
// http://pc.2ch.net/mac |
| 54 |
host_ = [buffer mutableBytes]; |
| 55 |
// ://pc.2ch.net/mac |
| 56 |
host_ += n; |
| 57 |
|
| 58 |
// //pc.2ch.net/mac |
| 59 |
if (*host_ != ':') { |
| 60 |
return NULL; |
| 61 |
} |
| 62 |
host_++; |
| 63 |
|
| 64 |
// pc.2ch.net/mac |
| 65 |
while ('/' == *host_) { |
| 66 |
host_++; |
| 67 |
} |
| 68 |
while (1) { |
| 69 |
p = strrchr(host_, '/'); |
| 70 |
if (NULL == p) { |
| 71 |
return host_; |
| 72 |
} |
| 73 |
*p = '\0'; |
| 74 |
if (*(p +1) != '\0') { |
| 75 |
break; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
if (pbbs != NULL) { |
| 80 |
*pbbs = ++p; |
| 81 |
} |
| 82 |
return host_; |
| 83 |
} |
| 84 |
|
| 85 |
NSString *CMRGetHostStringFromBoardURL(NSURL *anURL, NSString **pbbs) |
| 86 |
{ |
| 87 |
const char *host_; |
| 88 |
const char *bbs_ = NULL; |
| 89 |
|
| 90 |
host_ = CMRGetHostCStringFromBoardURL(anURL, (pbbs ? &bbs_ : NULL)); |
| 91 |
|
| 92 |
if (pbbs != NULL) { |
| 93 |
*pbbs = bbs_ ? [NSString stringWithUTF8String : bbs_] : nil; |
| 94 |
} |
| 95 |
return [NSString stringWithUTF8String:host_]; |
| 96 |
} |
| 97 |
|
| 98 |
NSURL *CMRGetAlternativeHostURLFromShitarabaBoardURL(NSURL *anURL) |
| 99 |
{ |
| 100 |
const char *host = CMRGetHostCStringFromBoardURL(anURL, NULL); |
| 101 |
if (host == NULL) { |
| 102 |
return nil; |
| 103 |
} |
| 104 |
|
| 105 |
if (strstr(host, "jbbs.livedoor.jp") != NULL) { |
| 106 |
return [[[NSURL alloc] initWithScheme:[anURL scheme] host:@"jbbs.shitaraba.net" path:[anURL path]] autorelease]; |
| 107 |
} else if (strstr(host, "jbbs.shitaraba.net") != NULL) { |
| 108 |
return [[[NSURL alloc] initWithScheme:[anURL scheme] host:@"jbbs.livedoor.jp" path:[anURL path]] autorelease]; |
| 109 |
} else { |
| 110 |
return nil; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
/* |
| 115 |
* read.cgi��������������������������������������������������������� |
| 116 |
* ���������������������offlaw���������������URL��������������������������� |
| 117 |
*/ |
| 118 |
bool can_readcgi(const char *host) |
| 119 |
{ |
| 120 |
// const char *p; |
| 121 |
// char *ep; |
| 122 |
//#warning 64BIT: Inspect use of long |
| 123 |
// long l; |
| 124 |
|
| 125 |
if (NULL == host) { |
| 126 |
return false; |
| 127 |
} |
| 128 |
if (strstr(host, ".2ch.net")) { |
| 129 |
return !strstr(host, "tako") && !strstr(host, "piza."); |
| 130 |
} |
| 131 |
if (strstr(host, ".bbspink.com")) { |
| 132 |
return !strstr(host, "www."); |
| 133 |
} |
| 134 |
/* 64.71.128.0/18 216.218.128.0/17 ������������ */ |
| 135 |
// p = strstr(host, "64.71."); |
| 136 |
// if (p) { |
| 137 |
// l = strtol(p + 6, &ep, 10); |
| 138 |
// if (*ep == '.' && (l & 0xc0) == 128) { |
| 139 |
// return true; |
| 140 |
// } |
| 141 |
// } |
| 142 |
// p = strstr(host, "216.218."); |
| 143 |
// if (p) { |
| 144 |
// l = strtol(p + 8, &ep, 10); |
| 145 |
// if (*ep == '.' && (l & 0x80) == 128) { |
| 146 |
// return true; |
| 147 |
// } |
| 148 |
// } |
| 149 |
// return strstr(host, ".he.net") != NULL; |
| 150 |
return false; |
| 151 |
} |
| 152 |
|
| 153 |
bool is_2channel(const char *host) |
| 154 |
{ |
| 155 |
return can_readcgi(host); |
| 156 |
} |
| 157 |
|
| 158 |
bool is_bbspink(const char *host) |
| 159 |
{ |
| 160 |
if (host == NULL) { |
| 161 |
return false; |
| 162 |
} |
| 163 |
if (strstr(host, ".bbspink.com")) { |
| 164 |
return !strstr(host, "www."); |
| 165 |
} |
| 166 |
return false; |
| 167 |
} |
| 168 |
|
| 169 |
bool is_2ch_except_pink(const char *host) |
| 170 |
{ |
| 171 |
if (host == NULL) { |
| 172 |
return false; |
| 173 |
} |
| 174 |
if (strstr(host, ".2ch.net")) { |
| 175 |
return !strstr(host, "tako") && !strstr(host, "piza."); |
| 176 |
} |
| 177 |
return false; |
| 178 |
} |
| 179 |
|
| 180 |
bool is_2ch_belogin_needed(const char *host) |
| 181 |
{ |
| 182 |
if (host != NULL) { |
| 183 |
return strstr(host, "be.2ch.net") != NULL || strstr(host, "qa.2ch.net") != NULL; |
| 184 |
} |
| 185 |
return false; |
| 186 |
} |
| 187 |
|
| 188 |
bool is_jbbs_livedoor(const char *host) |
| 189 |
{ |
| 190 |
if (host != NULL) { |
| 191 |
return strstr(host, "jbbs.shitaraba.net") != NULL || strstr(host, "jbbs.livedoor.jp") != NULL || strstr(host, "jbbs.livedoor.com") != NULL || strstr(host, "jbbs.shitaraba.com") != NULL; |
| 192 |
} |
| 193 |
return false; |
| 194 |
} |
| 195 |
|
| 196 |
bool is_machi(const char *host) |
| 197 |
{ |
| 198 |
return host ? strstr(host, ".machi.to") || strstr(host, ".machibbs.com") : false; |
| 199 |
} |
| 200 |
|
| 201 |
bool is_2ch_sc(const char *host) |
| 202 |
{ |
| 203 |
return host ? strstr(host, ".2ch.sc") : false; |
| 204 |
} |