080622

|
今日の物置作りはニス塗りのみ。ちょっと休養です。ということでデスクトッ プ機を交換することに。旧マシンのディスクをつないでコピーを流しておいた のだけど、ニス塗りを終えてさぁ終わってるかなと見てみると、まったく進ん でない。マシンは恐ろしく重いし。やっぱりPIOなんだ...にしてもここまで遅 いとは思ってなかった。

ざっと眺めてみてixpideをアタッチしてみることに。
Index: ixpide.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/ixpide.c,v
retrieving revision 1.12
diff -u -r1.12 ixpide.c
--- ixpide.c	29 Apr 2008 06:53:03 -0000	1.12
+++ ixpide.c	22 Jun 2008 11:41:38 -0000
@@ -58,6 +58,8 @@
 	{ PCI_PRODUCT_ATI_SB400_SATA_2, 0, ixpdesc, ixp_chip_map },
 	{ PCI_PRODUCT_ATI_SB600_SATA_1, 0, ixpdesc, ixp_chip_map },
 	{ PCI_PRODUCT_ATI_SB600_SATA_2, 0, ixpdesc, ixp_chip_map },
+	{ PCI_PRODUCT_ATI_SB700_SATA_IDE, 0, ixpdesc, ixp_chip_map },
+	{ PCI_PRODUCT_ATI_SB700_IDE, 0, ixpdesc, ixp_chip_map },
 	{ 0, 			       0, NULL,	   NULL }
 };
 
なんとか動きそう。
[...]
ixpide0 at pci0 dev 17 function 0
ixpide0: ATI Technologies IXP IDE Controller (rev. 0x00)
ixpide0: bus-master DMA support present
ixpide0: primary channel configured to native-PCI mode
ixpide0: using ioapic0 pin 22 for native-PCI interrupt
[...]
ixpide1 at pci0 dev 20 function 1
ixpide1: ATI Technologies IXP IDE Controller (rev. 0x00)
ixpide1: bus-master DMA support present
ixpide1: primary channel configured to compatibility mode
ixpide1: primary channel interrupting at ioapic0 pin 14
最悪ディスクがふっとぶのでまずは新しいディスクをつけてみてテストしてみ たとこよさそう。fsckもかなり速くなった。そういえばpkgsrcコンパイルして いる時にExtracting...が妙に長いなとは思ってたんだけどね。その後はササっ とコピーといきたいとこだが、tarをパイプでつなげて展開していたらカーネル が落ちたので、なんとなくcp -RpにしてみたらOK。4.99.64の後半からちょっと 不安定。 日記システムもいろいろ手直しして動くようになった。ちょっとづつ便利ツー ルを組みあわせていったので、改めて見るとかなり見通しが悪い。 今の問題点はMovabletypeとの連携。メールの形にしてpost2blogで送りこんで いるのだけど、それもいいかげん面倒だし画像が全て下段にまとめられてしま うし。ということで、ちょっとxmlrpc-c++でMovabletypeにアクセスするコマン ドを作ってみました。
画像をアップロード。アップロードされたURLが標準出力に。
$ ./a.out -f -t "2008/06/22/20080622153109_0010999.jpg" < 20080622153109_0010999.jpg
http://crescentmoon.s.vnop.net/~uch/blog/2008/06/22/20080622153109_0010999.jpg
新しいエントリをポスト。ポストIDが標準出力に。タイトルは080622
$ nkf --utf8 < index.html |./a.out -p -t "080622"
5
ポストIDのエントリを変更。
$ nkf --utf8 < index.html |./a.out -e 5 -t "080622"
5
という感じで。されこれをどう組みこむかな...。
#include <string>
#include <iostream>
#include <xmlrpc-c/girerr.hpp>
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client_simple.hpp>

static void usage (void);
static bool read_from_stdin (uint8_t **, size_t *);
static int post_html (const char *, const uint8_t *);
static int edit_html (const char *, const uint8_t *, const char *);
static int upload_data (const uint8_t *, size_t, const char *);

using namespace std;

static struct
{
  string const server;
  const char *user;
  const char *password;
  const char *id;
} blog = {
  "http://crescentmoon.s.vnop.net/~uch/sn/mt-xmlrpc.cgi",
  "uch",
  "8ea8j7gl",// 'web service password'. not 'login password'.
  "1"
};

