⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocol.c

📁 Linux下的飞鸽传书
💻 C
📖 第 1 页 / 共 3 页
字号:
  return 0;}static intipmsg_proc_anspubkey(const udp_con_t *con,const msg_data_t *msg){  int rc;  char *pubkey_e=NULL;  char *pubkey_n=NULL;  const char *ipaddr=NULL;  unsigned long peer_cap;  if ( (!con) || (!msg) )    return -EINVAL;#if defined(USE_OPENSSL)  rc=pcrypt_crypt_parse_anspubkey(msg->message,				  &peer_cap,				  (unsigned char **)&pubkey_e,				  (unsigned char **)&pubkey_n);  if (rc) {    dbg_out("Can not parse anspub key message:rc=%d\n",rc);    goto error_out;  }  ipaddr=udp_get_peeraddr(con);  if (!ipaddr)    goto error_out;  rc=userdb_replace_public_key_by_addr(ipaddr,peer_cap,pubkey_e,pubkey_n);  if (rc) {    dbg_out("Can register parse anspub key message:rc=%d\n",rc);    goto error_out;  }  if (pubkey_e)    g_free(pubkey_e);  if (pubkey_n)    g_free(pubkey_n);#else  rc=-ENOSYS;#endif error_out:  return rc;  }static intipmsg_proc_release_files_msg(const udp_con_t *con,const msg_data_t *msg) {  int pktno;  int rc;  pktno=(int)strtol(msg->message, (char **)NULL, 10);  dbg_out("release files mssage:seq %d(%s)\n",pktno,msg->message);  rc = release_attach_file_block(pktno,FALSE);  if (rc < 0) {    dbg_out("Can not release attach file information:pktno=%d %s (%d)", 	    pktno, strerror(-rc), -rc);    //    ipmsg_err_dialog(_("Can not release attach file information:pktno=%d %s (%d)"),pktno,strerror(-rc),-rc);  }  return rc;}static intipmsg_proc_get_public_key(const udp_con_t *con,const msg_data_t *msg) {  unsigned long peer_cap;  char *ans_msg=NULL;  char base[IPMSG_BUFSIZ];  int index;  char *message=NULL;  size_t len;  int rc;  dbg_out("here\n");#if defined(USE_OPENSSL)  peer_cap=(int)strtoul(msg->message, (char **)NULL, 16);  dbg_out("Get public key:peer capability %x(%s)\n",peer_cap,msg->message);  rc=pcrypt_crypt_generate_anspubkey_string(peer_cap,(const char **)&ans_msg);  if (rc) {    if (ans_msg)      g_free(ans_msg);    return rc;  }  memset(base,0,IPMSG_BUFSIZ);  snprintf(base,IPMSG_BUFSIZ-1,MSG_STRING_INFOMSG,ipmsg_get_pkt_no(),hostinfo_refer_user_name(),hostinfo_refer_host_name(),(IPMSG_ANSPUBKEY),ans_msg);  if (ans_msg){    g_free(ans_msg);    ans_msg=NULL;  }  rc=construct_message(base,NULL,&message,&len);  if (rc<0)    return rc;  udp_send_peer(con,message,len);  g_free(message);#else  rc=-ENOSYS;#endif   error_out:  return rc;}static intipmsg_proc_recv_msg(const udp_con_t *con,const msg_data_t *msg) {  long pktno;  if ( (!msg) ||  (!(msg->message)))    return -EINVAL;  pktno=(long)strtol(msg->message, (char **)NULL, 10);  dbg_out("recv mssage:seq %ld\n",pkt_no);  unregister_sent_message(pktno);  return 0;}static intipmsg_proc_get_absence_info(const udp_con_t *con,const msg_data_t *orig_msg){  char base[IPMSG_BUFSIZ];  char *absent_message=NULL;  gchar *absent_message_proto=NULL;  int index;  char *msg=NULL;  size_t len;  int rc;  dbg_out("here\n");  memset(base,0,IPMSG_BUFSIZ);  if (hostinfo_is_ipmsg_absent()) {    if (!hostinfo_get_absent_id(&index)) {      hostinfo_get_absent_message(index,(const char **)&absent_message);      g_assert (absent_message);    }    convert_string_ipmsg_proto(absent_message,(const gchar **)&absent_message_proto);    g_free(absent_message);  }else{    absent_message=_("I am here.");    convert_string_ipmsg_proto(absent_message,(const gchar **)&absent_message_proto);  }  g_assert (absent_message_proto);    if (absent_message_proto) {    snprintf(base,IPMSG_BUFSIZ-1,MSG_STRING_INFOMSG,ipmsg_get_pkt_no(),hostinfo_refer_user_name(),hostinfo_refer_host_name(),(IPMSG_AUTORETOPT|IPMSG_SENDABSENCEINFO),absent_message_proto);    g_free (absent_message_proto);  }  rc=construct_message(base,NULL,&msg,&len);  if (rc<0)    return rc;  udp_send_peer(con,msg,len);  g_free(msg);  return 0;}static intipmsg_proc_send_version_info(const udp_con_t *con,const msg_data_t *orig_msg){  char base[IPMSG_BUFSIZ];  char ver[IPMSG_BUFSIZ];  int index;  char *message=NULL;  char *string=NULL;  size_t len;  int rc;  dbg_out("here\n");  memset(base,0,IPMSG_BUFSIZ);  memset(ver,0,IPMSG_BUFSIZ);  snprintf(ver,IPMSG_BUFSIZ-1,"GNOME2 %s (%s)\n%s:%s",_("Edition"),PACKAGE,_("Version"),VERSION);  rc=convert_string_ipmsg_proto(ver,(const gchar **)&string);  if (rc<0)    return rc;  snprintf(base,IPMSG_BUFSIZ-1,MSG_STRING_INFOMSG,ipmsg_get_pkt_no(),hostinfo_refer_user_name(),hostinfo_refer_host_name(),(IPMSG_AUTORETOPT|IPMSG_SENDINFO),string);  g_free(string);  rc=construct_message(base,NULL,&message,&len);  if (rc<0)    return rc;  udp_send_peer(con,message,len);  g_free(message);  return 0;}static intipmsg_proc_br_isgetlist2(const udp_con_t *con,const msg_data_t *msg){  char base[IPMSG_BUFSIZ];  char ver[IPMSG_BUFSIZ];  size_t len;  char *message=NULL;  int rc;  dbg_out("here\n");  if ( (!con) || (!msg) )    return -EINVAL;  memset(base,0,IPMSG_BUFSIZ);  snprintf(base,IPMSG_BUFSIZ-1,MSG_STRING_INFOMSG,ipmsg_get_pkt_no(),hostinfo_refer_user_name(),hostinfo_refer_host_name(),IPMSG_OKGETLIST,"");  rc=construct_message(base,NULL,&message,&len);  if (rc<0)    return rc;  dbg_out("isgetlist2 reply message :%s\n",message);  rc=udp_send_message(udp_con,udp_get_peeraddr(con),hostinfo_refer_ipmsg_port(),message,len);  g_free(message);  return 0;}static intipmsg_proc_getlist(const udp_con_t *con,const msg_data_t *msg){  char base[IPMSG_BUFSIZ];  char ver[IPMSG_BUFSIZ];  int length;  char *string=NULL;  gchar *exd_string=NULL;  unsigned long flags=0;  int index;  int start;  char *message=NULL;  size_t len;  int rc;  dbg_out("here\n");  if ( (!con) || (!msg) )    return -EINVAL;  length=G2IPMSG_DEFAULT_HOST_LIST_LEN;  start=0;  start=strtol(msg->message, (char **)NULL, 10);  dbg_out("require:%d(%s)\n",start,msg->message);  userdb_get_hostlist_string(start,&length, (const char **)&string,&flags);  dbg_out("return:%s\n",string);  rc=convert_string_ipmsg_proto(string,(const gchar **)&exd_string);  if (rc<0)    goto free_string_out;  memset(base,0,IPMSG_BUFSIZ);  snprintf(base,IPMSG_BUFSIZ-1,MSG_STRING_INFOMSG,ipmsg_get_pkt_no(),hostinfo_refer_user_name(),hostinfo_refer_host_name(),IPMSG_ANSLIST,exd_string);  g_free(exd_string);  rc=construct_message(base,NULL,&message,&len);  if (rc<0)    goto free_string_out;  dbg_out("send:%s\n",message);  if (string)     g_free(string);  rc=udp_send_peer(con,message,len);  if (rc<0)    goto free_message_out;    dbg_out("return:%s\n",message);  g_free(message);  return 0; free_string_out:  if (string)     g_free(string); free_message_out:  if (message)     g_free(message);  return rc;}static intipmsg_proc_anslist(const udp_con_t *con,const msg_data_t *msg){  int rc;  if ( (!con) || (!msg) )    return -EINVAL;  rc=userdb_hostlist_answer_add(con,msg);  return rc;}static intipmsg_proc_okgetlist(const udp_con_t *con,const msg_data_t *msg){  char base[IPMSG_BUFSIZ];  char ver[IPMSG_BUFSIZ];  size_t len;  char *message=NULL;  int rc;  long pktno;  dbg_out("here\n");  if ( (!con) || (!msg) )    return -EINVAL;  dbg_out("OK_GETLIST from %s.\n",udp_get_peeraddr(con));  rc=ipmsg_send_get_list(udp_con,udp_get_peeraddr(con),0);  return rc;}intipmsg_proc_send_info(const udp_con_t *con,const msg_data_t *msg) {  gchar *user;  dbg_out("send info:version %s\n",msg->message);  user=g_strdup(refer_user_name_from_msg(msg));  /*  メモリ不足の場合はNULLを送信。処理は受け手で考える  */  info_message_window(user,udp_get_peeraddr(con),IPMSG_SENDINFO,msg->message);  return 0;}intipmsg_proc_send_absence_info(const udp_con_t *con,const msg_data_t *msg) {  gchar *user;  dbg_out("send absence info:version %s\n",msg->message);  user=g_strdup(refer_user_name_from_msg(msg));  /*  メモリ不足の場合はNULLを送信。処理は受け手で考える  */  info_message_window(user,udp_get_peeraddr(con),IPMSG_SENDABSENCEINFO,msg->message);  return 0;}intipmsg_dispatch_message(const udp_con_t *con,const msg_data_t *msg){    if ( (!con) || (!msg) )    return -EINVAL;  switch(msg->command) {  case IPMSG_NOOPERATION:    break;  case IPMSG_BR_ENTRY:    dbg_out("Dispatch br_entry\n");    ipmsg_proc_br_entry(con,msg);    break;  case IPMSG_BR_EXIT:    dbg_out("Dispatch br_exit\n");    ipmsg_proc_br_exit(con,msg);    break;  case IPMSG_ANSENTRY:    dbg_out("Dispatch ans_entry\n");    ipmsg_proc_ans_entry(con,msg);    break;  case IPMSG_BR_ABSENCE:    dbg_out("Dispatch br_absense\n");    ipmsg_proc_br_absence(con,msg);    break;  case IPMSG_BR_ISGETLIST:    dbg_out("Dispatch isget_list2\n");    if (hostinfo_refer_ipmsg_is_allow_hlist())      ipmsg_proc_br_isgetlist2(con,msg);    break;  case IPMSG_OKGETLIST:    dbg_out("Dispatch okget_list\n");    if (hostinfo_refer_ipmsg_is_get_hlist())          ipmsg_proc_okgetlist(con,msg);    break;  case IPMSG_GETLIST:    dbg_out("Dispatch get_list\n");    if (hostinfo_refer_ipmsg_is_allow_hlist())      ipmsg_proc_getlist(con,msg);    else      dbg_out("Discard getlist request\n");    break;  case IPMSG_ANSLIST:    dbg_out("Dispatch ans_list\n");    ipmsg_proc_anslist(con,msg);    break;  case IPMSG_BR_ISGETLIST2:    dbg_out("Dispatch br_isget_list2\n");    if (hostinfo_refer_ipmsg_is_allow_hlist())      ipmsg_proc_br_isgetlist2(con,msg);    break;  case IPMSG_SENDMSG:    dbg_out("Dispatch send_message\n");    ipmsg_proc_send_msg(con,msg);    break;  case IPMSG_RECVMSG:    dbg_out("Dispatch recv_message\n");    ipmsg_proc_recv_msg(con,msg);    break;  case IPMSG_READMSG:    dbg_out("Dispatch read_message\n");    ipmsg_proc_read_msg(con,msg);    break;  case IPMSG_DELMSG:    dbg_out("Dispatch delete_message\n");    break;  case IPMSG_ANSREADMSG:    dbg_out("Dispatch ans_read_message\n");    break;  case IPMSG_GETINFO:    dbg_out("Dispatch get_info\n");    ipmsg_proc_send_version_info(con,msg);    break;  case IPMSG_SENDINFO:    dbg_out("Dispatch send_info\n");    ipmsg_proc_send_info(con,msg);    break;  case IPMSG_GETABSENCEINFO:    dbg_out("Dispatch get_absence_info\n");    ipmsg_proc_get_absence_info(con,msg);    break;  case IPMSG_SENDABSENCEINFO:    dbg_out("Dispatch send_absence_info\n");    ipmsg_proc_send_absence_info(con,msg);    break;  case IPMSG_RELEASEFILES:    dbg_out("Dispatch release files\n");    ipmsg_proc_release_files_msg(con,msg);    break;  case IPMSG_GETPUBKEY:    dbg_out("Dispatch get public key\n");    ipmsg_proc_get_public_key(con,msg);    break;  case IPMSG_ANSPUBKEY:    dbg_out("Dispatch ans public key\n");    ipmsg_proc_anspubkey(con,msg);    break;  default:    dbg_out("Can not dispatch unknown:%x\n",msg->command);    /* Unknown command */    break;  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -