Example #1
0
void recoverFromSpecialList(gchar *str)
{
    struct sockaddr_in addr ;
    LinpopUser *temp = g_malloc(sizeof(*temp));
    gboolean result;
    char ip[16];
    int i;
    bzero(ip,sizeof(ip));
    g_print("str:%s\n",str);
    for(;*str != '(';str++);
    g_print("str2:%s\n",str);
    for(++str,i = 0;*str != ')';str++,i++)
        ip[i] = *str;
    g_print("ip:%s\n",ip);
    inet_aton(ip,&addr.sin_addr);
    result = getUserByIP(addr,temp);
    g_print("%d",result);
    if(result == FALSE){
        g_print("No user at %s,cannot create chat window",ip);
        g_free(temp);
        return ;
    }
    setGroup(addr,temp->machine);
    listRefresh();
    freeUser(temp);
	//extern struct userinfo *head;
	//struct userinfo *p = head;
}
Example #2
0
void singleTalk(gchar *str)
{
    struct sockaddr_in addr ;
    LinpopUser *temp = g_malloc(sizeof(*temp));
    gboolean result;
    char ip[16];
    int i;
    bzero(ip,sizeof(ip));
    g_print("str:%s\n",str);
    for(;*str != '(';str++);
    g_print("str2:%s\n",str);
    for(++str,i = 0;*str != ')';str++,i++)
        ip[i] = *str;
    g_print("ip:%s\n",ip);
    inet_aton(ip,&addr.sin_addr);
    result = getUserByIP(addr,temp);
    g_print("%d",result);
    if(result == FALSE){
        g_print("No user at %s,cannot create chat window",ip);
        g_free(temp);
        return ;
    }
    createChatWindow(inet_ntoa(temp->from.sin_addr),temp->user,SHOW);
    freeUser(temp);
	//extern struct userinfo *head;
	//struct userinfo *p = head;
}
Example #3
0
PUBLIC int websRemoveUser(char *username) 
{
    WebsKey     *key;
    
    assure(username && *username);
    if ((key = hashLookup(users, username)) != 0) {
        freeUser(key->content.value.symbol);
    }
    return hashDelete(users, username);
}
Example #4
0
void sendEchoToTextView(GtkWidget *widget,gpointer ip){
     struct sockaddr_in addr;
     LinpopChat chat;
     gboolean result;
     LinpopUser *user ;
     size_t sizeText,sizeMsg;
     gchar *text = NULL;
     gchar *s,*t;
     inet_aton(ip,&addr.sin_addr);
     result = getChatByIP(addr,&chat);
     GtkTextBuffer *buffer = NULL;
     GtkTextIter start,end;
     assert(result == TRUE);
     buffer = gtk_text_view_get_buffer(chat.inputTextView);
     gtk_text_buffer_get_bounds(buffer,&start,&end);
     text = gtk_text_buffer_get_text(buffer,&start,&end,FALSE);
    
    for(sizeMsg = 0,t = chat.msg; *t;t++){
        if(*t == '\\'){
	    if(*(t+1) == '\\'){
	        sizeMsg++;
	    }
	    t++;
	}else{
	    sizeMsg++;
	}
    }
    for(s = text + sizeMsg;*s;s++,t++){
        if(*s == '\\'){
	    *t++ = '\\';
	    *t = '\\'; 
	}else{
	    *t = *s;
	}
    }
    *t = '\0';
         if(chat.msg[0] == '\0'){
	     printInfoToTextView(chat.showTextView,option.user,"Don`t send empty message!");
	     return ;
	  }
         user = g_malloc(sizeof(*user));
	 result = getUserByIP(addr,user);
	 assert(result == TRUE);
	 g_print("chat.msg is:%s\n",chat.msg);
	 printEchoToTextView(chat.showTextView,option.user,chat.msg);
	 LinpopTimeoutSend(user->from,chat.msg,LINPOP_SENDMSG);
	 chat.msg[0] = '\0';
	 clearTextView(chat.inputTextView);
	 freeUser(user);
     return ;
}
Example #5
0
void lin_refresh(void)
{
  	
    GtkTreeStore *treestore;
    GtkTreeIter toplevel, child;
	remove_all();
	treestore = GTK_TREE_STORE(gtk_tree_view_get_model(
       		GTK_TREE_VIEW(view)));
    gchar *p = NULL;
    gchar *q = NULL;
    struct sockaddr_in addr;
    int i,j;
    GList *group = NULL;
    GList *user = NULL;
    LinpopUser *temp ;
    char buf[256];
    gboolean result;
    //userListForeach(printUser,NULL);
    for(group = getGroupList();group != NULL;group = group->next){
        p = (gchar *)group->data;
	gtk_tree_store_append(treestore, &toplevel, NULL);
	gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
        g_print("group:%s\n",p);
	for(user = getGroupUserList(p);user != NULL;user = user->next){
	    /*    q = (gchar *)user->data;
		gtk_tree_store_append(treestore, &child, &toplevel);
		gtk_tree_store_set(treestore, &child,COLUMN,q,-1); 
                g_print("user:%s\n",q);*/
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("q is:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1); 
            g_print("user:%s\n",q);
            freeUser(temp);
	}
    }
 
    return GTK_TREE_MODEL(treestore);

}
Example #6
0
void lookUserProfile(gchar *str)
{
    struct sockaddr_in addr ;
    LinpopUser *temp = g_malloc(sizeof(*temp));
    gboolean result;
    char ip[16];
    int i;
    bzero(ip,sizeof(ip));
    g_print("str:%s\n",str);
    for(;*str != '(';str++);
    g_print("str2:%s\n",str);
    for(++str,i = 0;*str != ')';str++,i++)
        ip[i] = *str;
    g_print("ip:%s\n",ip);
    inet_aton(ip,&addr.sin_addr);
    result = getUserByIP(addr,temp);
    g_print("%d",result);
    if(result == FALSE){
        //g_print("No user at %s,cannot create chat window",ip);
        g_print("No this User!\n");
        g_free(temp);
        return ;
    }
    createProfileWindow(temp->user,temp->machine,ip,temp->nick);
    freeUser(temp);
	/*extern struct userinfo *head;
	struct userinfo *p = head;
  	const char *str = gtk_entry_get_text(entry);
	char node[50];
	char l[50];
	while(p!=NULL){
		strcpy(node,p->name);
		strcat(node,"(");
		strcat(node,p->ip);
		strcat(node,")");
		if(0 == strcmp(str,node)){
			printf("---------查看资料----------\n");
			printf("name:%s\n",p->name);
			printf("group:%s\n",p->group);
			printf("IP:%s\n",p->ip);
			printf("signature:%s\n",p->signature);
			printf("picture:%d\n",p->picture);
			get_usr_info(p->name,p->group,p->ip,p->signature);
		}
		p = p->next;
		strcpy(node,l);
	}*/

}
// Add a new User (if the name is not used yet) to the Users list
bool EntityManager_AddUser(EntityManager *entityManager, const char *name) {
  userData *entity = NULL;

  if (entityManager == NULL || name == NULL) {
    snprintf(errStr, sizeof(errStr), "EntityManager_AddUser entityManager (isNull %d) and user name '%s' must not be NULL", entityManager == NULL, name);
    return false;
  }
  if (checkAddValidParams(entityManager, name) == false) return false;
  if (newUser(&entity, name) == false) return false;
  if (ItemsList_AddItem(entityManager->Users, name, entity) == false) {
    freeUser(entity);
    return false;
  }
  return EntityManager_AddUserToGroup(entityManager, ALL_ACL_NAME, name);
}
Example #8
0
void sendToTextView1(GtkWidget *button, textView *textViewAll)
{
        GtkTextIter start,end;
	
	char *text ;
        gboolean result;
        char *ip;
	char *name;
	//strcpy(text,"\0");
	ip = textViewAll->ip;
	gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(textViewAll->buffer2),&start,&end);
	text=gtk_text_buffer_get_text(GTK_TEXT_BUFFER(textViewAll->buffer2),&start,&end,FALSE);

	if(strcmp(textViewAll->message,"\0")!=0)
	{
		strcat(text,"#");
		strcat(text,textViewAll->message);
g_print("%s\n","textViewAll->message != NULL");
	}

	g_print("%s\n","SEND1");
        g_print("%s\n",text);

textViewAll->message = "\0";
//add by wanglong  send message start
	struct sockaddr_in addr;
	bzero(&addr,sizeof(struct sockaddr_in));

	addr.sin_family=AF_INET;
	addr.sin_port=htons(LINPOP_DEFAULT_PORT);
	inet_pton(AF_INET,ip,&addr.sin_addr.s_addr);
        LinpopUser *user = g_malloc(sizeof(*user));
        result = getUserByIP(addr,user);
        if(result == FALSE){
              g_print("No this User\n");
              g_free(user);
        }
        else{
             LinpopSend(&user->from,LINPOP_SENDMSG,text);
             freeUser(user);
	}
	//if(msg_send(LINPOP_SENDMSG,text,(struct sockaddr *)&addr,s) != 0)
	//	die("send error!");
//add by wanglong send message end 

	showMessage(text,textViewAll);
	gtk_text_buffer_delete(GTK_TEXT_BUFFER(textViewAll->buffer2),&start,&end);
}
Example #9
0
void groupTalk(gchar *str)
{
    struct sockaddr_in addr ;
    LinpopUser *temp = g_malloc(sizeof(*temp));
    gboolean result;
    gchar *ip;
    GList *list = getGroupUserList(str);
    //assert(list != NULL);
    if(list == NULL){
        g_print("not this group!");
        return ;
    }
    for(; list != NULL;list = list->next){
            ip = (gchar *)list->data;
            //bzero(ip,sizeof(ip));
            //g_print("str:%s\n",str);
            //for(;*str != '(';str++);
            //g_print("str2:%s\n",str);
            //for(++str,i = 0;*str != ')';str++,i++)
                //ip[i] = *str;
            g_print("ip:%s\n",ip);
            inet_aton(ip,&addr.sin_addr);
            result = getUserByIP(addr,temp);
            //g_print("%d",result);
            if(result == FALSE){
                g_print("No user at %s,cannot create chat window",ip);
                g_free(temp);
                return ;
            }
            createChatWindow(inet_ntoa(temp->from.sin_addr),temp->user,SHOW);
    }
       freeUser(temp);
	/*while(p!=NULL){
		printf("************群组聊天***********\n\n");
		if(0 == strcmp(str,p->group)){
			printf("-----------------------\n");
			printf("name:%s\n",p->name);
			printf("group:%s\n",p->group);
			printf("IP:%s\n",p->ip);
			printf("signature:%s\n",p->signature);
			printf("picture:%d\n",p->picture);
			printf("-----------------------\n\n");
		}
		p = p->next;
	}*/
}
Example #10
0
/*
函数名:		void startChat(GtkTreeView *treeView,GtkTreePath *path);
参数:		treeView: 传入的树形视图,  path : 得到树形的路径
返回值:          空
函数描述:    调用对话框
*/
void startChat(GtkTreeView *treeView,GtkTreePath *path){
    GtkTreeModel *model;
    GtkTreeIter iter;
    GtkTreeSelection *selection;
    char *value;
    int i;
    struct sockaddr_in addr ;
    LinpopUser *temp = g_malloc(sizeof(*temp));
    gboolean result;
    char ip[16];
    g_print("path is:%x\n",path);
    model = gtk_tree_view_get_model(treeView);
    selection = gtk_tree_view_get_selection(treeView);
    if(gtk_tree_model_get_iter(model,&iter,path)){
        if(gtk_tree_selection_get_selected(selection,&model,&iter)){
	    gtk_tree_model_get(model,&iter,COLUMN,&value,-1);
	    g_print("value is:%s\n",value);
	    bzero(ip,sizeof(ip));
	    i = strlen(value);
	    for(;(*value != '(') && i;value++,i--);
	    if(!i){
	        g_print("invalid!\n");
	        return ;
	    }
	    g_print("str2:%s\n",value);
	    for(++value,i = 0;*value != ')';value++,i++)
		ip[i] = *value;
	    g_print("ip:%s\n",ip);
	    inet_aton(ip,&addr.sin_addr);
	    result = getUserByIP(addr,temp);
	    g_print("%d",result);
	    if(result == FALSE){
		g_print("No user at %s,cannot create chat window",ip);
		g_free(temp);
		return ;
	    }
	    createChatWindow(inet_ntoa(temp->from.sin_addr),temp->user,SHOW);
	    freeUser(temp);
	}
    }
}
Example #11
0
PUBLIC void websCloseAuth() 
{
    WebsKey     *key, *next;

    wfree(secret);
    if (users >= 0) {
        for (key = hashFirst(users); key; key = next) {
            next = hashNext(users, key);
            freeUser(key->content.value.symbol);
        }
        hashFree(users);
        users = -1;
    }
    if (roles >= 0) {
        for (key = hashFirst(roles); key; key = next) {
            next = hashNext(roles, key);
            freeRole(key->content.value.symbol);
        }
        hashFree(roles);
        roles = -1;
    }
}
Example #12
0
void listRefresh(void)
{
    GtkTreeStore *treestore;
    GtkTreeIter toplevel, child;
    remove_all();
    treestore = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view)));
    gchar *p = NULL;
    gchar *q = NULL;
    struct sockaddr_in addr;
    int i,j;
    GList *group = NULL;
    GList *user = NULL;
    LinpopUser *temp ;
    char buf[256];
    gboolean result;
    //userListForeach(printUser,NULL);
    //我的好友列表建立
    p="特别好友";
    gtk_tree_store_append(treestore, &toplevel, NULL);
    gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
    for(user = getGroupUserList(p);user != NULL;user = user->next){
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("q is special:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
            g_print("user special :%s\n",q);
            freeUser(temp);
	}
    //gtk_tree_store_append(treestore, &child, &toplevel);
    //q=NULL;
    //gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
    //!!!!!!!!!!!!
    for(group = getGroupList();group != NULL;group = group->next){
        p = (gchar *)group->data;
        if((strcmp(p,"黑名单")== 0) || (strcmp(p,"特别好友")== 0)){
              continue;
	      g_print("ignore\n");
	}
	gtk_tree_store_append(treestore, &toplevel, NULL);
	gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
        g_print("n group:%s\n",p);
	for(user = getGroupUserList(p);user != NULL;user = user->next){
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("n q is:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
            g_print("n user:%s\n",q);
            freeUser(temp);
	}
    }
    //黑名单列表建立
     p="黑名单";
    gtk_tree_store_append(treestore, &toplevel, NULL);
    gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
    for(user = getGroupUserList(p);user != NULL;user = user->next){
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("b q is:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
            g_print("b user:%s\n",q);
	    g_print("diff\n");
            freeUser(temp);
	}
   // gtk_tree_store_append(treestore, &child, &toplevel);
    //q=NULL;
    //gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
    //!!!!!!!!!!!!
	numToStr(buf,getUserNumber());
	strcat(buf," friends online");
	gtk_entry_set_text (GTK_ENTRY (entry), buf);
    /*for(i = 0,p = g_list_nth_data(group,i); p != NULL ;i++){
	gtk_tree_store_append(treestore, &toplevel, NULL);
	gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
        g_print("p:%s\n",p);
	user = getGroupUserList(p);
	for(j = 0,q = g_list_nth_data(user,j); q != NULL;j++ ){
		gtk_tree_store_append(treestore, &child, &toplevel);
		gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
                g_print("q:%s\n",q);
	}
    }*/
}