風は北向き ブログ

時の狭間で 今 お前を待つ

apache httpd 2.2.25 make (ubuntu 12.04) SSL コンパイルエラー対応

apacheの2.2.25をmakeしてたのですが、コンパイルエラーになってしまいました。

ssl_engine_io.c: In function ‘ssl_io_filter_connect’:
ssl_engine_io.c:1082:36: error: ‘SSL_PROTOCOL_SSLV2’ undeclared (first use in this function)
ssl_engine_io.c:1082:36: note: each undeclared identifier is reported only once for each function it appears in
make[4]: *** [ssl_engine_io.slo] Error 1

ASF Bugzilla – Bug 55194 をみて修正するとうまくいくようになりました

L1082行付近 変更前

if (hostname_note &&
    sc->proxy->protocol != SSL_PROTOCOL_SSLV2 &&
    sc->proxy->protocol != SSL_PROTOCOL_SSLV3 &&

変更後

if (hostname_note &&
//      sc->proxy->protocol != SSL_PROTOCOL_SSLV2 &&
        sc->proxy->protocol != SSL_PROTOCOL_SSLV3 &&

です。

YouTube API 動画検索6

所定のユーザーの投稿リストを取得する方法です。 ※前回のソースを利用しました。

public void YtSearchYtLib_search3()
{
    Feed<Video> ytEntries = null;
    YtSearchYtLib ytSearch = new YtSearchYtLib();
    url = YouTubeQuery.CreateUserUri("morningmusumechannel");
    for (ytEntries = ytSearch.searchFirst(url); ytEntries != null; ytEntries = ytSearch.searchNext())
    {
        foreach (Video ytEntry in ytEntries.Entries)
        {
            Debug.WriteLine(ytEntry.Title + ":" + ytEntry.Id);
            Console.WriteLine("Media:");
            foreach (Google.GData.YouTube.MediaContent mediaContent in ytEntry.Contents)
            {
                Console.WriteLine("\tMedia Location: " + mediaContent.Url);
                Console.WriteLine("\tMedia Type: " + mediaContent.Format);
                Console.WriteLine("\tDuration: " + mediaContent.Duration);
            }
        }
    }
}

これで、投稿した利用者に絞った検索ができますね。

YouTube API 動画検索5

あと、アップされた動画の参照回数を取得する方法です。 ※前回

public void YtSearchYtLib_search()
{
    Feed<Video> ytEntries = null;
    YtSearchYtLib ytSearch = new YtSearchYtLib();
    for (ytEntries = ytSearch.searchFirst("生田衣梨奈"); ytEntries != null; ytEntries = ytSearch.searchNext())
    {
        foreach (Video ytEntry in ytEntries.Entries)
        {
            Debug.WriteLine(ytEntry.Title + ":" + ytEntry.Id);
            Console.WriteLine("Media:");
            Console.WriteLine("ViewCount:"+video.ViewCount); // 参照回数
            foreach (Google.GData.YouTube.MediaContent mediaContent in ytEntry.Contents)
            {
                Console.WriteLine("\tMedia Location: " + mediaContent.Url);
                Console.WriteLine("\tMedia Type: " + mediaContent.Format);
                Console.WriteLine("\tDuration: " + mediaContent.Duration);
            }
        }
    }
}

同じVideoに定期的に(2~3時間くらい?)見に行くと変わってます。

次回はこれで、統計とか集めてみようと思います。

PHP 5.3.20 から MSSQL (sqlserver 2008) への 接続について

UbuntuPHP 5.3.20 から MSSQL(SqlServer)への接続について

以下の設定で行うことができます。 ※PHP 5.3 以降は本来、Microsoftからとってくるのが良いようです。

  1. unixODBC install download from ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.1.tar.gz
tar xvzf unixODBC-2.3.1.tar.gz
cd unixODBC-2.3.1
./configure
make
make install
  1. freetds install download from ftp://ftp.astron.com/pub/freetds/stable/freetds-stable.tgz (freetds-0.91) 2013/1/17
tar xvzf freetds-stable.tgz
cd freetds-0.91
./configure --with-unixodbc=/usr/local
make
make install
  1. ここで、ライブラリをロードします
/sbin/ldconfig
  1. envrionment file settings 4.1. /usr/local/etc/odbcinst.ini
[FreeTDS]
Description     = TDS driver
Driver          = /usr/local/lib/libtdsodbc.so.0
Setup           = /usr/lib/libtdsS.so
CPTimeout       =
CPReuse         =
FileUsage       = 1

4.2. /usr/local/etc/odbc.ini

[SQLSERVER]
Driver = FreeTDS
Description = sqlserver
Trace = No
Servername = backend
Database = testdb

4.3. /usr/local/etc/freetds.conf の最後に追加

[SQLSERVER]
host = backend
port = 1433
tds version = 7.2
charset = cp932
client charset = UTF-8
language = english
  1. ODBC設定の確認
#isql -v 識別子 接続ユーザー 接続パスワード
isql -v SQLSERVER sa admin
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>
  1. php install download from http://www.php.net/get/php-5.3.20.tar.gz/from/jp.php.net/mirror
./configure --prefix=/usr/local/php-5.3.20 --enable-mbstring --with-apxs2=/usr/local/httpd/bin/apxs --with-mssql --with-pdo-odbc=unixODBC
make
make install

となります。

  1. phpソース 実際のPHPには
<?php
$dbh= new PDO('odbc:dbname', 'user', 'pass');
$stmt = $dbh->prepare("select * from selecttable");
$stmt->execute();
while ($row = $stmt->fetch()) {
print_r($row);
}
unset($dbh); unset($stmt);
?>

で記述します。

結構古い記事が多かったので改めて整理してみました。

YouTube API 動画検索4

普通に YouTube APIのライブラリを使用して作ってみましたこんな感じです。

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.YouTube;
using Google.GData.Client;
using Google.YouTube;
using Google.GData.Extensions.MediaRss;
public class YtSearchYtLib
{
    Feed<Video> videoFeed = null;
    YouTubeRequest request = null;
    string applicationName = null;
    string developerKey = null;
    public YtSearchYtLib()
    {
    }
    public YtSearchYtLib(string applicationName, string developerKey)
    {
        this.applicationName = applicationName;
        this.developerKey = developerKey;
    }
    public Feed<Video> searchFirst(string queryKeyword)
    {
        Feed<Video> retp = null;
        YouTubeRequestSettings settings = new YouTubeRequestSettings(applicationName, developerKey);
        request = new YouTubeRequest(settings);
        YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
        query.OrderBy = "published";
        query.Query = queryKeyword;
        query.SafeSearch = YouTubeQuery.SafeSearchValues.None;
        videoFeed = request.Get<Video>(query);
        if (videoFeed != null && videoFeed.Entries.Count() > 0)
        {
            retp = videoFeed;
        }
        return retp;
    }
    public Feed<Video> searchNext()
    {
        Feed<Video> retp = null;
        videoFeed = request.Get<Video>(videoFeed, FeedRequestType.Next);
        if (videoFeed != null && videoFeed.Entries.Count() > 0)
        {
            retp = videoFeed;
        }
        return retp;
    }
}

使い方はこんな感じです。

public void YtSearchYtLib_search()
{
    Feed<Video> ytEntries = null;
    YtSearchYtLib ytSearch = new YtSearchYtLib();
    for (ytEntries = ytSearch.searchFirst("生田衣梨奈"); ytEntries != null; ytEntries = ytSearch.searchNext())
    {
        foreach (Video ytEntry in ytEntries.Entries)
        {
            Debug.WriteLine(ytEntry.Title + ":" + ytEntry.Id);
            Console.WriteLine("Media:");
            foreach (Google.GData.YouTube.MediaContent mediaContent in ytEntry.Contents)
            {
                Console.WriteLine("\tMedia Location: " + mediaContent.Url);
                Console.WriteLine("\tMedia Type: " + mediaContent.Format);
                Console.WriteLine("\tDuration: " + mediaContent.Duration);
            }
        }
    }
}

こっちのほうがいろいろ情報が見れますね。 これから詳しく YouTube API のライブラリを調査してみようと思います。

Ubuntu 12.04 server cifs で mount その4

CIFS で mount 出来なかった件について

/etc/network/if-up.dでやる方法でも大丈夫だったのですが、 ちょっと納得いかなかったので、いろいろ試していたのですが、 以下の方法で大丈夫というのがわかりました。 とりあえず、

CIFS VFS: default security mechanism requested.  The default security mechanism will be upgraded from ntlm to ntlmv2 in kernel release 3.3
CIFS VFS: cifs_mount failed w/return code = -112

はなくなりました。

やりかたとしては、まず、/etc/fstabに

//10.1.XXX.XXX/share /mnt/share cifs noauto,username=...

と、「noauto」で登録しておきます。

で、rc.localなどで、

mount /mnt/share

としておけばOKでした。

自分の場合、 service でちょっとネットワークドライブを mount する必要があったので、

!/bin/sh
ACTION=$1
shift
ARGS="$*"
case "$ACTION" in
  start)
        mount /mnt/share
        ;;
  stop)
        umount /mnt/share
        ;;
  restart)
        $0 stop $*
        sleep 5
        $0 start $*
        ;;
