📄 simple.c
字号:
shell_exec_status = (int)ShellExecute(NULL, "open", gag_path, "-l", NULL, 0); /* If that fails, see if it's in the path somewhere. */ if (shell_exec_status <= 32) { shell_exec_status = (int)ShellExecute(NULL, "open", "gag.exe", "-l", NULL, 0); } /* Well, if we can't find the gag.exe binary, we can't continue. */ if (shell_exec_status <= 32) { gaim_connection_error(gc, _("Unable to start the SIP engine - gag.exe is not in your path")); close(listenfd); return; } gagfd = accept(listenfd, (struct sockaddr *)&them, &addr_len); if (gagfd < 0) { gaim_connection_error(gc, _("Unable to start the SIP engine - " "Could not accept incoming loopback connection")); close(listenfd); return; } close (listenfd); }#else { int fork_result; if ( (pipe(gaimtogag)!=0) || (pipe(gagtogaim)!=0) ) { gaim_connection_error(gc, _("Unable to start the SIP engine - resources unavailable")); return; } if ( (fork_result = fork()) == -1 ) { gaim_connection_error(gc, _("Unable to start the SIP engine - process unavailable")); return; } if (fork_result == 0) { /* We are the child Read from gaim using gaimtogag[0] Write to gaim using gagtogaim[1] */ close(0); close(1); dup(gaimtogag[0]); /* new 0 */ close(gaimtogag[0]); close(gaimtogag[1]); dup(gagtogaim[1]); /* new 1 */ close(gagtogaim[0]); close(gagtogaim[1]); execlp("gag","gag", (char*)0); /* if we're here, exec went horribly wrong */ { int t,l; char v; t=2; l=1; v=0; write (1,(void *)&t,sizeof(int)); write (1,(void *)&l,sizeof(int)); write (1,(void *)&v,1); } _exit(-1); } }#endif /* In the parent Read from gag using FD_GAG_TO_GAIM Write to gag using FD_GAIM_TO_GAG */ gaim_debug(GAIM_DEBUG_INFO,"sippy","starting sanity check\n"); sane = 1; read(FD_GAG_TO_GAIM,sanity_check_buffer,sizeof(int)); sane = (*((int*)sanity_check_buffer)==2); if (sane) { read(FD_GAG_TO_GAIM,sanity_check_buffer,sizeof(int)); sane = (*((int*)sanity_check_buffer)==1); } if (sane) { read(FD_GAG_TO_GAIM,sanity_check_buffer,1); sane = ((*sanity_check_buffer)!=0x00); } if (!sane) { return; } gaim_debug(GAIM_DEBUG_INFO,"sippy","gag is sane\n"); gaginitialized = 1;}static struct simple_friend_cache *simple_friend_cache_new(){ struct simple_friend_cache *retval; retval = g_new0(struct simple_friend_cache, 1); return retval;}static voidsimple_friend_cache_free(gpointer gp){ struct simple_friend_cache *f = gp; if (f) { if (f->status_string) g_free(f->status_string); g_free(f); }}static voidsippy_login(GaimAccount *account){ char *sipAccountURI = NULL; GaimConnection *gc = gaim_account_get_connection(account); if (gaim_connection_get_state(gc) == GAIM_CONNECTED) { gaim_debug(GAIM_DEBUG_INFO,"sippy","Somebody's trying to login to something that's already connected - ignoring the request\n"); return; } /* * Do a safety check on the account name */ if (isAccountNameUnsafe(account->username)) { gaim_connection_error(gc, _("Login not attempted - The account name is unacceptable")); g_free(sipAccountURI); return; } sipAccountURI = buildSIPURI(account->username); struct simple_connection_cache *sc_cache; if (gc->proto_data == NULL) { gaim_debug(GAIM_DEBUG_INFO,"sippy","Creating new simple cache\n"); sc_cache = gc->proto_data = g_new0(struct simple_connection_cache,1); } else { /* I don't think this will ever happen - RjS */ gaim_debug(GAIM_DEBUG_INFO,"sippy","Reusing old simple cache\n"); sc_cache = gc->proto_data; } if (sc_cache->friends != NULL) { /* Likewise, I don't think this will ever happen - RjS */ gaim_debug(GAIM_DEBUG_INFO,"sippy","Destroying old simple friend list\n"); g_hash_table_destroy(sc_cache->friends); } sc_cache->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, simple_friend_cache_free); if (!gaginitialized) { gaim_debug(GAIM_DEBUG_INFO,"sippy","Initializing gag\n"); init_gag(gc); } if (!gaginitialized) { gaim_connection_error(gc, _("Unable to start the SIP engine - SIP engine not found")); g_free(sipAccountURI); return; } gaim_connection_update_progress(gc,"Connecting",0,2); /* send the login stuff (aor,userid,password) */ sippy_send_command( SIMPLE_LOGIN ); gaim_debug(GAIM_DEBUG_INFO,"sippy","Sending aor [%s]\n",sipAccountURI); sippy_send_string( sipAccountURI ); /* This assumes the digest username is always equal * to the user part of the AOR */ gaim_debug(GAIM_DEBUG_INFO,"sippy","Sending username [%s]\n",account->username); sippy_send_string( account->username ); gaim_debug(GAIM_DEBUG_INFO,"sippy","Sending password [%s]\n",account->password); sippy_send_string( account->password ); gaim_debug(GAIM_DEBUG_INFO,"sippy", "Sending register_with_service flag [%s]\n", (gaim_account_get_bool(account,"register_with_service",TRUE) ?"true":"false")); sippy_send_bool(gaim_account_get_bool(account,"register_with_service",TRUE)); gaim_debug(GAIM_DEBUG_INFO,"sippy", "Sending publish_to_service flag [%s]\n", (gaim_account_get_bool(account,"publish_to_service",TRUE) ?"true":"false")); sippy_send_bool(gaim_account_get_bool(account,"publish_to_service",TRUE)); if (gc->inpa!=0) { /* I don't think this will ever happen, and it points out a huge issue with the current plumbing - trying to login to two SIPPY accounts _will_ cause the gagtogaim fd to get put on gaim's input queue twice, with different gc's - the callbacks are going to happen with very wrong contexts */ gaim_debug(GAIM_DEBUG_INFO,"sippy","Removing old simple gaim_input\n"); gaim_input_remove(gc->inpa); } gaim_debug(GAIM_DEBUG_INFO,"sippy","Adding gag's simple gaim_input\n"); gc->inpa = gaim_input_add(FD_GAG_TO_GAIM,GAIM_INPUT_READ,sippy_recv_cb,gc); g_free(sipAccountURI);}static int sippy_send_im(GaimConnection *gc, const char *who, const char *what, GaimConvImFlags flags){ const char* from = gc->account->username; const char* to = who; const char* im = what; assert( FD_GAIM_TO_GAG ); sippy_send_command( SIMPLE_IM ); sippy_send_string( to ); sippy_send_string( from ); sippy_send_string( im ); /* m=g_strdup_printf("I saw '%s'",what); serv_got_im(gc,who,m,0,time(NULL)); g_free(m);*/ return 1;}static void sippy_set_presence(GaimConnection *gc, const char *state, const char *msg){ if (!gaginitialized) {return;} if (gc->away) { g_free(gc->away); gc->away = NULL; } if (msg) { gc->away = g_strdup(msg); } gaim_debug(GAIM_DEBUG_INFO,"sippy","sending PRESENCE to us=%s open=%d msg=%s\n",gc->account->username, *state, msg); sippy_send_command( SIMPLE_PRESENCE ); sippy_send_string( gc->account->username ); sippy_send_bool( (unsigned char)(*open) ); sippy_send_string( msg );}static char *simple_status_text(GaimBuddy *b){ struct simple_connection_cache *sc_cache = (struct simple_connection_cache *)b->account->gc->proto_data; struct simple_friend_cache *fc = g_hash_table_lookup(sc_cache->friends,b->name); return ( fc ? g_strdup(fc->status_string) : g_strdup(_("Unknown")) ); /* Probably want NULL instead of a copy of "Unknown" */}static char *simple_tooltip_text(GaimBuddy *b){ return simple_status_text(b);}static GaimPluginProtocolInfo prpl_info ={ 5, /* API version number */ /* GaimProtocolOptions */ OPT_PROTO_PASSWORD_OPTIONAL, NULL, /* user_splits */ NULL, /* protocol_options */ NO_BUDDY_ICONS, /* icon_spec */ sippy_list_icon, /* list_icon */ NULL, /* list_emblems */ simple_status_text, /* status_text */ simple_tooltip_text, /* tooltip_text */ NULL, /* away_states */ NULL, /* blist_node_menu */ NULL, /* chat_info */ sippy_login, /* login */ sippy_logout, /* close */ sippy_send_im, /* message_send_im */ NULL, /* set_info */ NULL, /* send_typing */ NULL, /* get_info */ sippy_set_presence, /* set_away */ NULL, /* set_idle */ NULL, /* change_passwd */ sippy_add_buddy, /* add_buddy */ NULL, /* add_buddies */ sippy_remove_buddy, /* remove_buddy */ NULL, /* remove_buddies */ NULL, /* add_permit */ NULL, /* add_deny */ NULL, /* rem_permit */ NULL, /* rem_deny */ NULL, /* set_permit_deny */ NULL, /* warn */ NULL, /* join_chat */ NULL, /* reject_chat */ NULL, /* chat_invite */ NULL, /* chat_leave */ NULL, /* chat_whisper */ NULL, /* chat_send */ NULL, /* keepalive */ NULL, /* register_user */ NULL, /* get_cb_info */ NULL, /* get_cb_away */ NULL, /* alias_buddy */ NULL, /* group_buddy */ NULL, /* rename_group */ NULL, /* buddy_free */ NULL, /* convo_closed */ /* XXX: thread_ids */ NULL, /* normalize */ NULL, /* set_buddy_icon */ NULL, /* remove_group */ NULL, /* get_cb_real_name */ NULL, /* set_chat_topic */ NULL, /* find_blist_chat */ NULL, /* roomlist_get_list */ NULL, /* roomlist_cancel */ NULL /* roomlist_expand_category */};static GaimPluginInfo info ={ 4, /**< api_version */ GAIM_PLUGIN_PROTOCOL, /**< type */ NULL, /**< ui_requirement */ 0, /**< flags */ NULL, /**< dependencies */ GAIM_PRIORITY_DEFAULT, /**< priority */ "prpl-simple", /**< id */ "SIP/SIMPLE", /**< name */ VERSION, /**< version */ /** summary */ N_("SIP/SIMPLE Protocol Plugin"), /** description */ N_("SIP/SIMPLE Protocol Plugin"), NULL, /**< author */ GAIM_WEBSITE, /**< homepage */ NULL, /**< load */ sippy_unload_plugin, /**< unload */ NULL, /**< destroy */ NULL, /**< ui_info */ &prpl_info, /**< extra_info */ NULL, /**< prefs_info */ NULL /**< actions */};static voidinit_plugin(GaimPlugin *plugin){/* GaimAccountUserSplit *split;*/ GaimAccountOption *option;/* split = gaim_account__split_new(_("Scheme"), "sip", ':'); prpl_info.user_splits = g_list_prepend(prpl_info.user_splits, split); split = gaim_account_user_split_new(_("Server"), "iptel.org", '@'); prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);*//* option = gaim_account_option_string_new(_("Display Name"), "display_name", NULL); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = gaim_account_option_string_new(_("Digest Username"), "digest_username", NULL); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = gaim_account_option_string_new(_("Digest Realm"), "digest_realm", NULL); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = gaim_account_option_string_new(_("Transport"), "transport_protocol", "TCP"); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = gaim_account_option_int_new(_("Port"), "port", 5060); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);*/ option = gaim_account_option_bool_new(_("Register with this service"), "register_with_service", TRUE ); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = gaim_account_option_bool_new(_("Publish presence to this service"), "publish_to_service", TRUE ); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); my_protocol = plugin; gaim_prefs_add_none("/plugins/prpl/simple");}GAIM_INIT_PLUGIN(simple, init_plugin, info);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -