2008/11/07

[Programming] urlencode

這邊應該是作為 這裡的備份
今天在整理我的 wiki 的時候才發現以前寫的筆記有不少東西已經不見了,怕再消失,所以把 source 也丟一份在這邊:
static char*
urlencode(char *s, int len, int *new_len)
{
unsigned char *from, *start, *end, *to;
unsigned c;
unsigned char hexchars[] = "0123456789ABCDEF";

from = s;
end = s + len;
start = to = (unsigned char *) malloc (3 * len + 1);
while (from < end)
{
c = *from;
if (c == ' ')
{
*to = '+';
to ++;
}
else if (
(c < '0' && c != '-' && c != '.') ||
(c < 'A' && c > '9') ||
(c > 'Z' && c < 'a' && c != '_') ||
(c > 'z'))
{
to[0] = '%';
to[1] = hexchars[c >> 4];
to[2] = hexchars[c & 15];
to += 3;
}
else
{
*to++ = c;
}
from ++;
}
*to = 0;
if (new_len)
{
*new_len = to - start;
}
return (unsigned char *) start;
}


這個 code 我有再依自已習慣的 code style 整理過。
話說,從退伍到現在,自已的 code style 變化不少。
張貼留言

[Linux] Private Key 不能登入的除錯方法與可能的問題點

最簡單的除錯方法是 $ ssh HOST -v 可能的問題點有: File/Dir Permission # 目錄是 700, 檔案是 600 Server 設定 RSAAuthentication yes PubkeyAuthentication yes...