Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /bathyscaphe/trunk/frameworks/CocoMonar/framework/src/CMRHostTypes.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1670 - (hide annotations) (download)
Sat Dec 14 11:48:21 2013 UTC (10 years, 4 months ago) by tsawada2
File size: 4132 byte(s)
Treat shitaraba's old host URL / new host URL as same
1 tsawada2 1159 //
2     // CMRHostTypes.h
3     // BathyScaphe
4     //
5     // Updated by Tsutomu Sawada on 10/03/07.
6 tsawada2 1670 // Copyright 2005-2013 BathyScaphe Project. All rights reserved.
7 tsawada2 1159 // encoding="UTF-8"
8     //
9 tsawada2 3
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 tsawada2 1159 if (pbbs != NULL) {
28     *pbbs = NULL;
29     }
30     if (NULL == anURL || NULL == (path_ = [[anURL absoluteString] UTF8String])) {
31 tsawada2 3 return NULL;
32 tsawada2 1159 }
33    
34 tsawada2 3 pathsize = strlen(path_) * sizeof(char) + 1;
35    
36     buffer = SGTemporaryData();
37     bufSize = [buffer length];
38 tsawada2 1159 if (bufSize < pathsize) {
39     [buffer setLength:pathsize];
40     }
41 tsawada2 3 bufSize = [buffer length];
42     p = (char*)[buffer mutableBytes];
43    
44     memset(p, bufSize, '\0');
45     memmove(p, path_, pathsize);
46 tsawada2 1159
47 tsawada2 3 p = (char*)[[anURL scheme] UTF8String];
48 tsawada2 1159 if (NULL == p) {
49     return NULL;
50     }
51 tsawada2 3 n = strlen(p);
52 tsawada2 1159
53 tsawada2 3 // http://pc.2ch.net/mac
54     host_ = [buffer mutableBytes];
55     // ://pc.2ch.net/mac
56     host_ += n;
57    
58     // //pc.2ch.net/mac
59 tsawada2 1159 if (*host_ != ':') {
60     return NULL;
61     }
62 tsawada2 3 host_++;
63 tsawada2 1159
64 tsawada2 3 // pc.2ch.net/mac
65 tsawada2 1159 while ('/' == *host_) {
66 tsawada2 3 host_++;
67 tsawada2 1159 }
68     while (1) {
69 tsawada2 3 p = strrchr(host_, '/');
70 tsawada2 1159 if (NULL == p) {
71 tsawada2 3 return host_;
72 tsawada2 1159 }
73 tsawada2 3 *p = '\0';
74 tsawada2 1159 if (*(p +1) != '\0') {
75 tsawada2 3 break;
76 tsawada2 1159 }
77 tsawada2 3 }
78 tsawada2 1159
79     if (pbbs != NULL) {
80     *pbbs = ++p;
81     }
82 tsawada2 3 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 tsawada2 1159 if (pbbs != NULL) {
93 tsawada2 3 *pbbs = bbs_ ? [NSString stringWithUTF8String : bbs_] : nil;
94 tsawada2 1159 }
95     return [NSString stringWithUTF8String:host_];
96 tsawada2 3 }
97 tsawada2 1159
98 tsawada2 1670 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 tsawada2 3 /*
115 tsawada2 1159 * read.cgi���������������������������������������������������������
116     * ���������������������offlaw���������������URL���������������������������
117 tsawada2 3 */
118     bool can_readcgi(const char *host)
119     {
120 tsawada2 1159 // const char *p;
121     // char *ep;
122     //#warning 64BIT: Inspect use of long
123     // long l;
124 tsawada2 3
125 tsawada2 1159 if (NULL == host) {
126     return false;
127     }
128     if (strstr(host, ".2ch.net")) {
129 tsawada2 3 return !strstr(host, "tako") && !strstr(host, "piza.");
130 tsawada2 1159 }
131     if (strstr(host, ".bbspink.com")) {
132 tsawada2 3 return !strstr(host, "www.");
133 tsawada2 1159 }
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 tsawada2 3 }
152 tsawada2 1159
153 tsawada2 3 bool is_2channel(const char *host)
154     {
155     return can_readcgi(host);
156     }
157 tsawada2 238
158 tsawada2 1315 bool is_2ch_except_pink(const char *host)
159     {
160     if (host == NULL) {
161     return false;
162     }
163     if (strstr(host, ".2ch.net")) {
164     return !strstr(host, "tako") && !strstr(host, "piza.");
165     }
166     return false;
167     }
168    
169 tsawada2 238 bool is_2ch_belogin_needed(const char *host)
170     {
171     if (host != NULL) {
172 tsawada2 1159 return strstr(host, "be.2ch.net") != NULL || strstr(host, "qa.2ch.net") != NULL;
173 tsawada2 238 }
174     return false;
175     }
176    
177 tsawada2 1159 bool is_jbbs_livedoor(const char *host)
178 tsawada2 3 {
179     if (host != NULL) {
180 tsawada2 1667 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;
181 tsawada2 3 }
182     return false;
183     }
184    
185     bool is_machi(const char *host)
186     {
187     return host ? strstr(host, ".machi.to") || strstr(host, ".machibbs.com") : false;
188     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26