Beispiel #1
0
void mt_ns_not(mpacket mp, session s)
{
    int i = 0;
    xmlnode msg, oob1, oob2;
    /* message body spool*/
    pool p = pool_new();
    spool sp = spool_new(p);
    /* parsing the message... */
    xmlnode notification, msgtag, action, subscr, body, text;
    spool action_url = spool_new(p);
    spool subscr_url = spool_new(p);
    char *chunk, *fixedchunk, *notification_id, *msg_id, *bodytext;

    if (s->ti->inbox_headlines == 0)
        return;

    /* grab the <notification/> chunk */
    for(i = 2; i < mp->count; i++) {
        spool_add(sp, mt_packet_data(mp,i));
    }

    msg = xmlnode_new_tag("message");
    xmlnode_put_attrib(msg,"to",jid_full(s->id));
    xmlnode_put_attrib(msg,"from",s->host);
    xmlnode_put_attrib(msg,"type","headline");

    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"subject"),"MSN Alert",-1);

    /* Parse the alert -- there's probably better ways to do this */
    chunk = spool_print(sp);
    log_debug(ZONE, "chunk from spool_print: \"%s\"", chunk);
    fixedchunk = mt_fix_amps(p, chunk);
    log_debug(ZONE, "fixedchunk: \"%s\"", fixedchunk);
    // Get the notification ID
    notification = xmlnode_str(fixedchunk, strlen(fixedchunk));
    notification_id = xmlnode_get_attrib(notification, "id");
    log_debug(ZONE, "notification - %X\nn_id - %s", notification, notification_id);
    // Get the message ID
    msgtag = xmlnode_get_tag(notification, "MSG");
    msg_id = xmlnode_get_attrib(msgtag, "id");
    // Get the action URL
    action = xmlnode_get_tag(msgtag, "ACTION");
    spool_add(action_url, xmlnode_get_attrib(action, "url"));
    spool_add(action_url, "&notification=");
    spool_add(action_url, notification_id);
    spool_add(action_url, "&message_id=");
    spool_add(action_url, msg_id);
    spool_add(action_url, "&agent=messenger");
    // Get the subscription URL
    subscr = xmlnode_get_tag(msgtag, "SUBSCR");
    spool_add(subscr_url, xmlnode_get_attrib(subscr, "url"));
    spool_add(subscr_url, "&notification=");
    spool_add(subscr_url, notification_id);
    spool_add(subscr_url, "&message_id=");
    spool_add(subscr_url, msg_id);
    spool_add(subscr_url, "&agent=messenger");
    // Get the body
    body = xmlnode_get_tag(msgtag, "BODY");
    text = xmlnode_get_tag(body, "TEXT");
    bodytext = xmlnode_get_data(text);
    /* Finished parsing the XML */

    // Insert the body
    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),bodytext,-1);
    
    // Insert the action URL
    oob1 = xmlnode_insert_tag(msg,"x");
    xmlnode_put_attrib(oob1,"xmlns","jabber:x:oob");
    xmlnode_insert_cdata(xmlnode_insert_tag(oob1,"url"),spool_print(action_url),-1);
    xmlnode_insert_cdata(xmlnode_insert_tag(oob1,"desc"),"More information on this alert",-1);
    
    // Insert the subscription URL
    oob2 = xmlnode_insert_tag(msg,"x");
    xmlnode_put_attrib(oob2,"xmlns","jabber:x:oob");
    xmlnode_insert_cdata(xmlnode_insert_tag(oob2,"url"),spool_print(subscr_url),-1);
    xmlnode_insert_cdata(xmlnode_insert_tag(oob2,"desc"),"Manage subscriptions to alerts",-1);

    mt_deliver(s->ti,msg);
    
    xmlnode_free(notification);
    
    pool_free(p);   
}
Beispiel #2
0
char* get_avatar(char* uin)
{
  CURL *curl_handle;
  char* xml_url=malloc(strlen(uin)+200*sizeof(char));
  struct MemoryStruct chunk;
  xmlnode xml = NULL;
  xmlnode xmlnode_users;
  xmlnode xmlnode_user;
  xmlnode xmlnode_avatars;
  xmlnode xmlnode_avatar;
  xmlnode xmlnode_bigavatar;
  char* is_blank;

  chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
  chunk.size = 0;    /* no data at this point */

  curl_global_init(CURL_GLOBAL_ALL);

  /* init the curl session */
  curl_handle = curl_easy_init();

  /* specify URL to get */
  sprintf(xml_url,"http://api.gadu-gadu.pl/avatars/%s/0.xml", uin);
  curl_easy_setopt(curl_handle, CURLOPT_URL, xml_url);

  /* send all data to this function  */
  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

  /* we pass our 'chunk' struct to the callback function */
  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);

  /* some servers don't like requests that are made without a user-agent
     field, so we provide one */
  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.5)");

  /* get it! */
  curl_easy_perform(curl_handle);

  xml = xmlnode_str(chunk.memory, strlen(chunk.memory));
  xmlnode_users = xmlnode_get_tag(xml, "users");
  xmlnode_user = xmlnode_get_tag(xmlnode_users, "user");
  xmlnode_avatars = xmlnode_get_tag(xmlnode_user, "avatars");
  xmlnode_avatar = xmlnode_get_tag(xmlnode_avatars, "avatar");
  xmlnode_bigavatar = xmlnode_get_tag(xmlnode_avatar, "originBigAvatar");
  is_blank = xmlnode_get_attrib(xmlnode_avatar, "blank");
  xml_url = xmlnode_get_data(xmlnode_bigavatar);

  chunk.memory = NULL;
  chunk.size=0;

  curl_easy_setopt(curl_handle, CURLOPT_URL, xml_url);
  curl_easy_perform(curl_handle);

  /* cleanup curl stuff */
  curl_easy_cleanup(curl_handle);

  free(chunk.memory);

  /* we're done with libcurl, so clean it up */
  curl_global_cleanup();

  if(!strlen(is_blank))
   return g_base64_encode(chunk.memory,chunk.size);
  else
   return "0";
}