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

📄 protocol.c

📁 linux下的飞鸽传书 日本人设计 使用非常方便
💻 C
📖 第 1 页 / 共 2 页
字号:
  rc=construct_message(base,NULL,&msg,&len);  if (rc<0)    return rc;  rc=udp_send_message(con,ipaddr,hostinfo_refer_ipmsg_port(),msg,len);  free(msg);  if (rc<0)    return rc;  return 0;}intipmsg_send_get_info_msg(const udp_con_t *con,const char *ipaddr,unsigned long command){  char base[IPMSG_BUFSIZ];  char *send_string=NULL;  size_t len;  int rc;  if ( (!con) || (!ipaddr) || ( (command != IPMSG_GETINFO) && (command != IPMSG_GETABSENCEINFO) ) )    return -EINVAL;  memset(base,0,IPMSG_BUFSIZ);  snprintf(base,IPMSG_BUFSIZ-1,MSG_GETINFO_STRING,ipmsg_get_pkt_no(),hostinfo_refer_user_name(),hostinfo_refer_host_name(),command);  rc=construct_message(base,NULL,&send_string,&len);  if (rc<0)    return rc;  rc=udp_send_message(con,ipaddr,hostinfo_refer_ipmsg_port(),send_string,len);  free(send_string);  if (rc<0)    return rc;  return 0;}intipmsg_send_send_msg(const udp_con_t *con,const char *ipaddr,int flags,int pkt_no,const char *message,const char *ext_part){  int rc;  size_t len;  char *send_string=NULL;  gchar *internal_message=NULL;  if ( (!con) || (!ipaddr) || (!message) )    return -EINVAL;  if ( (flags & IPMSG_FILEATTACHOPT) && (!ext_part) )    return -EINVAL;      if (flags & IPMSG_FILEATTACHOPT)    rc=ipmsg_construct_file_attach_message(message,ext_part,flags,&len,&send_string,pkt_no);  else    rc=ipmsg_construct_normal_message(message,flags,&len,&send_string,pkt_no);  if (rc<0){    if (send_string)      free(send_string);    return rc;  }  dbg_out("send message to %s:%s\n",ipaddr,send_string);  rc=register_sent_message(con,ipaddr,pkt_no,send_string,len);  if (rc<0) {    rc *= -1;    err_out("Can not register message:%s (%d)\n",strerror(rc),rc);    return -rc;  }  rc=udp_send_message(con,ipaddr,hostinfo_refer_ipmsg_port(), send_string,len);  if (rc<0) {    rc*=-1;    err_out("Can not send: %s %d\n",strerror(rc),rc);    goto err_out;  }  convert_string_internal(message,(const gchar **)&internal_message);  if (internal_message) {    logfile_send_log(ipaddr,internal_message);    g_free(internal_message);  }  rc=0; err_out:  free(send_string);  return rc;}intipmsg_proc_br_absence(const udp_con_t *con,const msg_data_t *msg){  dbg_out("\nNew user: \n\tUser:%s Host: %s\n\tNickName: %s GroupName:%s\n",	  refer_user_name_from_msg(msg),	  refer_host_name_from_msg(msg),	  refer_nick_name_from_msg(msg),	  refer_group_name_from_msg(msg));  userdb_update_user(con,msg);  userdb_print_user_list();  return 0;}intipmsg_proc_br_entry(const udp_con_t *con,const msg_data_t *msg) {  int rc=0;  ipmsg_send_ans_entry(con,0);  rc=userdb_add_user(con,msg);  if (rc == -EEXIST)    rc=userdb_update_user(con,msg);  userdb_print_user_list();  return rc;}intipmsg_proc_br_exit(const udp_con_t *con,const msg_data_t *msg) {  dbg_out("\nLeave user: \n\tUser:%s Host: %s\n\tNickName: %s GroupName:%s\n",	  refer_user_name_from_msg(msg),	  refer_host_name_from_msg(msg),	  refer_nick_name_from_msg(msg),	  refer_group_name_from_msg(msg));  userdb_del_user(con,msg);  userdb_print_user_list();  return 0;}intipmsg_proc_ans_entry(const udp_con_t *con,const msg_data_t *msg) {  dbg_out("\nNew user: \n\tUser:%s Host: %s\n\tNickName: %s GroupName:%s\n",	  refer_user_name_from_msg(msg),	  refer_host_name_from_msg(msg),	  refer_nick_name_from_msg(msg),	  refer_group_name_from_msg(msg));  userdb_add_user(con,msg);  userdb_print_user_list();  return 0;}intipmsg_proc_send_msg(const udp_con_t *con,const msg_data_t *msg) {  gchar *internal_message=NULL;  int flags;  if ( (msg->command_opts & IPMSG_SENDCHECKOPT) &&        (!(msg->command_opts & IPMSG_NO_REPLY_OPTS)) ) {    dbg_out("Send check opt is enabled\n");    ipmsg_send_recv_msg(con,msg);  }  dbg_out("\nmessage:\n%s\n",msg->message);  convert_string_internal(msg->message,(const gchar **)&internal_message);  if (internal_message) {    if (!(msg->command_opts & IPMSG_NOLOGOPT))      logfile_recv_log(udp_get_peeraddr(con),internal_message);    g_free(internal_message);  }  if (hostinfo_is_ipmsg_absent()){    flags=hostinfo_get_normal_send_flags();    if (hostinfo_refer_ipmsg_default_secret())      flags |= IPMSG_SECRETOPT;    if (!(msg->command_opts & IPMSG_NO_REPLY_OPTS))      ipmsg_send_absent_msg(con,flags);  }  if (hostinfo_refer_ipmsg_default_popup()) /* if it is set, should not pop-up the win */    store_message_window(msg,udp_get_peeraddr(con));  else    recv_message_window(msg,udp_get_peeraddr(con));  return 0;}intipmsg_proc_read_msg(const udp_con_t *con,const msg_data_t *msg) {  long pktno;  gchar *user;  struct timeval tv;  gettimeofday(&tv, NULL);  pktno=strtol(msg->message, (char **)NULL, 10);  dbg_out("read mssage:seq %ld\n",pkt_no);  /* TODO:開封確認 */  dbg_out("read mssage:seq %s\n",msg->message);  user=strdup(refer_user_name_from_msg(msg));  /*  メモリ不足の場合はNULLを送信。処理は受け手で考える  */  read_message_dialog(user,udp_get_peeraddr(con),tv.tv_sec);  return 0;}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)    err_out("Can not release attach file information:pktno=%d %s (%d)\n",pktno,strerror(-rc),-rc);  return rc;}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);    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);    free (absent_message_proto);  }  rc=construct_message(base,NULL,&msg,&len);  if (rc<0)    return rc;  udp_send_peer(con,msg,len);  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);  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=ipmsg_send_get_list(udp_con,udp_get_peeraddr(con),0);  //udp_send_peer(con,message,len);  rc=udp_send_message(udp_con,udp_get_peeraddr(con),hostinfo_refer_ipmsg_port(),message,len);  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)     free(string);  rc=udp_send_peer(con,message,len);  if (rc<0)    goto free_message_out;    dbg_out("return:%s\n",message);  free(message);  return 0; free_string_out:  if (string)     free(string); free_message_out:  if (message)     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=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=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");    if (hostinfo_refer_ipmsg_is_get_hlist())      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;  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 + -