void addForm::on_butAdd_clicked() { if(ui->lName->text().simplified() == "") { msg(trUtf8("Поле <b>Имя</b> не должно быть пустым.")); return; } if(ui->lNick->text().simplified() == "") { msg(trUtf8("Поле <b>Никнейм</b> не должно быть пустым.")); return; } if(QFile::exists("Contacts/"+ui->lName->text().simplified()+" "+ui->lNick->text().simplified())) { QMessageBox* pmbx = new QMessageBox(trUtf8("Добавление контакта"), trUtf8("Контакт с таким <b>именем</b> и <b>никнеймом</b> уже существует, вы желаете перезаписать его?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape); int n = pmbx->exec(); delete pmbx; if (n == QMessageBox::Yes) { add_contact(); } } else { add_contact(); } }
static gboolean each_contact (MuMsgContact *c, ContactData *cdata) { switch (mu_msg_contact_type (c)) { case MU_MSG_CONTACT_TYPE_FROM: add_contact(&cdata->from, c); break; case MU_MSG_CONTACT_TYPE_TO: add_contact(&cdata->to ,c); break; case MU_MSG_CONTACT_TYPE_CC: add_contact(&cdata->cc, c); break; case MU_MSG_CONTACT_TYPE_BCC: add_contact(&cdata->bcc, c); break; case MU_MSG_CONTACT_TYPE_REPLY_TO: add_contact(&cdata->reply_to, c); break; default: g_return_val_if_reached (FALSE); } return TRUE; }
static void rpc_add_contact(rpc_t* rpc, void* c) { udomain_t* d; int expires, flags, sid; double q; qvalue_t qval; str table, uid, contact; if (rpc->scan(c, "SSSdfd", &table, &uid, &contact, &expires, &q, &flags) < 6) return; qval = double2q(q); if (rpc->scan(c, "d", &sid) < 1) sid = -1; rpc_find_domain(&table, &d); if (d) { lock_udomain(d); if (add_contact(d, &uid, &contact, expires, qval, flags, sid) < 0) { unlock_udomain(d); ERR("Error while adding contact ('%.*s','%.*s') in table '%.*s'\n", uid.len, ZSW(uid.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); rpc->fault(c, 500, "Error while adding Contact"); return; } unlock_udomain(d); } else { rpc->fault(c, 400, "Table Not Found"); } }
ContactListWidget::ContactListWidget(QWidget *parent) : QListWidget(parent) { addcontactAct = new QAction(tr("&Add Contact..."), this); addcontactAct->setStatusTip(tr("add new contact")); connect(addcontactAct,SIGNAL(triggered()),this,SLOT(add_contact())); delcontactAct = new QAction(tr("&Delete Contact"),this); connect(delcontactAct,SIGNAL(triggered()),this,SLOT(del_contact())); startchatAct = new QAction(tr("Start &Chat"), this); connect(startchatAct, SIGNAL(triggered()), this, SLOT(start_chat())); viewcertAct = new QAction(tr("&View Certificate"), this); connect(viewcertAct, SIGNAL(triggered()), this, SLOT(view_cert())); showidAct = new QAction(tr("Show Pica Pica &ID"), this); connect(showidAct, SIGNAL(triggered()), this, SLOT(show_id())); sendfileAct = new QAction(tr("Send &File"), this); connect(sendfileAct, SIGNAL(triggered()), this, SLOT(send_file())); connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(start_chat())); setContactsStorage(new Contacts(config_dbname, Accounts::GetCurrentAccount().id)); }
static void complete (EBookClientView *view, const GError *error) { /* Now add a contact and assert that we received notification */ loading_view = FALSE; add_contact (e_book_client_view_get_client (view)); }
void Contact::add_failure(int node, time_t time) { net_contact_rec* c = contact_rec_for(node); if (c == nullptr) { // TODO(rushfan): Add support for creating new contact records. return; } add_contact(c, time); c->numfails++; }
session_widget::session_widget( s::session_service_ptr session_service, s::session_ptr session, a::app_service_ptr app_service) : _session_service{session_service}, _session{session}, _app_service{app_service}, _messages{new message_list{app_service, session}} { REQUIRE(session_service); REQUIRE(session); REQUIRE(app_service); _layout = new QGridLayout; _contact_select = new QComboBox; _add_contact = new QPushButton{"+"}; _add_contact->setMaximumSize(20,20); connect(_add_contact, SIGNAL(clicked()), this, SLOT(add_contact())); update_contact_select(); _contacts = new contact_list{_session_service->user_service(), _session->contacts()}; auto* cw = new QWidget; auto* cl = new QGridLayout; cw->setLayout(cl); cl->addWidget(_contact_select, 0,0); cl->addWidget(_add_contact, 0, 1); cl->addWidget(_contacts, 1, 0, 1, 2); cw->resize(CW_WIDTH, cw->height()); _splitter = new QSplitter{Qt::Horizontal}; _splitter->addWidget(_messages); _splitter->addWidget(cw); _splitter->setStretchFactor(0, 1); _splitter->setStretchFactor(1, 0); _layout->addWidget(_splitter); setLayout(_layout); _layout->setContentsMargins(0,0,0,0); //setup mail timer auto *t2 = new QTimer(this); connect(t2, SIGNAL(timeout()), this, SLOT(check_mail())); t2->start(TIMER_SLEEP); INVARIANT(_session_service); INVARIANT(_session); INVARIANT(_messages); INVARIANT(_layout); INVARIANT(_app_service); }
contact_list::contact_list(us::user_service_ptr service, const us::contact_list& contacts, make_user_info mk) : _service{service}, _mk{mk} { REQUIRE(service); for(auto u : contacts.list()) { CHECK(u); add_contact(u); } INVARIANT(_service); }
KAB::Book::Book (Ekiga::ContactCore &_core): core(_core) { KABC::AddressBook *kab = KABC::StdAddressBook::self (); kab->load (); // FIXME: turn async! for (KABC::AddressBook::Iterator iter = kab->begin (); iter != kab->end (); iter++) { add_contact (ContactPtr (new Contact (core, &(*iter)))); } }
static void complete (EBookClientView *view, const GError *error) { EBookClient *client; client = e_book_client_view_ref_client (view); /* Now add a contact and assert that we received notification */ loading_view = FALSE; add_contact (client); g_object_unref (client); }
void Contact::add_connect(int node, time_t time, uint32_t bytes_sent, uint32_t bytes_received) { net_contact_rec* c = contact_rec_for(node); if (c == nullptr) { // TODO(rushfan): Add support for creating new contact records. return; } add_contact(c, time); uint32_t time32 = static_cast<uint32_t>(time); if (bytes_sent > 0) { c->lastcontactsent = time32; c->bytes_waiting = 0; c->bytes_sent += bytes_sent; } c->bytes_received += bytes_received; }
static void cmd_join(struct xmpp *xmpp, struct contact *u, char *s) { char *p, *part; int len; p = strchr(s + 3, ' '); if (p) *p = 0; part = jid_partial(s + 3, &len); if (!part) return; add_contact(len, part); if (p) { send_message(xmpp, "chat", s + 3, p + 1); print_msg(len, part, "<%s> %s\n", me, p + 1); } }
static void cmd_join_room(struct xmpp *xmpp, struct contact *u, char *s) { char *p, *part, *res; char to[JID_BUF]; int npart, nres; p = strchr(s + 3, ' '); if (p) *p = 0; part = jid_partial(s + 3, &npart); res = jid_resource(s + 3, &nres); if (!(part && res)) return; u = add_contact(npart, part); u->type = "groupchat"; snprintf(to, sizeof(to), "%.*s/%.*s", npart, part, nres, res); join_room(xmpp, to); }
static int process_connection(int fd, struct xmpp *xmpp) { int res, max_fd; struct contact *u, *next; fd_set fds; struct timeval tv; add_contact(0, ""); fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); while (1) { FD_ZERO(&fds); FD_SET(fd, &fds); max_fd = fd; for (u = contacts; u && is_ready; u = u->next) if (u->fd >= 0) { FD_SET(u->fd, &fds); if (u->fd > max_fd) max_fd = u->fd; } tv.tv_sec = keep_alive_ms / 1000; tv.tv_usec = (keep_alive_ms % 1000) * 1000; res = select(max_fd + 1, &fds, 0, 0, (keep_alive_ms > 0) ? &tv : 0); if (res < 0) break; if (res > 0) { if (FD_ISSET(fd, &fds) && process_server_input(fd, xmpp)) break; for (u = contacts; u; u = next) { next = u->next; if (FD_ISSET(u->fd, &fds)) handle_contact_input(xmpp, u); } } else if (io_send(1, " ", &fd) < 1) break; } return 0; }
void contact_list::update(const us::contact_list& contacts) { //add new contacts for(auto c : contacts.list()) { CHECK(c); add_contact(c); } //remove ones not in list ids_to_remove ids; for(auto& p : _um) { auto c = contacts.by_id(p.first); if(c) continue; ids.push_back(p.first); } for(const auto& id : ids) remove_contact(id); ENSURE_GREATER_EQUAL(_contacts.size(), contacts.size()); ENSURE_LESS_EQUAL(_contacts.size(), _um.size()); }
static int msg_hook(int x, struct xmpp *xmpp) { char *s, *from, *part, *n, *type; int npart, len; struct contact *u; s = xml_node_find_text(x, "body", &xmpp->xml.mem); from = xml_node_find_attr(x, "from", &xmpp->xml.mem); part = from ? jid_partial(from, &npart) : 0; if (!part || !s) return 0; u = add_contact(npart, part); type = xml_node_find_attr(x, "type", &xmpp->xml.mem); if (type && !strcmp(type, "groupchat")) { u->type = "groupchat"; n = jid_resource(from, &len); } else n = jid_name(from, &len); print_msg(npart, from, "<%.*s> %s\n", len, n, s); notify(u->type, npart, from, len, n, s); return 0; }
void main(){ ul *list = (ul *) malloc (sizeof(ul)); make_user_list(list); printf("\n\n"); printf("------------------------Seja bem-vindo---------------------------------- \n\n\n"); int run = 1; int op; char name[50] ; char name1[50] ; user *u = NULL; while (run == 1){ printf("Escolha sua opção: \n"); printf("1 - Cadastrar novo usuário.\n"); printf("2 - Remover um contato.\n"); printf("3 - Criar amizade.\n"); printf("4 - Desfazer amizade.\n"); printf("5 - Imprimir dados de um usuário.\n"); printf("6 - Imprimir dados de todos os usuários.\n"); printf("7 - Sair.\n\n"); printf("Opção: "); scanf ("%d", &op); switch (op){ case 1: printf("\n\n"); u = make_user(); add_user(list,u); free(u); u = NULL; break; case 2: printf("Informe o nome do usuário que quer remover: "); scanf("%s",&name); remove_user(list, name); break; case 3: printf("Informe o nome de uma das pessoas: "); scanf("%s",&name); printf("Informe o nome de uma outra pessoa: "); scanf("%s",&name1); add_contact(list, name, name1); break; case 4: printf("Informe o nome de uma das pessoas: "); scanf("%s",&name); printf("Informe o nome de uma outra pessoa: "); scanf("%s",&name1); remove_contact(list, name, name1); break; case 5: printf("Informe o nome do usuário que quer imprimir os dados: "); scanf("%s",&name); print_info(list, name); break; case 6: print_list_user(list); case 7: run = 2; printf("\n\n\n"); printf("Até logo.\n"); // exit(0); break; } } exit(0); }
/** * @brief ht dmq callback */ int usrloc_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* node) { int content_length; str body; srjson_doc_t jdoc; srjson_t *it = NULL; static ucontact_info_t ci; int action, expires, cseq, flags, cflags, q, last_modified, methods, reg_id; str aor, ruid, c, received, path, callid, user_agent, instance; parse_from_header(msg); body = ((struct to_body*)msg->from->parsed)->uri; LM_DBG("dmq message received from %.*s\n", body.len, body.s); if(!msg->content_length) { LM_ERR("no content length header found\n"); goto invalid; } content_length = get_content_length(msg); if(!content_length) { LM_DBG("content length is 0\n"); goto invalid; } body.s = get_body(msg); body.len = content_length; if (!body.s) { LM_ERR("unable to get body\n"); goto error; } srjson_InitDoc(&jdoc, NULL); jdoc.buf = body; if(jdoc.root == NULL) { jdoc.root = srjson_Parse(&jdoc, jdoc.buf.s); if(jdoc.root == NULL) { LM_ERR("invalid json doc [[%s]]\n", jdoc.buf.s); goto invalid; } } for(it=jdoc.root->child; it; it = it->next) { if (it->string == NULL) continue; if (strcmp(it->string, "action")==0) { action = it->valueint; } else if (strcmp(it->string, "aor")==0) { aor.s = it->valuestring; aor.len = strlen(aor.s); } else if (strcmp(it->string, "ruid")==0) { ruid.s = it->valuestring; ruid.len = strlen(ruid.s); } else if (strcmp(it->string, "c")==0) { c.s = it->valuestring; c.len = strlen(c.s); } else if (strcmp(it->string, "received")==0) { received.s = it->valuestring; received.len = strlen(received.s); } else if (strcmp(it->string, "path")==0) { path.s = it->valuestring; path.len = strlen(path.s); } else if (strcmp(it->string, "callid")==0) { callid.s = it->valuestring; callid.len = strlen(callid.s); } else if (strcmp(it->string, "user_agent")==0) { user_agent.s = it->valuestring; user_agent.len = strlen(user_agent.s); } else if (strcmp(it->string, "instance")==0) { instance.s = it->valuestring; instance.len = strlen(instance.s); } else if (strcmp(it->string, "expires")==0) { // expires = it->valueint; } else if (strcmp(it->string, "cseq")==0) { cseq = it->valueint; } else if (strcmp(it->string, "flags")==0) { flags = it->valueint; } else if (strcmp(it->string, "cflags")==0) { cflags = it->valueint; } else if (strcmp(it->string, "q")==0) { q = it->valueint; } else if (strcmp(it->string, "last_modified")==0) { last_modified = it->valueint; } else if (strcmp(it->string, "methods")==0) { methods = it->valueint; } else if (strcmp(it->string, "reg_id")==0) { reg_id = it->valueint; } else { LM_ERR("unrecognized field in json object\n"); } } memset( &ci, 0, sizeof(ucontact_info_t)); ci.ruid = ruid; ci.c = &c; ci.received = received; ci.path = &path; ci.expires = expires; ci.q = q; ci.callid = &callid; ci.cseq = cseq; ci.flags = flags; ci.flags |= FL_RPL; ci.cflags = cflags; ci.user_agent = &user_agent; ci.methods = methods; ci.instance = instance; ci.reg_id = reg_id; ci.tcpconn_id = -1; ci.last_modified = last_modified; switch(action) { case DMQ_UPDATE: LM_DBG("Received DMQ_UPDATE. Update contact info...\n"); add_contact(aor, &ci); break; case DMQ_RM: LM_DBG("Received DMQ_RM. Delete contact info...\n"); delete_contact(aor, &ci); break; case DMQ_SYNC: LM_DBG("Received DMQ_SYNC. Sending all contacts...\n"); usrloc_get_all_ucontact(node); break; case DMQ_NONE: LM_DBG("Received DMQ_NONE. Not used...\n"); break; default: goto invalid; } srjson_DestroyDoc(&jdoc); resp->reason = dmq_200_rpl; resp->resp_code = 200; return 0; invalid: srjson_DestroyDoc(&jdoc); resp->reason = dmq_400_rpl; resp->resp_code = 400; return 0; error: srjson_DestroyDoc(&jdoc); resp->reason = dmq_500_rpl; resp->resp_code = 500; return 0; }
static int ul_add(FILE* pipe, char* response_file) { char table_s[MAX_TABLE]; char user_s[MAX_USER]; char contact_s[MAX_CONTACT_LEN]; char expires_s[MAX_EXPIRES_LEN]; char q_s[MAX_Q_LEN]; char rep_s[MAX_REPLICATE_LEN]; char flags_s[MAX_FLAGS_LEN]; udomain_t* d; int exp_i, flags_i; char* at; qvalue_t qval; str table, user, contact, expires, q, rep, flags; if (!read_line(table_s, MAX_TABLE, pipe, &table.len) || table.len == 0) { fifo_reply(response_file, "400 ul_add: table name expected\n"); LOG(L_ERR, "ERROR: ul_add: table name expected\n"); return 1; } if (!read_line(user_s, MAX_USER, pipe, &user.len) || user.len == 0) { fifo_reply(response_file, "400 ul_add: aor name expected\n"); LOG(L_ERR, "ERROR: ul_add: aor expected\n"); return 1; } at = memchr(user_s, '@', user.len); if (use_domain) { if (!at) { fifo_reply(response_file, "400 ul_add: username@domain expected\n"); LOG(L_ERR, "ERROR: ul_add: Domain missing\n"); return 1; } } else { if (at) { user.len = at - user_s; } } if (!read_line(contact_s, MAX_CONTACT_LEN, pipe, &contact.len) || contact.len == 0) { fifo_reply(response_file, "400 ul_add: contact expected\n"); LOG(L_ERR, "ERROR: ul_add: contact expected\n"); return 1; } if (!read_line(expires_s, MAX_EXPIRES_LEN, pipe, &expires.len) || expires.len == 0) { fifo_reply(response_file, "400 ul_add: expires expected\n"); LOG(L_ERR, "ERROR: ul_add: expires expected\n"); return 1; } if (!read_line(q_s, MAX_Q, pipe, &q.len) || q.len == 0) { fifo_reply(response_file, "400 ul_add: q expected\n"); LOG(L_ERR, "ERROR: ul_add: q expected\n"); return 1; } /* Kept for backwards compatibility */ if (!read_line(rep_s, MAX_REPLICATE_LEN, pipe, &rep.len) || rep.len == 0) { fifo_reply(response_file, "400 ul_add: replicate expected\n"); LOG(L_ERR, "ERROR: ul_add: replicate expected\n"); return 1; } if (!read_line(flags_s, MAX_FLAGS_LEN, pipe, &flags.len) || flags.len == 0) { fifo_reply(response_file, "400 ul_add: flags expected\n"); LOG(L_ERR, "ERROR: ul_add: flags expected\n"); return 1; } table.s = table_s; user.s = user_s; strlower(&user); contact.s = contact_s; expires.s = expires_s; q.s = q_s; flags.s = flags_s; fifo_find_domain(&table, &d); if (d) { if (str2int(&expires, (unsigned int*)&exp_i) < 0) { fifo_reply(response_file, "400 Invalid expires format\n"); return 1; } if (str2q(&qval, q.s, q.len) < 0) { fifo_reply(response_file, "400 Invalid q value\n"); return 1; } if (str2int(&flags, (unsigned int*)&flags_i) < 0) { fifo_reply(response_file, "400 Invalid flags format\n"); return 1; } lock_udomain(d); if (add_contact(d, &user, &contact, exp_i, qval, flags_i) < 0) { unlock_udomain(d); LOG(L_ERR, "ul_add(): Error while adding contact ('%.*s','%.*s') in table '%.*s'\n", user.len, ZSW(user.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); fifo_reply(response_file, "500 Error while adding contact\n" " ('%.*s','%.*s') in table '%.*s'\n", user.len, ZSW(user.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); return 1; } unlock_udomain(d); fifo_reply(response_file, "200 Added to table\n" "('%.*s','%.*s') to '%.*s'\n", user.len, ZSW(user.s), contact.len, ZSW(contact.s), table.len, ZSW(table.s)); return 1; } else { fifo_reply(response_file, "400 Table '%.*s' not found in memory, use save(\"%.*s\") or lookup(\"%.*s\") in the configuration script first\n", table.len, ZSW(table.s), table.len, ZSW(table.s), table.len, ZSW(table.s)); return 1; } }
void OPENLDAP::Book::refresh_result () { int result = LDAP_SUCCESS; int nbr = 0; struct timeval timeout = { 1, 0}; /* block 1s */ LDAPMessage *msg_entry = NULL; LDAPMessage *msg_result = NULL; gchar* c_status = NULL; result = ldap_result (ldap_context, LDAP_RES_ANY, LDAP_MSG_ALL, &timeout, &msg_entry); if (result <= 0) { if (patience == 3) { patience--; Ekiga::Runtime::run_in_main (boost::bind (&OPENLDAP::Book::refresh_result, this), 12); } else if (patience == 2) { patience--; Ekiga::Runtime::run_in_main (boost::bind (&OPENLDAP::Book::refresh_result, this), 21); } else if (patience == 1) { patience--; Ekiga::Runtime::run_in_main (boost::bind (&OPENLDAP::Book::refresh_result, this), 30); } else { // patience == 0 status = std::string (_("Could not search")); updated (this->shared_from_this ()); ldap_unbind_ext (ldap_context, NULL, NULL); ldap_context = NULL; } if (msg_entry != NULL) ldap_msgfree (msg_entry); return; } msg_result = ldap_first_message (ldap_context, msg_entry); do { if (ldap_msgtype (msg_result) == LDAP_RES_SEARCH_ENTRY) { ContactPtr contact = parse_result (msg_result); if (contact) { add_contact (contact); nbr++; } } msg_result = ldap_next_message (ldap_context, msg_result); } while (msg_result != NULL); // Do not count ekiga.net's first entry "Search Results ... 100 entries" if (bookinfo.uri_host == EKIGA_NET_URI) nbr--; c_status = g_strdup_printf (ngettext ("%d user found", "%d users found", nbr), nbr); status = c_status; g_free (c_status); updated (this->shared_from_this ()); (void)ldap_msgfree (msg_entry); ldap_unbind_ext (ldap_context, NULL, NULL); ldap_context = NULL; }
int push_on_network(struct sip_msg *msg, int net) { str body; struct sip_uri uri; struct sms_msg *sms_messg; struct to_body *from; char *p; int len; int mime; /* get the message's body * anyhow we have to call this function, so let's do it at the beginning * to force the parsing of all the headers - like this we avoid separate * calls of parse_headers function for FROM, CONTENT_LENGTH, TO hdrs */ body.s = get_body( msg ); if (body.s==0) { LM_ERR("failed to extract body from msg!\n"); goto error; } /* content-length (if present) must be already parsed */ if (!msg->content_length) { LM_ERR("no Content-Length header found!\n"); goto error; } body.len = get_content_length( msg ); /* parse the content-type header */ if ( (mime=parse_content_type_hdr(msg))<1 ) { LM_ERR("failed to parse Content-Type header\n"); goto error; } /* check the content-type value */ if ( mime!=(TYPE_TEXT<<16)+SUBTYPE_PLAIN && mime!=(TYPE_MESSAGE<<16)+SUBTYPE_CPIM ) { LM_ERR("invalid content-type for a message request! type found=%d\n", mime); goto error; } /* we try to get the user name (phone number) first from the RURI (in our case means from new_uri or from first_line.u.request.uri); if it's missing there (like in requests generated by MSN MESSENGER), we go for "to" header */ LM_DBG("string to get user from new_uri\n"); if ( !msg->new_uri.s||parse_uri( msg->new_uri.s,msg->new_uri.len,&uri) || !uri.user.len ) { LM_DBG("string to get user from R_uri\n"); if ( parse_uri( msg->first_line.u.request.uri.s, msg->first_line.u.request.uri.len ,&uri)||!uri.user.len ) { LM_DBG("string to get user from To\n"); if ( (!msg->to&&((parse_headers(msg,HDR_TO_F,0)==-1) || !msg->to)) || parse_uri( get_to(msg)->uri.s, get_to(msg)->uri.len, &uri)==-1 || !uri.user.len) { LM_ERR("unable to extract user name from RURI and To header!\n"); goto error; } } } /* check the uri.user format = '+(inter code)(number)' */ if (uri.user.len<2 || uri.user.s[0]!='+' || uri.user.s[1]<'1' || uri.user.s[1]>'9') { LM_ERR("user tel number [%.*s] does not respect international format\n" ,uri.user.len,uri.user.s); goto error; } /* parsing from header */ if ( parse_from_header( msg )==-1 ) { LM_ERR("failed to get FROM header\n"); goto error; } from = (struct to_body*)msg->from->parsed; #if 0 /* adds contact header into reply */ if (add_contact(msg,&(uri.user))==-1) { LM_ERR("can't build contact for reply\n"); goto error; } #endif /*-------------BUILD AND FILL THE SMS_MSG STRUCTURE --------------------*/ /* computes the amount of memory needed */ len = SMS_HDR_BF_ADDR_LEN + from->uri.len + SMS_HDR_AF_ADDR_LEN + body.len + SMS_FOOTER_LEN /*text to send*/ + from->uri.len /* from */ + uri.user.len-1 /* to user (without '+') */ + sizeof(struct sms_msg) ; /* the sms_msg structure */ /* allocs a new sms_msg structure in shared memory */ sms_messg = (struct sms_msg*)shm_malloc(len); if (!sms_messg) { LM_ERR("failed to get shm memory!\n"); goto error; } p = (char*)sms_messg + sizeof(struct sms_msg); /* copy "from" into sms struct */ sms_messg->from.len = from->uri.len; sms_messg->from.s = p; append_str(p,from->uri.s,from->uri.len); /* copy "to.user" - we have to strip out the '+' */ sms_messg->to.len = uri.user.len-1; sms_messg->to.s = p; append_str(p,uri.user.s+1,sms_messg->to.len); /* copy (and composing) sms body */ sms_messg->text.len = SMS_HDR_BF_ADDR_LEN + sms_messg->from.len + SMS_HDR_AF_ADDR_LEN + body.len+SMS_FOOTER_LEN; sms_messg->text.s = p; append_str(p, SMS_HDR_BF_ADDR, SMS_HDR_BF_ADDR_LEN); append_str(p, sms_messg->from.s, sms_messg->from.len); append_str(p, SMS_HDR_AF_ADDR, SMS_HDR_AF_ADDR_LEN); append_str(p, body.s, body.len); append_str(p, SMS_FOOTER, SMS_FOOTER_LEN); if (*queued_msgs>MAX_QUEUED_MESSAGES) goto error; (*queued_msgs)++; if (write(net_pipes_in[net], &sms_messg, sizeof(sms_messg))!= sizeof(sms_messg) ) { LM_ERR("error when writing for net %d to pipe [%d] : %s\n", net,net_pipes_in[net],strerror(errno) ); shm_free(sms_messg); (*queued_msgs)--; goto error; } return 1; error: return -1; }
int main(int argc, char** argv) { cvector_void contacts; char choice; int quit = 0; cvec_void(&contacts, 0, 10, sizeof(contact), free_contact, NULL); saved = 1; print_menu(); while (!quit) { puts("What action would you like to perform?"); choice = read_char(stdin, SPACE_SET, 0, 1); switch (choice) { case 'A': case 'a': add_contact(&contacts); break; case 'D': case 'd': display_contacts(&contacts); break; case 'E': case 'e': edit_contacts(&contacts); break; case 'V': case 'v': save_contacts(&contacts); break; case 'L': case 'l': load_contacts(&contacts); break; case 'R': case 'r': remove_contact(&contacts); break; case 'S': case 's': sort_contacts(&contacts); break; case 'F': case 'f': find_contacts(&contacts, NULL, 1); break; case 'Q': case 'q': //TODO if (!saved) { puts("You have unsaved changes! Are you sure you want to quit? (y/N)"); choice = read_char(stdin, SPACE_SET_NO_NEWLINE, 0, 1); if (choice == 'y' || choice == 'y') quit = 1; else quit = 0; } else { quit = 1; } break; case '?': print_menu(); break; } putchar('\n'); } cvec_free_void(&contacts); return 0; }
int main() { Contact *head=NULL; Contact *tail=NULL; srand(time(0)); CURRENT_OS_TYPE = OS_TYPE_WINDOWS; puts("-----------------| INITIALIZING CONTACTS |-----------------"); puts("Please wait while initializing your contacts..."); initialize_contacts(&head, &tail); puts("Done !"); puts("-----------------------------------------------------------"); int ch = -1, keep = 1; while(keep == 1) { show_func_menu(); printf("SELECT : "); scanf("%d", &ch); switch(ch) { clean_screen(CURRENT_OS_TYPE); case 1: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| LIST ALL CONTACTS |-----------------"); list_all_contacts(head); puts("-------------------------------------------------------"); break; } case 2: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| SEARCH CONTACT BY NAME |-----------------"); char *tmp_fn = (char *)malloc(20); char *tmp_ln = (char *)malloc(20); printf("Enter First_Name Last_Name: "); scanf("%s %s", tmp_fn, tmp_ln); Contact *temp = search_contact_by_name(head, tmp_fn, tmp_ln); if(temp == NULL) puts("No results !"); else printf("%s %s\t\t%s\t\t%s\n", temp->name->first_name, temp->name->last_name, temp->gender == FEMALE ? "Female" : "Male", temp->phone); puts("------------------------------------------------------------"); break; } case 3: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| SEARCH CONTACT BY PHONE |-----------------"); char *tmp_phone = (char *)malloc(10); printf("Enter Phone: "); scanf("%s", tmp_phone); Contact *temp = search_contact_by_phone(head, tmp_phone); if(temp == NULL) puts("No results !"); else printf("%s %s\t\t%s\t\t%s\n", temp->name->first_name, temp->name->last_name, temp->gender == FEMALE ? "Female" : "Male", temp->phone); puts("-------------------------------------------------------------"); break; } case 4: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| ADD CONTACT |-----------------"); char *tmp_fn = (char *)malloc(20); char *tmp_ln = (char *)malloc(20); char *tmp_phone = (char *)malloc(11); int tmp_gender; printf("Enter First_Name Last_Name: "); scanf("%s %s", tmp_fn, tmp_ln); printf("Enter Phone: "); scanf("%s", tmp_phone); printf("Enter Gender(1 for Male, 0 for Female): "); scanf("%d", &tmp_gender); Name *tmp_name = (struct Name *)malloc(sizeof(struct Name)); tmp_name->first_name = tmp_fn; tmp_name->last_name = tmp_ln; add_contact(&head, &tail, tmp_name, tmp_gender, tmp_phone); puts("-------------------------------------------------"); break; } case 5: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| UPDATE CONTACT BY INDEX |-----------------"); int index; printf("Enter The Index: "); scanf("%d",&index); if((index<=0)||(index>CSIZE)) { printf("Cannot Found This Data\n"); break; } else { Contact *current=head; int i; for(i=1;i<=CSIZE;i++) { if(index==1) { break; } else if((i==index)&&(i<CSIZE)) { break; } else if((i==index)&&(i==CSIZE)) { break; } current=current->next; } puts("------------------------------------------------------------"); printf("%s %s\t\t%s\t\t%s\n", current->name->first_name, current->name->last_name, current->gender == FEMALE ? "Female" : "Male", current->phone); puts("------------------------------------------------------------"); } printf("Would you like to update it? (Y/N) "); char *tmp_fn = (char *)malloc(20); char *tmp_ln = (char *)malloc(20); char *tmp_phone = (char *)malloc(10); int tmp_gender; if(toupper(getche())=='Y') { printf("\nEnter First_Name Last_Name: "); scanf("%s %s", tmp_fn, tmp_ln); printf("Enter Phone: "); scanf("%s", tmp_phone); printf("Enter Gender(1 for Male, 0 for Female): "); scanf("%d", &tmp_gender); Name *tmp_name = (struct Name *)malloc(sizeof(struct Name)); tmp_name->first_name = tmp_fn; tmp_name->last_name = tmp_ln; update_contact_by_index(&head,index, tmp_name, tmp_gender, tmp_phone); puts("------------------------------------------------------------"); } else { printf("\n"); } break; } case 6: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| UPDATE CONTACT BY NAME |-----------------"); char *tmp_o_fn = (char *)malloc(20); char *tmp_o_ln = (char *)malloc(20); printf("Enter First_Name Last_Name: "); scanf("%s %s", tmp_o_fn, tmp_o_ln); Name *tmp_o_name = (struct Name *)malloc(sizeof(struct Name)); tmp_o_name->first_name = tmp_o_fn; tmp_o_name->last_name = tmp_o_ln; Contact *temp = search_contact_by_name(head, tmp_o_fn, tmp_o_ln); if(temp == NULL) printf("Cannot locate %s %s.\n",tmp_o_fn, tmp_o_ln); else{ puts("------------------------------------------------------------"); printf("%s %s\t\t%s\t\t%s\n", temp->name->first_name, temp->name->last_name, temp->gender == FEMALE ? "Female" : "Male", temp->phone); puts("------------------------------------------------------------"); } printf("Would you like to continue the update? (Y/N) "); char *tmp_fn = (char *)malloc(20); char *tmp_ln = (char *)malloc(20); char *tmp_phone = (char *)malloc(10); int tmp_gender; if(toupper(getche())=='Y') { printf("\nEnter First_Name Last_Name: "); scanf("%s %s", tmp_fn, tmp_ln); printf("Enter Phone: "); scanf("%s", tmp_phone); printf("Enter Gender(1 for Male, 0 for Female): "); scanf("%d", &tmp_gender); Name *tmp_name = (struct Name *)malloc(sizeof(struct Name)); tmp_name->first_name = tmp_fn; tmp_name->last_name = tmp_ln; update_contact_by_name(&head, tmp_o_name, tmp_name, tmp_gender, tmp_phone); puts("------------------------------------------------------------"); } else { printf("\n"); } break; } case 7: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| UPDATE CONTACT BY PHONE |-----------------"); char *temp_o_phone=(char *)malloc(11); printf("Enter The Phone: "); scanf("%s", temp_o_phone); Contact *temp=search_contact_by_phone(head,temp_o_phone); if(temp==NULL) { printf("Cannot Found %s",temp_o_phone); } else { puts("------------------------------------------------------------"); printf("%s %s\t\t%s\t\t%s\n", temp->name->first_name, temp->name->last_name, temp->gender == FEMALE ? "Female" : "Male", temp->phone); puts("------------------------------------------------------------"); } printf("Would you like to continue the update? (Y/N) "); char *tmp_fn = (char *)malloc(20); char *tmp_ln = (char *)malloc(20); char *tmp_phone = (char *)malloc(10); int tmp_gender; if(toupper(getche())=='Y') { printf("\nEnter First_Name Last_Name: "); scanf("%s %s", tmp_fn, tmp_ln); printf("Enter Phone: "); scanf("%s", tmp_phone); printf("Enter Gender(1 for Male, 0 for Female): "); scanf("%d", &tmp_gender); Name *tmp_name = (struct Name *)malloc(sizeof(struct Name)); tmp_name->first_name = tmp_fn; tmp_name->last_name = tmp_ln; update_contact_by_phone(&head, temp_o_phone, tmp_name, tmp_gender, tmp_phone); puts("------------------------------------------------------------"); }else { printf("\n"); } break; } case 8: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| DELETE CONTACT BY INDEX |-----------------"); int index; printf("Enter Index[1:%d]: ", CSIZE); scanf("%d", &index); int success=0; success = delete_contact_by_index(&head, &tail, index); if(success) printf("Deletion successful\n"); else printf("No such index %d\n",index); puts("-------------------------------------------------------------"); break; } case 9: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| DELETE CONTACT BY NAME |-----------------"); char *tmp_o_fn = (char *)malloc(20); char *tmp_o_ln = (char *)malloc(20); printf("Enter First_Name Last_Name: "); scanf("%s %s", tmp_o_fn, tmp_o_ln); Name *tmp_o_name = (struct Name *)malloc(sizeof(struct Name)); tmp_o_name->first_name = tmp_o_fn; tmp_o_name->last_name = tmp_o_ln; int success=0; success = delete_contact_by_name(&head, &tail, tmp_o_name); if(success) printf("Deletion successful\n"); else printf("%s %s cannot be found!\n", tmp_o_fn, tmp_o_ln); puts("------------------------------------------------------------"); break; } case 10: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| DELETE CONTACT BY PHONE |-----------------"); char *tmp_phone=(char *)malloc(11); printf("Enter The Phone: "); scanf("%s",tmp_phone); int success=0; success=delete_contact_by_phone(&head,&tail,tmp_phone); if(success) { printf("Deletion successful\n"); } else { printf("%s cannot be found!\n",tmp_phone); } puts("------------------------------------------------------------"); break; } case 11: { clean_screen(CURRENT_OS_TYPE); puts("-----------------| ABOUT DEVELOPER |-----------------"); about_developer(); puts("-----------------------------------------------------"); break; } case 12: { clean_screen(CURRENT_OS_TYPE); list_all_nodes_address(head, tail); break; } case 13: { clean_screen(CURRENT_OS_TYPE); puts("BYE-BYE !"); keep = 0; break; } default: puts("Bad choice"); } pause(CURRENT_OS_TYPE); } return 0; }
GestioneContatti::GestioneContatti(LinkedInClient* c, QWidget* parent):client(c){ this->setStyleSheet("background:qlineargradient(x1:0 y1:0, x2:0 y2:1,stop:0 #3498db, stop:1 #2980b9);color:white;width:470px;max-height:350px;" ); this->setGeometry(150,150,0,0); QVBoxLayout* layout=new QVBoxLayout; QLabel* gestione_contatti=new QLabel("Gestione contatti"); gestione_contatti->setAlignment(Qt::AlignHCenter); gestione_contatti->setStyleSheet("font: 20pt \"FontAwesome\";background:transparent; font-weight:bold; margin-bottom:20px;margin-top:20px;" ); QVBoxLayout* layoutsx=new QVBoxLayout; LEcerca=new QLineEdit; LEcerca->setStyleSheet("background:white;" "color:black;" ); LEcerca->setPlaceholderText("Inserisci Username da cercare"); QHBoxLayout* container=new QHBoxLayout; QVBoxLayout* layoutdx=new QVBoxLayout; container->setContentsMargins(5,0,0,5); output=new QTableWidget; output->setStyleSheet("background:white;color:black;" ); output->setColumnCount(8); QHeaderView *HorzHdr=output->horizontalHeader(); HorzHdr->setSectionResizeMode(QHeaderView::Stretch); QStringList headerlabels; headerlabels<<"Username"<<"Nome"<<"Cognome"<<"Data di Nascita"<<"Luogo di Nascita"<<"Tipo di Utente"<<"Curriculum"<<"Rete"; output->setHorizontalHeaderLabels(headerlabels); output->horizontalHeader()->setHighlightSections(false); output->verticalHeader()->setVisible(false); output->setEditTriggers( QAbstractItemView::NoEditTriggers ); output->setSelectionBehavior(QAbstractItemView::SelectRows); QPushButton* cerca=new QPushButton("Cerca"); cerca->setStyleSheet("background:#0082b6;max-height:25px;max-width:150px;"); connect(cerca,SIGNAL(clicked()),this,SLOT(find())); QPushButton* aggiungi_contatto=new QPushButton("Aggiungi Contatto"); connect(aggiungi_contatto,SIGNAL(clicked()),this,SLOT(add_contact())); aggiungi_contatto->setStyleSheet("background:#0082b6;max-height:25px;max-width:150px;"); QPushButton* rimuovi_contatto=new QPushButton("Rimuovi Contatto"); connect(rimuovi_contatto,SIGNAL(clicked()),this,SLOT(remove_contact())); rimuovi_contatto->setStyleSheet("background:#0082b6;max-height:25px;max-width:150px;"); QPushButton* visualizza_contatti=new QPushButton("Visualizza Contatti"); visualizza_contatti->setStyleSheet("background:#0082b6;max-height:25px;max-width:150px;"); connect(visualizza_contatti,SIGNAL(clicked()),this,SLOT(visualizza_contacts())); QPushButton* savedb=new QPushButton("Save DB"); savedb->setStyleSheet("background:#0082b6;max-height:25px;max-width:150px;"); connect(savedb,SIGNAL(clicked()),this,SLOT(save_DB())); QPushButton* button_back=new QPushButton("Back"); button_back->setStyleSheet("background:#0082b6;max-width:150px;"); connect(button_back,SIGNAL(clicked()),this,SLOT(close())); connect(button_back,SIGNAL(clicked()),parent,SLOT(show())); layoutsx->addWidget(LEcerca); layoutsx->addWidget(output); layoutsx->setContentsMargins(5,0,0,0); layoutdx->addWidget(cerca); layoutdx->addWidget(aggiungi_contatto); layoutdx->addWidget(rimuovi_contatto); layoutdx->addWidget(visualizza_contatti); layoutdx->addWidget(savedb); layoutdx->addWidget(button_back,0,Qt::AlignTop); layoutdx->setContentsMargins(0,0,0,0); container->addLayout(layoutsx); container->addLayout(layoutdx); layout->addWidget(gestione_contatti); layout->addLayout(container); layout -> setMargin(0); layout -> setContentsMargins (0,0,0,0); layout->setSizeConstraint(QLayout::SetFixedSize); setLayout(layout); }
static int ServiceParseAimLink(WPARAM, LPARAM lParam) { char *arg = (char*)lParam; if (arg == NULL) return 1; /* sanity check */ /* skip leading prefix */ arg = strchr(arg, ':'); if (arg == NULL) return 1; /* parse failed */ for (++arg; *arg == '/'; ++arg); /* add user: aim:addbuddy?screenname=NICK&groupname=GROUP send message: aim:goim?screenname=NICK&message=MSG open chatroom: aim:gochat?roomname=ROOM&exchange=NUM */ /* add a contact to the list */ if (!_strnicmp(arg, "addbuddy?", 9)) { char *tok, *sn = NULL, *group = NULL; ADDCONTACTSTRUCT acs; PROTOSEARCHRESULT psr; if (*(arg += 9) == 0) return 1; /* parse failed */ tok = strtok(arg, "&"); /* first token */ while (tok != NULL) { if (!_strnicmp(tok, "screenname=", 11) && *(tok + 11) != 0) sn = Netlib_UrlDecode(tok + 11); if (!_strnicmp(tok, "groupname=", 10) && *(tok + 10) != 0) group = Netlib_UrlDecode(tok + 10); /* group is currently ignored */ tok = strtok(NULL, "&"); /* next token */ } if (sn == NULL) return 1; /* parse failed */ if (find_contact(sn) == NULL) { /* does not yet check if sn is current user */ acs.handleType = HANDLE_SEARCHRESULT; acs.szProto = AIM_PROTOCOL_NAME; acs.psr = &psr; memset(&psr, 0, sizeof(PROTOSEARCHRESULT)); psr.cbSize = sizeof(PROTOSEARCHRESULT); psr.nick.t = sn; CallService(MS_ADDCONTACT_SHOW, 0, (LPARAM)&acs); } return 0; } /* send a message to a contact */ else if (!_strnicmp(arg, "goim?", 5)) { char *tok, *sn = NULL, *msg = NULL; MCONTACT hContact; if (*(arg += 5) == 0) return 1; /* parse failed */ tok = strtok(arg, "&"); /* first token */ while (tok != NULL) { if (!_strnicmp(tok, "screenname=", 11) && *(tok + 11) != 0) sn = Netlib_UrlDecode(tok + 11); if (!_strnicmp(tok, "message=", 8) && *(tok + 8) != 0) msg = Netlib_UrlDecode(tok + 8); tok = strtok(NULL, "&"); /* next token */ } if (sn == NULL) return 1; /* parse failed */ if (ServiceExists(MS_MSG_SENDMESSAGE)) { hContact = find_contact(sn); if (hContact == NULL) { hContact = add_contact(sn); /* does not yet check if sn is current user */ if (hContact != NULL) db_set_b(hContact, MOD_KEY_CL, AIM_KEY_NL, 1); } if (hContact != NULL) CallService(MS_MSG_SENDMESSAGE, hContact, (LPARAM)msg); } return 0; } /* open a chatroom */ else if (!_strnicmp(arg, "gochat?", 7)) { char *tok, *rm = NULL; int exchange = 0; if (*(arg += 7) == 0) return 1; /* parse failed */ tok = strtok(arg, "&"); /* first token */ while (tok != NULL) { if (!_strnicmp(tok, "roomname=", 9) && *(tok + 9) != 0) rm = Netlib_UrlDecode(tok + 9); if (!_strnicmp(tok, "exchange=", 9)) exchange = atoi(Netlib_UrlDecode(tok + 9)); tok = strtok(NULL, "&"); /* next token */ } if (rm == NULL || exchange <= 0) return 1; /* parse failed */ aim_gchat_joinrequest(rm, exchange); return 0; } return 1; /* parse failed */ }