int
main (int argc, char *argv[])
{
  enum doit
    {
      none,
      newPost,
      editPost,
      newMediaObject
    }
  doit = none;
  extern char *optarg;
  uint8_t *buf;
  size_t sz;
  int ch;
  int command = 0;
  const char *post_id = "0";
  const char *title = "noname";

  while ((ch = getopt(argc, argv, "pfe:t:")) != -1)
    {
      switch (ch)
	{
	case 'p':
	  doit = newPost;
	  command++;
	  break;
	case 'e':
	  doit = editPost;
	  command++;
	  post_id = optarg;
	  break;
	case 'f':
	  doit = newMediaObject;
	  command++;
	  break;
	case 't':
	  title = optarg;
	  break;
	default:
	  usage ();
	  break;
	}
    }

  if (doit == none || command != 1)
    {
      usage ();
    }

  if (!read_from_stdin (&buf, &sz))
    {
      return 1;
    }

  switch (doit)
    {
    case newPost:
      return post_html (title, buf);
    case editPost:
      return edit_html (title, buf, post_id);
    case newMediaObject:
      return upload_data (buf, sz, title);
    default:
      ;//FALLTHROUGH
    }

  return 1;
}

static void
usage ()
{

  cerr << "-p: post HTML, -f: upload file, -e: edit HTML," <<
    "-t 'name' set title/filepath.\n";

  exit (1);
}

static int
post_html (const char *title, const uint8_t *content)
{
  string const method ("metaWeblog.newPost");

  try
    {
      xmlrpc_c::clientSimple rpc;
      xmlrpc_c::value value;
      string post_id;

      rpc.call (blog.server, method, "sss{s:s,s:s,s:s}b", &value,
		blog.id, blog.user, blog.password,
		"title", title,
		"description", content,
		"mt_text_more", "",
		1	// publish
		);

      // Get post id server returns.
      post_id = xmlrpc_c::value_string (value);
      cout << post_id;
    }
  catch (girerr::error const error)
    {
      cerr << method << " threw error: " << error.what() << endl;
      return 1;
    }
  catch (...)
    {
      cerr << method << " threw unexpected error." << endl;
      return 1;
    }

  return 0;
}


static int
edit_html (const char *title, const uint8_t *content, const char *post_id)
{
  string const method ("metaWeblog.editPost");

  try
    {
      xmlrpc_c::clientSimple rpc;
      xmlrpc_c::value value;

      rpc.call (blog.server, method, "sss{s:s,s:s,s:s}b", &value,
		post_id, blog.user, blog.password,
		"title", title,
		"description", content,
		"mt_text_more", "",
		1	// publish
		);
    }
  catch (girerr::error const error)
    {
      cerr << method << " threw error: " << error.what() << endl;
      return 1;
    }
  catch (...)
    {
      cerr << method << " threw unexpected error." << endl;
      return 1;
    }
  cout << post_id;

  return 0;
}

static int
upload_data (const uint8_t *buf, size_t sz, const char *filename)
{
  string const method ("metaWeblog.newMediaObject");

  try
    {
      xmlrpc_c::clientSimple rpc;
      xmlrpc_c::value retval;

      rpc.call
	(blog.server, method, "sss{s:s,s:6}",	// '6' means Base64
	 &retval,
	 blog.id, blog.user, blog.password,
	 "name", filename,// destination filename. (including path.)
	 "bits", buf, sz // data itself. (plane binary. libs encode to base64.)
	 );
      // Uploaded URL.
      std::map <std::string, xmlrpc_c::value> retitr =
	static_cast <xmlrpc_c::value_struct> (retval);
      cout << string (xmlrpc_c::value_string (retitr.find ("url")->second));
    }
  catch (girerr::error const error)
    {
      cerr << method << " threw error: " << error.what() << endl;
      return 1;
    }
  catch (...)
    {
      cerr << method << " threw unexpected error." << endl;
      return 1;
    }

  return 0;
}

static bool
read_from_stdin (uint8_t **buffer, size_t *total_size)
{
  size_t total_sz = 0, sz, chunk_sz = 1024;
  uint8_t *buf = (uint8_t *)malloc (chunk_sz);
  uint8_t *p1, *p = buf;

  while ((sz = fread (p + total_sz, 1, chunk_sz, stdin)) > 0)
    {
      total_sz += sz;
      if ((p1 = (uint8_t *)realloc (p, total_sz + chunk_sz)) == NULL)
	{
	  free (p);
	  perror ("realloc");
	  *total_size = 0, *buffer = 0;
	  return false;
	}
      p = p1;
    }

  *total_size = total_sz;
  *buffer = p;

  return true;
}