*)
        ;;
esac
exit 0

みたいな shell を作って /etc/init.d/mountcifs.sh に格納して、

sudo update-rc.d mountcifs.sh defaults 70

みたいにネットワークドライブを使う service の起動前にサービスとして 登録しました。rc.localでやっても、 service に登録してやっても、どちらでも大丈夫でした。

これで今のところエラーも出ずに動いています。 前のやり方でもOKだと思うのですが、こちらのほうがしっくりくるかなという感じです。

YouTube API 動画検索3

普通に.net frameworkのライブラリだけで作ってみたのがこんな感じです。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceModel.Syndication;
using System.Text;
using System.Xml;
using System.Web;
public class YtSearchStdNet
{
    const string YT_SEARCH_URI = "http://gdata.youtube.com/feeds/api/videos?orderby=published&max-results=10&start-index=1&v=2";
    string queryParam = "";
    string nextUri = "";
    public List searchFirst(string query)
    {
        string encodedQueryString = System.Web.HttpUtility.UrlEncode(query, Encoding.GetEncoding("UTF-8"));
        nextUri = YtSearchStdNet.YT_SEARCH_URI + "&q=" + encodedQueryString;
        return searchNext();
    }
    public List&lt;SyndicationItem&gt; searchNext()
    {
        List&lt;SyndicationItem&gt; retp = new List&lt;SyndicationItem&gt;();
        if (nextUri == null || nextUri.Length &lt;= 0)
        {
            return null;
        }
        using (XmlReader rdr = XmlReader.Create(nextUri))
        {
            nextUri = null;
            SyndicationFeed feed = SyndicationFeed.Load(rdr);
            retp.AddRange(feed.Items);
            foreach (SyndicationLink link in feed.Links)
            {
                if (link.RelationshipType == "next")
                {
                    nextUri = link.Uri.ToString();
                    break;
                }
            }
        }
        return retp;
    }
}

使い方はこんな感じです。

public void YtSearchStdNet_search()
{
    List&lt;SyndicationItem&gt; ytEntries = null;
    YtSearchStdNet ytSearch = new YtSearchStdNet();
    for (ytEntries = ytSearch.searchFirst("生田衣梨奈"); ytEntries != null && ytEntries.Count != 0; ytEntries = ytSearch.searchNext())
    {
        foreach (SyndicationItem ytEntry in ytEntries)
        {
            string uri = "";
            foreach (SyndicationLink sl in ytEntry.Links)
            {
                if (sl.RelationshipType == "alternate")
                {
                    uri = sl.Uri.ToString();
                    break;
                }
            }
            Debug.WriteLine(ytEntry.Title + ":" + ytEntry.Id + ":" + uri);
        }
    }
}

次は、YouTubeのライブラリで作ってみようと思います。