Archive

Posts Tagged ‘IM’

调整im 机器人的数据发送方式

June 24th, 2009 陈毓端 No comments

之前的im机器人是用c的system调用shell的curl来实现数据传送。测试了两天感觉上不是很舒服。决定调整为c的libcurl API发送数据。
就这个小小的调整,涉及到一堆的修改。
最主要的如下:
1 制作 curl发送的动态链接库 so文件
2 修改im机器人的makefile 文件

curl 发送的so动态连接库:
curl_so_head.h
#include “stdio.h”
#include “curl/curl.h”
#include “stdlib.h”
#include “string.h”
#include “dlfcn.h”
void c2(char *msg,char *from,char *robot); // 设置了msg:消息 from:来源 robot:机器人类型

curl_so.c

#include “curl_so_head.h”
void c2(char *msg,char *from,char *robot)
{
CURL *curl;
CURLcode res;
char *s=”&msg=”;
char *s1=”&from=”;
char *s2=”&robot=”;
char pp[200];
strcpy(pp,s);
strcat(pp,msg);
strcat(pp,s1);
strcat(pp,from);
strcat(pp,s2);
strcat(pp,robot);

curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL,”http://xxxx.xxx.xxx.php”);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,pp);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}

}
这个是发送调用程序:

void *SoLib;
int (*So)();
SoLib=dlopen(“so_curl.so”,RTLD_LAZY); //so_curl.so是上面操作生成的so文件
So = dlsym( SoLib, “c2″);
(*So)( msg,from,robot); //msg,from,robot表示需要的 消息 来源 robot 机器人类型

修改makefile文件 主要是要在 gcc 后面加上 -ldl 参数 .

ok 目前这项应用就到此吧。后期可能还要加新东西。

Categories: linux, 编程语言 Tags: , , ,

SNS IM 机器人阶段性成果

June 10th, 2009 陈毓端 No comments

截至昨天,经过一段时间的专研msn 以及国内某一垄断的im的机器人昨天已经突破了各个技术节点,下一步整合项目应用。还需努力,力争提供方便快捷,友好的消息分享于获取通道。

Categories: linux, 愤青牢骚 Tags: , ,