void userlist_add (struct session *sess, const char name[], const char hostname[], const char account[], const char realname[], const message_tags_data *tags_data) { int prefix_chars; auto acc = nick_access (sess->server, name, prefix_chars); notify_set_online (*sess->server, name + prefix_chars, tags_data); std::unique_ptr<User> user(new User()); user->access = acc; /* assume first char is the highest level nick prefix */ if (prefix_chars) user->prefix[0] = name[0]; /* add it to our linked list */ if (hostname) user->hostname = std::string(hostname); user->nick = (name + prefix_chars); /* is it me? */ if (!sess->server->compare (user->nick, sess->server->nick)) user->me = true; /* extended join info */ if (sess->server->have_extjoin) { if (account && *account) user->account = std::string (account); if (realname && *realname) user->realname = std::string (realname); } User * user_ref = user.get(); auto row = userlist_insertname (sess, std::move(user)); /* duplicate? some broken servers trigger this */ if (row == -1) { return; } sess->total++; /* most ircds don't support multiple modechars in front of the nickname for /NAMES - though they should. */ while (prefix_chars) { update_counts (sess, user_ref, name[0], true, 1); name++; prefix_chars--; } if (user_ref->me) sess->me = user_ref; fe_userlist_insert(sess, user_ref, row, false); fe_userlist_numbers (*sess); }
void userlist_add (struct session *sess, char *name, char *hostname) { struct User *user; int row, prefix_chars; unsigned int acc; acc = nick_access (sess->server, name, &prefix_chars); notify_set_online (sess->server, name + prefix_chars); user = malloc (sizeof (struct User)); memset (user, 0, sizeof (struct User)); user->access = acc; /* assume first char is the highest level nick prefix */ if (prefix_chars) user->prefix[0] = name[0]; /* add it to our linked list */ if (hostname) user->hostname = strdup (hostname); safe_strcpy (user->nick, name + prefix_chars, NICKLEN); /* is it me? */ if (!sess->server->p_cmp (user->nick, sess->server->nick)) user->me = TRUE; row = userlist_insertname (sess, user); /* duplicate? some broken servers trigger this */ if (row == -1) { if (user->hostname) free (user->hostname); free (user); return; } sess->total++; /* most ircds don't support multiple modechars infront of the nickname for /NAMES - though they should. */ while (prefix_chars) { update_counts (sess, user, name[0], TRUE, 1); name++; prefix_chars--; } if (user->me) sess->me = user; fe_userlist_insert (sess, user, row, FALSE); fe_userlist_numbers (sess); }
void userlist_update_mode (session * sess, char *name, char mode, char sign) { int access; int offset = 0; int level; int pos; char prefix; struct User *user; user = userlist_find (sess, name); if (!user) return; /* remove from binary trees, before we loose track of it */ tree_remove (sess->usertree, user, &pos); tree_remove (sess->usertree_alpha, user, &pos); /* which bit number is affected? */ access = mode_access (sess->server, mode, &prefix); if (sign == '+') { level = TRUE; if (!(user->access & (1 << access))) { offset = 1; user->access |= (1 << access); } } else { level = FALSE; if (user->access & (1 << access)) { offset = -1; user->access &= ~(1 << access); } } /* now what is this users highest prefix? e.g. @ for ops */ user->prefix[0] = get_nick_prefix (sess->server, user->access); /* update the various counts using the CHANGED prefix only */ update_counts (sess, user, prefix, level, offset); /* insert it back into its new place */ tree_insert (sess->usertree_alpha, user); pos = tree_insert (sess->usertree, user); /* let GTK move it too */ fe_userlist_move (sess, user, pos); fe_userlist_numbers (sess); }
void userlist_update_mode (session *sess, const char name[], char mode, char sign) { auto result = std::find_if( sess->usertree.begin(), sess->usertree.end(), [sess, name](const std::unique_ptr<User> &u){ return sess->server->compare(name, u->nick) == 0; }); if (result == sess->usertree.end()) return; User * user = result->get(); /* which bit number is affected? */ char prefix; auto access = mode_access (sess->server, mode, &prefix); bool level = false; int offset = 0; if (sign == '+') { level = true; if (!(user->access & (1 << access))) { offset = 1; user->access |= (1 << access); } } else { level = false; if (user->access & (1 << access)) { offset = -1; user->access &= ~(1 << access); } } /* now what is this users highest prefix? e.g. @ for ops */ user->prefix[0] = get_nick_prefix (sess->server, user->access); /* update the various counts using the CHANGED prefix only */ update_counts (sess, user, prefix, level, offset); int pos = userlist_resort(*sess, user->nick); /* let GTK move it too */ fe_userlist_move (sess, user, pos); fe_userlist_numbers (*sess); }
void rfc2045_parse_partial(struct rfc2045 *h) { /* ** Our buffer's getting pretty big. Let's see if we can ** partially handle it. */ if (h->workbuflen > 0) { struct rfc2045 *p; int l, i; for (p=h; p->lastpart && !p->lastpart->workclosed; p=p->lastpart) ; /* If p->workinheader, we've got a mother of all headers ** here. Well, that's just too bad, we'll end up garbling ** it. */ l=h->workbuflen; /* We do need to make sure that the final \r\n gets ** stripped off, so don't gobble up everything if ** the last character we see is a \r */ if (h->workbuf[l-1] == '\r') --l; /* If we'll be rewriting, make sure rwprep knows about ** stuff that was skipped just now. */ if (h->rfc2045acptr && !p->workinheader && (!p->lastpart || !p->lastpart->workclosed)) (*h->rfc2045acptr->section_contents)(h->workbuf, l); update_counts(p, p->endpos+l, p->endpos+l, 0); p->informdata=1; for (i=0; l<h->workbuflen; l++) h->workbuf[i++]=h->workbuf[l]; h->workbuflen=i; } }
lit make_decision(solver* s) { int i, maxval; lit maxlit; if(!update_counts(s)) fprintf(stderr, "ERROR! Failed to update literal counts at level %d\n", s->cur_level), exit(1); maxval = -1; maxlit = -1; for(i = 0; i < s->size*2; i++){ if (s->counts[i] > maxval){ maxval = s->counts[i]; maxlit = i; } } if (maxval == 0 || s->assigns[maxlit] == l_False) fprintf(stderr, "ERROR! make_decision failed to find a lit that exists and isn't false!\n"), exit(1); return maxlit; }
static void doline(struct rfc2045 *p) { size_t cnt=p->workbuflen; char *c=p->workbuf; size_t n=cnt-1; /* Strip \n (we always get at least a \n here) */ struct rfc2045 *newp; struct rfc2045ac *rwp=p->rfc2045acptr; unsigned num_levels=0; size_t k; int bit8=0; if (p->numparts > MAXPARTS) { p->rfcviolation |= RFC2045_ERR2COMPLEX; return; } for (k=0; k<cnt; k++) { if (c[k] == 0) c[k]=' '; if (c[k] & 0x80) bit8=1; } if (n && c[n-1] == '\r') /* Strip trailing \r */ --n; /* Before the main drill down loop before, look ahead and see if we're ** in a middle of a form-data section. */ for (newp=p; newp->lastpart && !newp->lastpart->workclosed; newp=newp->lastpart, ++num_levels) { if (ContentBoundary(newp) == 0 || newp->workinheader) continue; if (newp->lastpart->informdata) { p=newp->lastpart; p->informdata=0; break; } } /* Drill down until we match a boundary, or until we've reached the last RFC2045 section that has been opened. */ while (p->lastpart) { size_t l; const char *cb; if (p->lastpart->workclosed) { update_counts(p, p->endpos+cnt, p->endpos+n, 1); return; } /* Leftover trash -- workclosed is set when the final ** terminating boundary has been seen */ /* content_boundary may be set before the entire header ** has been seen, so continue drilling down in that case */ cb=ContentBoundary(p); if (cb == 0 || p->workinheader) { p=p->lastpart; ++num_levels; continue; } l=strlen(cb); if (c[0] == '-' && c[1] == '-' && n >= 2+l && strncasecmp(cb, c+2, l) == 0) { if (rwp && (!p->lastpart || !p->lastpart->isdummy)) (*rwp->end_section)(); /* Ok, we've found a boundary */ if (n >= 4+l && strncmp(c+2+l, "--", 2) == 0) { /* Last boundary */ p->lastpart->workclosed=1; update_counts(p, p->endpos+cnt, p->endpos+cnt, 1); return; } /* Create new RFC2045 section */ newp=append_part(p, p->endpos+cnt); update_counts(p, p->endpos+cnt, p->endpos+n, 1); /* The new RFC2045 section is MIME compliant */ if ((newp->mime_version=strdup(p->mime_version)) == 0) rfc2045_enomem(); return; } p=p->lastpart; ++num_levels; } /* Ok, we've found the RFC2045 section that we're working with. ** No what? */ if (! p->workinheader) { /* Processing body, just update the counts. */ size_t cnt_update=cnt; if (bit8 && !p->content_8bit && (p->rfcviolation & RFC2045_ERR8BITCONTENT) == 0) { struct rfc2045 *q; for (q=p; q; q=q->parent) q->rfcviolation |= RFC2045_ERR8BITCONTENT; } /* ** In multiparts, the final newline in a part belongs to the ** boundary, otherwise, include it in the text. */ if (p->parent && p->parent->content_type && strncasecmp(p->parent->content_type, "multipart/", 10) == 0) cnt_update=n; if (!p->lastpart || !p->lastpart->workclosed) { if (rwp && !p->isdummy) (*rwp->section_contents)(c, cnt); update_counts(p, p->endpos+cnt, p->endpos+cnt_update, 1); } return; } if (bit8 && (p->rfcviolation & RFC2045_ERR8BITHEADER) == 0) { struct rfc2045 *q; for (q=p; q; q=q->parent) q->rfcviolation |= RFC2045_ERR8BITHEADER; } /* In the header */ if ( n == 0 ) /* End of header, body begins. Parse header. */ { do_header(p); /* Clean up any left over header line */ p->workinheader=0; /* Message body starts right here */ p->startbody=p->endpos+cnt; update_counts(p, p->startbody, p->startbody, 1); --p->nbodylines; /* Don't count the blank line */ /* Discard content type and boundary if I don't understand ** this MIME flavor. */ if (!RFC2045_ISMIME1(p->mime_version)) { set_string(&p->content_type, 0); rfc2045_freeattr(p->content_type_attr); p->content_type_attr=0; set_string(&p->content_disposition, 0); rfc2045_freeattr(p->content_disposition_attr); p->content_disposition_attr=0; if (p->boundary) { free(p->boundary); p->boundary=0; } } /* Normally, if we don't have a content_type, default it ** to text/plain. However, if the multipart type is ** multipart/digest, it is message/rfc822. */ if (RFC2045_ISMIME1(p->mime_version) && !p->content_type) { char *q="text/plain"; if (p->parent && p->parent->content_type && strcmp(p->parent->content_type, "multipart/digest") == 0) q="message/rfc822"; set_string(&p->content_type, q); } /* If this is not a multipart section, we don't want to ** hear about any boundaries */ if (!p->content_type || strncmp(p->content_type, "multipart/", 10)) { if (p->boundary) free(p->boundary); p->boundary=0; } /* If this section's a message, we will expect to see ** more RFC2045 stuff, so create a nested RFC2045 structure, ** and indicate that we expect to see headers. */ if (p->content_type && strcmp(p->content_type, "message/rfc822") == 0) { newp=append_part_noinherit(p, p->startbody); newp->workinheader=1; return; } /* ** If this is a multipart message (boundary defined), ** create a RFC2045 structure for the pseudo-section ** that precedes the first boundary line. */ if (ContentBoundary(p)) { newp=append_part(p, p->startbody); newp->workinheader=0; newp->isdummy=1; /* It's easier just to create it. */ return; } if (rwp) (*rwp->start_section)(p); return; } /* RFC822 header continues */ update_counts(p, p->endpos + cnt, p->endpos+n, 1); /* If this header line starts with a space, append one space ** to the saved contents of the previous line, and append this ** line to it. */ if (isspace((int)(unsigned char)*c)) { rfc2045_add_buf(&p->header, &p->headersize, &p->headerlen, " ", 1); } else { /* Otherwise the previous header line is complete, so process it */ do_header(p); p->headerlen=0; } /* Save this line in the header buffer, because the next line ** could be a continuation. */ rfc2045_add_buf( &p->header, &p->headersize, &p->headerlen, c, n); }
void userlist_add (struct session *sess, char *name, char *hostname, char *account, char *realname, const message_tags_data *tags_data) { struct User *user; int row, prefix_chars; unsigned int acc; acc = nick_access (sess->server, name, &prefix_chars); notify_set_online (sess->server, name + prefix_chars, tags_data); user = g_new0 (struct User, 1); user->access = acc; /* assume first char is the highest level nick prefix */ if (prefix_chars) user->prefix[0] = name[0]; /* add it to our linked list */ if (hostname) user->hostname = g_strdup (hostname); safe_strcpy (user->nick, name + prefix_chars, NICKLEN); /* is it me? */ if (!sess->server->p_cmp (user->nick, sess->server->nick)) user->me = TRUE; /* extended join info */ if (sess->server->have_extjoin) { if (account && *account) user->account = g_strdup (account); if (realname && *realname) user->realname = g_strdup (realname); } row = userlist_insertname (sess, user); /* duplicate? some broken servers trigger this */ if (row == -1) { g_free (user->hostname); g_free (user->account); g_free (user->realname); g_free (user); return; } sess->total++; /* most ircds don't support multiple modechars in front of the nickname for /NAMES - though they should. */ while (prefix_chars) { update_counts (sess, user, name[0], TRUE, 1); name++; prefix_chars--; } if (user->me) sess->me = user; fe_userlist_insert (sess, user, FALSE); fe_userlist_numbers (sess); }