void doYahooStep1a( char *buffer, char *request, const char *target, const char *username, const char *password, char *cookie, size_t *cookieSize ) { int retry = 5; while ( strstr( buffer, sjis2euc("パスワードの再確認") ) ) { Sleep( 2000 ); doYahooStep1b( buffer, request, username, password ); if ( strstr( buffer, "<input type=\"submit\" class=\"fakebutton\"" ) ) break; retry--; if ( retry <= 0 ) break; } if ( strstr( buffer, "<input type=\"submit\" class=\"fakebutton\"" ) ) doYahooStep2( buffer, request, target, cookie, cookieSize ); }
static errr send_text_to_chuukei_server(int x, int y, int len, byte col, cptr str) { char buf[1024]; char buf2[1024]; strncpy(buf2, str, len); buf2[len] = '\0'; if (len == 1) { sprintf(buf, "s%c%c%c%c", x+1, y+1, col, buf2[0]); } else if(string_is_repeat(buf2, len)) { int i; for (i = len; i > 0; i -= 127) { sprintf(buf, "n%c%c%c%c%c", x+1, y+1, MIN(i, 127), col, buf2[0]); } } else { #ifdef SJIS sjis2euc(buf2); #endif sprintf(buf, "t%c%c%c%c%s", x+1, y+1, len, col, buf2); } insert_ringbuf(buf); return (*old_text_hook)(x, y, len, col, str); }
/* * Hack -- read a string */ static void rd_string(char *str, int max) { int i; /* Read the string */ for (i = 0; TRUE; i++) { byte tmp8u; /* Read a byte */ rd_byte(&tmp8u); /* Collect string while legal */ if (i < max) str[i] = tmp8u; /* End of string */ if (!tmp8u) break; } /* Terminate */ str[max-1] = '\0'; #ifdef JP /* Convert Kanji code */ switch (kanji_code) { #ifdef SJIS case 2: /* EUC to SJIS */ euc2sjis(str); break; #endif #ifdef EUC case 3: /* SJIS to EUC */ sjis2euc(str); break; #endif case 0: { /* 不明の漢字コードからシステムの漢字コードに変換 */ byte code = codeconv(str); /* 漢字コードが判明したら、それを記録 */ if (code) kanji_code = code; break; } default: /* No conversion needed */ break; } #endif }
void logoutYahooJapan( char *buffer ) { char *p, *q; char cookie[MAX_COOKIE_LEN + 1]; _httpGetIC( "http://www.yahoo.co.jp/", buffer, FALSE, TRUE ); p = strstr( buffer, sjis2euc("ログアウト</a>") ); if ( p ) { while ( (p > buffer) && (strncmpi( p, " href=\"", 7 ) != 0) ) p--; if ( !strncmpi( p, " href=\"", 7 ) ) { p += 7; q = strchr( p, '"' ); if ( q ) { char url[BUFSIZ * 2]; strncpy( url, p, q - p ); url[q - p] = NUL; if ( url[0] == '/' ) { char buf[BUFSIZ]; sprintf( buf, "http://www.yahoo.co.jp%s", url ); strcpy( url, buf ); } // Yahoo! Japan からログアウトする _httpGetIC( url, buffer, FALSE, TRUE ); // クッキーを削除 cookie[0] = NUL; InternetSetCookie( "http://www.yahoo.co.jp/", NULL, cookie ); _httpGetIC( "http://www.yahoo.co.jp/", buffer, FALSE, TRUE ); p = strstr( buffer, sjis2euc("ログイン</a>") ); if ( !p ) logoutYahooJapan( buffer ); } } } }
static char *sj_to_euc(char *from, BOOL overwrite) { char *out; char *save; save = (char *) from; for (out = cvtbuf; *from && (out - cvtbuf < sizeof(cvtbuf)-3);) { if (is_shift_jis (*from)) { int code = sjis2euc ((int) from[0] & 0xff, (int) from[1] & 0xff); *out++ = (code >> 8) & 0xff; *out++ = code; from += 2; } else if (is_kana (*from)) {
int postArticleOnRakuten( const char *userName, /* ユーザ名 */ const char *password, /* パスワード */ char *title, /* 投稿記事題名 */ char *body, /* 投稿記事本文 */ const char *categoryName ) /* カテゴリ名 */ { int ret = 0; char *cookie = (char *)malloc( MAX_COOKIE_LEN ); char myBlogURL[MAX_URLLENGTH]; if ( cookie ) { memset( cookie, 0x00, MAX_COOKIE_LEN ); if ( loginRakuten( userName, password, cookie, myBlogURL ) ) { char *s, *t; s = sjis2euc( title ); strcpy( title, s ); t = sjis2euc( editForRakuten( body ) ); strcpy( body, t ); ret = postRakuten( userName, password, cookie, categoryName, title, body ); } free( cookie ); } else { if ( isatty( fileno( stderr ) ) ) fprintf( stderr, "login に失敗しました。\n" ); else MessageBox( NULL, "login に失敗しました。 ", "楽天ブログ", MB_OK|MB_ICONWARNING ); } return ( ret ); }
int postArticleOnFC2NETWORK( const char *username, /* メールアドレス */ const char *password, /* パスワード */ char *title, /* 投稿記事題名 */ char *body ) /* 投稿記事本文 */ { int ret = 0; char *cookie = (char *)malloc( MAX_COOKIE_LEN ); if ( cookie ) { memset( cookie, 0x00, MAX_COOKIE_LEN ); if ( loginFC2NETWORK( username, password, cookie ) ) { char *s, *t; s = sjis2euc( title ); strcpy( title, s ); /* FC2NETWORKでは使えないタグを別の表現に置換 */ t = editForFC2NETWORK( body ); strcpy( body, sjis2euc( t ) ); ret = postFC2NETWORK( username, password, cookie, title, body, NULL ); } free( cookie ); } else { if ( isatty( fileno( stderr ) ) ) fprintf( stderr, "login に失敗しました。\n" ); else MessageBox( NULL, "login に失敗しました。 ", "FC2NETWORK", MB_OK|MB_ICONWARNING ); } return ( ret ); }
char * any2euc( const char *p ) { char *q; q = utf2sjis( p ); if ( q ) // 変換対象文字列は UTF-8 である q = utf2euc( p ); else { // p の charset は UTF-8 ではない if ( strstr( p, "\033$@" ) || strstr( p, "\033$B" ) ) q = jis2euc( p ); else { q = sjis2euc( p ); if ( !q ) q = (char *)p; // すでに EUC-JP 変換済み(とみなす) } } return ( q ); }
/* 自 blog URL を取得 */ static char * getBlogURL( char *url, const char *htmlSrc ) { const char *p, *q; p = strstr( htmlSrc, sjis2euc("Myページの確認") ); if ( p ) { while ( p > htmlSrc ) { if ( *--p != 'h' ) continue; if ( !strncmp( p, "href=\"http://plaza.rakuten.co.jp/", 33 ) ) { p += 6; q = strchr( p, '"' ); if ( q ) { strncpy( url, p, q - p ); url[q - p] = NUL; } break; } } } return ( url ); }
/* 連日記 */ int interDiary( const char *usernameLivedoor, const char *usernameFC2N, const char *passwordFC2N, const char *editorPath ) { char postID[MAX_POSTIDLENGTH + 1]; char title[80]; char livedoorContent[20480]; char fc2networkContent[20480]; int ret; ret = writeDiary( title, livedoorContent, fc2networkContent, editorPath ); if ( ret ) { /* livedoor Blog に 記事 を投稿する */ CATLISTINFEX catEx; char blogID[80]; char *content, *subject; int bRet; char summary[2048]; blogID[0] = NUL; setTargetURL( ATOMURL_LIVEDOOR_200507 ); setBlogID( blogID ); catEx.numberOfCategories = 1; strcpy( catEx.categoryName[0], sjis2utf( "連日記" ) ); strcpy( summary, sjis2utf( "FC2NETWORK と連携した日記を書く企画です。" ) ); subject = (char *)malloc( strlen( title ) + BUFSIZ + 1 ); content = (char *)malloc( strlen(livedoorContent) * 3 + BUFSIZ + 1 ); strcpy( subject, sjis2utf( title ) ); if ( !strncmp( livedoorContent, "<p>", 3 ) ) strcpy( content, sjis2utf( livedoorContent ) ); else sprintf( content, "<p>%s</p>\n", sjis2utf( livedoorContent ) ); strcat( content, sjis2utf( "<p style=\"text-align: right;\">(つづく)</p>\n" "<hr />\n" "<p>* 続きは FC2NETWORK の私の日記をご覧ください</p>\n" ) ); bRet = postEntryOnAtomAPI( NULL, NULL, blogID, subject, /* 題名 */ summary, /* 概要 */ content, /* 本文 */ &catEx, /* カテゴリ */ TRUE, /* 投稿状態 */ postID /* 投稿後の記事ID */ ); free( subject ); free( content ); } if ( ret ) { /* FC2NETWORK に 日記 を投稿する */ char cookie[BUFSIZ * 4]; char livedoorURL[MAX_URLLENGTH]; char trackbackURL[512]; char *content, *subject; char body[20480]; setUserInfo( usernameFC2N, passwordFC2N ); setBlogKind( BLOGKIND_FC2NETWORK ); memset( cookie, 0x00, BUFSIZ * 4 ); if ( loginFC2NETWORK( NULL, NULL, cookie ) ) { sprintf( trackbackURL, "http://blog.livedoor.jp/%s/tb.cgi/%s", usernameLivedoor, postID ); sprintf( livedoorURL, "http://blog.livedoor.jp/%s/archives/%s.html", usernameLivedoor, postID ); sprintf( body, "* livedoor Blog で日記の前半、FC2NETWORK で日記の後半" "を書いています\n (この日記は livedoor Blog で書いた記" "事とセットになって1つの日記、つまり「連日記」を構成し" "ています。)\n\n" "livedoor Blog で書いた日記\n" "『[:strong-s:]%s[:strong-e:]』\n[:i-s:](%s)[:i-e:]\n" "の続きです。\n\n[:strong-s:](つづき)[:strong-e:]\n%s\n", title, livedoorURL, fc2networkContent ); subject = (char *)malloc( strlen( title ) + BUFSIZ + 1 ); content = (char *)malloc( strlen( body ) * 3 + BUFSIZ + 1 ); strcpy( subject, sjis2euc( title ) ); strcpy( content, sjis2euc( body ) ); postFC2NETWORK( NULL, NULL, cookie, subject, content, trackbackURL ); free( subject ); free( content ); } } return ( ret ); }
int getBlogIDsRakuten( const char *userName, // (I) ユーザ名 const char *password, // (I) パスワード int *numberOfBlogs, // (I) 取得する/取得した blog 情報の数 BLOGINF *blogInfo ) // (O) 取得した blog 情報 { char cookie[MAX_COOKIE_LEN]; char url[MAX_URLLENGTH]; int numOfBlogs = 0; cookie[0] = NUL; url[0] = NUL; loginRakuten( userName, password, cookie, url ); if ( url[0] ) { size_t sz = MAX_CONTENT_SIZE; char *response; strcpy( blogInfo[0].url, url ); blogInfo[0].blogName[0] = NUL; blogInfo[0].blogID[0] = NUL; response = (char *)malloc( sz ); if ( response ) { setUpReceiveBuffer( response, sz ); http_get( url, response ); if ( *response ) { char target[BUFSIZ]; const char *p, *q; target[0] = NUL; p = strstr( response, "<td class=\"title_text\" id=\"title\">" ); if ( p ) { p += 34; while ( (*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n') ) p++; q = strstr( p, "</td>" ); if ( q ) { while ( (q > p) && ( (*(q - 1) == ' ') || (*(q - 1) == '\t') || (*(q - 1) == '\r') || (*(q - 1) == '\n') ) ) q--; strncpy( target, p, q - p ); target[q - p] = NUL; } } else { p = strstr( response, "<title>" ); if ( p ) { p += 7; q = strstr( p, sjis2euc(" - 楽天") ); if ( q ) { strncpy( target, p, q - p ); target[q - p] = NUL; } } else { p = strstr( response, " id=\"counter\">" ); if ( p ) { p += 14; p = strstr( p, "<font color=\"" ); if ( p ) { p = strchr( p + 13, '>' ); if ( p ) { p++; q = strstr( p, sjis2euc(" 楽天") ); if ( q ) { strncpy( target, p, q - p ); target[q - p] = NUL; } } } } } } if ( target[0] ) { p = euc2sjis( target ); strcpy( blogInfo[0].blogName, p ? p : target ); } } free( response ); } numOfBlogs = 1; } *numberOfBlogs = numOfBlogs; return ( numOfBlogs ); }
int postRakuten( const char *username, const char *password, char *cookie, const char *categoryName, /* カテゴリ名 */ const char *title, /* 題名 */ const char *body ) /* 本文 */ { int ret = 0; char *request; char *response; size_t sz = MAX_CONTENT_SIZE * 4; char url[MAX_URLLENGTH]; char var_dummy[80]; char ch[80]; int yyyy, mm, dd; time_t t; struct tm *tm; int categoryID = 0; /* デフォルトは「カテゴリ未分類」 */ if ( !username || !(*username) || !password || !(*password) || !title || !(*title) || !body || !(*body) || !cookie || !(*cookie) ) return ( ret ); // if ( !username ) // username = xmlrpc_p->userName; // if ( !password ) // password = xmlrpc_p->password; request = (char *)malloc( MAX_CONTENT_SIZE ); if ( !request ) return ( ret ); response = (char *)malloc( sz ); if ( !response ) { free( request ); return ( ret ); } /* var_dummy 取得 */ memset( request, 0x00, MAX_CONTENT_SIZE ); var_dummy[0] = NUL; ch[0] = NUL; strcpy( url, "http://my.plaza.rakuten.co.jp/?func=diary&act=write" ); setUpReceiveBuffer( response, sz ); // httpGetBufferWithSession( url, response, TRUE, NULL, NULL, cookie, // NULL, NULL ); http_getEx( url, response, cookie ); if ( response[0] ) { char *p = strstr( response, "name=\"var_dummy\"" ); char *q; if ( p ) { p += 16; q = strstr( p, "value=\"" ); if ( q ) { q += 7; p = strchr( q, '"' ); if ( p ) { strncpy( var_dummy, q, p - q ); var_dummy[p - q] = NUL; } } } p = strstr( response, "name=\"ch\"" ); if ( p ) { p += 9; q = strstr( p, "value=\"" ); if ( q ) { q += 7; p = strchr( q, '"' ); if ( p ) { strncpy( ch, q, p - q ); ch[p - q] = NUL; } } } if ( categoryName && *categoryName ) { /* カテゴリ名 → カテゴリID 変換 */ char catID[64]; getCategoryIDbyName( catID, categoryName, response, "<select name=\"cate_id\">", "</select>", "<option value=\"", "\">", CHARSET_EUCJP ); if ( *catID ) categoryID = atol( catID ); } /* 投稿 */ strcpy( url, "http://my.plaza.rakuten.co.jp/" ); setTargetURL( url ); t = time( NULL ); tm = localtime( &t ); yyyy = tm->tm_year + 1900; mm = tm->tm_mon + 1; dd = tm->tm_mday; sprintf( request, "theme_id=0¤t_theme_id=0&ex_cate_id=0&" "cate_id=%d&" /* カテゴリID (テーマID) */ "d_title=%s&" /* 題名 (160バイト以内) */ "d_text=%s&" /* 本文 */ "d_img_service=&" "d_img_filename=&" "d_img_position=0&" "d_feel=1&" /* 気持ち (普通: 1) */ "d_himitsu=&" /* 非公開日記 */ "s_d_img_fileid=&" "s_d_img_position=&" "s_d_imgurl=&" "s_d_img_title=&" "s_d_img_w=&" "s_d_img_h=&" "t_img_service=&" "char_dummy=%s&" "var_dummy=%s&" "d_date=%04d-%02d-%02d&" "func=diary&act=write&" "sub_act=insert&" "ch=%s", categoryID, title, body, sjis2euc( "◇楽天◇"), var_dummy, yyyy, mm, dd, ch ); setUpReceiveBuffer( response, sz ); // ret = httpPostWithSession( xmlrpc_p->webServer, xmlrpc_p->webPage, // "application/x-www-form-urlencoded", // request, response, cookie, // NULL, NULL ); http_postEx( url, "application/x-www-form-urlencoded", request, response, cookie ); if ( response[0] && strstr( response, sjis2euc( "書き込みが完了しました" ) ) ) ret = 0; /* 投稿成功 */ else ret = -1; /* 投稿失敗 */ /* 注意: 楽天広場は1日3件までしか投稿できない。4件目を投稿しようと */ /* するとエラーになる */ } else ret = -1; free( response ); free( request ); return ( ret == -1 ? 0 : 1 ); }
BOOL _loginNewsingOnBBAuth( const char *username, // (I) ユーザ名 (Yahoo! Japan ID) const char *password, // (I) パスワード char *cookie, // (I/O) クッキー size_t *cookieSize // (I/O) クッキー文字列長 ) { BOOL ret = FALSE; const char *target = "http://newsing.jp/"; char address[MAX_WEBPAGENAME]; char *p; char *buffer = (char *)malloc( MAX_CONTENT_SIZE * 16 ); BOOL done = FALSE; int retry = 5; *cookie = NUL; if ( !buffer ) return ( ret ); // proxy 情報取得 setConfirmProxyInfoFunc( (CONF_FUNC)(-1) ); proxyInfoForBBAuth.useProxy = FALSE; proxyInfoForBBAuth.proxyServer[0] = NUL; proxyInfoForBBAuth.proxyPort = 0; proxyInfoForBBAuth.proxyUserName[0] = NUL; proxyInfoForBBAuth.proxyPassword[0] = NUL; getProxyInfo( &(proxyInfoForBBAuth.useProxy), proxyInfoForBBAuth.proxyServer, &(proxyInfoForBBAuth.proxyPort), proxyInfoForBBAuth.proxyUserName, proxyInfoForBBAuth.proxyPassword ); // 複数ユーザで同一PCを使っている場合もあり得るので、ログイン状態であれば // 念のためにいったんログアウトしておく _httpGetIC( target, buffer, FALSE, TRUE ); p = strstr( buffer, "/logout\">" ); if ( p ) { // newsing からログアウトする _httpGetIC( "http://newsing.jp/logout", buffer, FALSE, TRUE ); // クッキーを削除 // cookie[0] = NUL; // InternetSetCookie( target, NULL, cookie ); } done = FALSE; do { // Yahoo! Japan からログアウトする logoutYahooJapan( buffer ); // Sleep( 10000 ); // newsing向けBBAuth開始URLを取得 getLoginAddressOnYahooJapan( "http://newsing.jp/login", buffer, address, FALSE ); // BBAuth 開始 _httpGetIC( address, buffer, FALSE, FALSE ); if ( strstr( buffer, sjis2euc("パスワードの再確認") ) ) { char *request = (char *)malloc( RCV_BUFFER_SIZE ); if ( request ) { doYahooStep1a( buffer, request, target, username, password, cookie, cookieSize ); free( request ); if ( *cookie ) break; } retry--; if ( retry <= 0 ) break; } else done = TRUE; } while ( !done ); if ( done ) if ( !(*cookie) ) doYahooStep1( buffer, target, username, password, cookie, cookieSize ); if ( *cookie ) ret = TRUE; translateURL( NULL ); free( buffer ); return ( ret ); }