/* reads buddy list from server and populates purple blist */ void gfire_packet_131(PurpleConnection *gc, int packet_len) { int index = 0; int itmp = 0; int i = 0; gfire_buddy *gf_buddy = NULL; GList *friends = NULL; GList *nicks = NULL; GList *userids = NULL; GList *f,*n,*u; gchar uids[(XFIRE_USERID_LEN*2)+1]; gfire_data *gfire = (gfire_data *)gc->proto_data; if (packet_len < 16) { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: packet 131 recv'd but way too short?!? %d bytes\n", packet_len); return; } index = 6; itmp = gfire_read_attrib(&friends, gfire->buff_in + index, packet_len - index, "friends", TRUE, FALSE, 0, 0, 0); if (itmp < 1 ) { //FIXME add mem cleanup code FIXME("gfire_read_attrib returned < 1! friends"); return; } index += itmp + 1; itmp = gfire_read_attrib(&nicks, gfire->buff_in + index, packet_len - index, "nick", TRUE, FALSE, 0, 0, 0); if (itmp < 1 ) { //FIXME add mem cleanup code FIXME("gfire_read_attrib returned < 1! nicks"); return; } index+= itmp + 1; itmp = gfire_read_attrib(&userids, gfire->buff_in + index, packet_len - index, "userid", FALSE, TRUE, 0, 0, XFIRE_USERID_LEN); if (itmp < 1 ) { //FIXME add mem cleanup code FIXME("gfire_read_attrib returned < 1! userids"); return; } friends = g_list_first(friends); nicks = g_list_first(nicks); userids = g_list_first(userids); f = friends; u = userids; n = nicks; while (NULL != f) { gf_buddy = g_malloc0(sizeof(gfire_buddy)); gfire->buddies = g_list_append(gfire->buddies, (gpointer *) gf_buddy); gf_buddy->name = (gchar *)f->data; gf_buddy->alias = (gchar *)n->data; gf_buddy->userid = (guint8 *)u->data; if (NULL == gf_buddy->alias) gf_buddy->alias = g_strdup(gf_buddy->name); /* make userid into string */ for(i = 0;i < XFIRE_USERID_LEN; i++) g_sprintf(uids + (i*2), "%02x", gf_buddy->userid[i]); uids[(XFIRE_USERID_LEN*2)+1]=0x00; gf_buddy->uid_str = g_strdup(uids); f->data = NULL; u->data = NULL; n->data = NULL; /* so we don't free stuff we don't want to */ f = g_list_next(f); u = g_list_next(u); n = g_list_next(n); } g_list_free(friends); // g_list_free(userids); /* segfaults if we free this? why? */ //FIXME g_list_free(nicks); n = gfire->buddies; while (n != NULL) { gf_buddy = (gfire_buddy *)n->data; purple_debug(PURPLE_DEBUG_MISC, "gfire", "buddy info: %s, %s, %02x%02x%02x%02x, %s\n", NN(gf_buddy->name), NN(gf_buddy->uid_str), NNA(gf_buddy->userid, gf_buddy->userid[0]), NNA(gf_buddy->userid, gf_buddy->userid[1]), NNA(gf_buddy->userid, gf_buddy->userid[2]), NNA(gf_buddy->userid, gf_buddy->userid[3]), NN(gf_buddy->alias)); n = g_list_next(n); } }
/* called with the main thread */ static int APP_CC session_start_fork(int width, int height, int bpp, char *username, char *password, tbus data, tui8 type, char *domain, char *program, char *directory, char *client_ip) { int display = 0; int pid = 0; int wmpid = 0; int xpid = 0; int i = 0; char geometry[32]; char depth[32]; char screen[32]; char text[256]; char passwd_file[256]; char **pp1 = (char **)NULL; struct session_chain *temp = (struct session_chain *)NULL; struct list *xserver_params = (struct list *)NULL; time_t ltime; struct tm stime; char execvpparams[2048]; /* initialize (zero out) local variables: */ g_memset(<ime, 0, sizeof(time_t)); g_memset(&stime, 0, sizeof(struct tm)); g_memset(geometry, 0, sizeof(char) * 32); g_memset(depth, 0, sizeof(char) * 32); g_memset(screen, 0, sizeof(char) * 32); g_memset(text, 0, sizeof(char) * 256); g_memset(passwd_file, 0, sizeof(char) * 256); /* check to limit concurrent sessions */ if (g_session_count >= g_cfg->sess.max_sessions) { log_message(LOG_LEVEL_INFO, "max concurrent session limit " "exceeded. login for user %s denied", username); return 0; } temp = (struct session_chain *)g_malloc(sizeof(struct session_chain), 0); if (temp == 0) { log_message(LOG_LEVEL_ERROR, "cannot create new chain " "element - user %s", username); return 0; } temp->item = (struct session_item *)g_malloc(sizeof(struct session_item), 0); if (temp->item == 0) { g_free(temp); log_message(LOG_LEVEL_ERROR, "cannot create new session " "item - user %s", username); return 0; } display = session_get_aval_display_from_chain(); if (display == 0) { g_free(temp->item); g_free(temp); return 0; } pid = g_fork(); if (pid == -1) { } else if (pid == 0) /* child sesman */ { g_tcp_close(g_sck); g_tcp_close(g_thread_sck); auth_start_session(data, display); g_sprintf(geometry, "%dx%d", width, height); g_sprintf(depth, "%d", bpp); g_sprintf(screen, ":%d", display); wmpid = g_fork(); if (wmpid == -1) { } else if (wmpid == 0) /* child (child sesman) xserver */ { wait_for_xserver(display); env_set_user(username, 0, display); if (x_server_running(display)) { auth_set_env(data); if (directory != 0) { if (directory[0] != 0) { g_set_current_dir(directory); } } if (program != 0) { if (program[0] != 0) { g_execlp3(program, program, 0); log_message(LOG_LEVEL_ALWAYS, "error starting program %s for user %s - pid %d", program, username, g_getpid()); } } /* try to execute user window manager if enabled */ if (g_cfg->enable_user_wm) { g_sprintf(text, "%s/%s", g_getenv("HOME"), g_cfg->user_wm); if (g_file_exist(text)) { g_execlp3(text, g_cfg->user_wm, 0); log_message(LOG_LEVEL_ALWAYS, "error starting user " "wm for user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message(LOG_LEVEL_DEBUG, "errno: %d, " "description: %s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execlp3 parameter " "list:"); log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text); log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->user_wm); } } /* if we're here something happened to g_execlp3 so we try running the default window manager */ g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm); g_execlp3(text, g_cfg->default_wm, 0); log_message( LOG_LEVEL_ALWAYS, "error starting default " "wm for user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message( LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:"); log_message(LOG_LEVEL_DEBUG, " argv[0] = %s", text); log_message(LOG_LEVEL_DEBUG, " argv[1] = %s", g_cfg->default_wm); /* still a problem starting window manager just start xterm */ g_execlp3("xterm", "xterm", 0); /* should not get here */ log_message(LOG_LEVEL_ALWAYS, "error starting xterm " "for user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); } else { log_message(LOG_LEVEL_ERROR, "another Xserver might " "already be active on display %d - see log", display); } log_message(LOG_LEVEL_DEBUG, "aborting connection..."); g_exit(0); } else /* parent (child sesman) */ { xpid = g_fork(); if (xpid == -1) { } else if (xpid == 0) /* child */ { env_set_user(username, passwd_file, display); env_check_password_file(passwd_file, password); if (type == SESMAN_SESSION_TYPE_XVNC) { xserver_params = list_create(); xserver_params->auto_free = 1; /* these are the must have parameters */ list_add_item(xserver_params, (long)g_strdup("Xvnc")); list_add_item(xserver_params, (long)g_strdup(screen)); list_add_item(xserver_params, (long)g_strdup("-geometry")); list_add_item(xserver_params, (long)g_strdup(geometry)); list_add_item(xserver_params, (long)g_strdup("-depth")); list_add_item(xserver_params, (long)g_strdup(depth)); list_add_item(xserver_params, (long)g_strdup("-rfbauth")); list_add_item(xserver_params, (long)g_strdup(passwd_file)); /* additional parameters from sesman.ini file */ //config_read_xserver_params(SESMAN_SESSION_TYPE_XVNC, // xserver_params); list_append_list_strdup(g_cfg->vnc_params, xserver_params, 0); /* make sure it ends with a zero */ list_add_item(xserver_params, 0); pp1 = (char **)xserver_params->items; log_message(LOG_LEVEL_INFO, "Xvnc start:%s", dumpItemsToString(xserver_params, execvpparams, 2048)); g_execvp("Xvnc", pp1); } else if (type == SESMAN_SESSION_TYPE_XRDP) { xserver_params = list_create(); xserver_params->auto_free = 1; /* these are the must have parameters */ list_add_item(xserver_params, (long)g_strdup("X11rdp")); list_add_item(xserver_params, (long)g_strdup(screen)); list_add_item(xserver_params, (long)g_strdup("-geometry")); list_add_item(xserver_params, (long)g_strdup(geometry)); list_add_item(xserver_params, (long)g_strdup("-depth")); list_add_item(xserver_params, (long)g_strdup(depth)); /* additional parameters from sesman.ini file */ //config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP, // xserver_params); list_append_list_strdup(g_cfg->rdp_params, xserver_params, 0); /* make sure it ends with a zero */ list_add_item(xserver_params, 0); pp1 = (char **)xserver_params->items; log_message(LOG_LEVEL_INFO, "X11rdp start:%s", dumpItemsToString(xserver_params, execvpparams, 2048)); g_execvp("X11rdp", pp1); } else { log_message(LOG_LEVEL_ALWAYS, "bad session type - " "user %s - pid %d", username, g_getpid()); g_exit(1); } /* should not get here */ log_message(LOG_LEVEL_ALWAYS, "error starting X server " "- user %s - pid %d", username, g_getpid()); /* logging parameters */ log_message(LOG_LEVEL_DEBUG, "errno: %d, description: " "%s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execve parameter list size: " "%d", (xserver_params)->count); for (i = 0; i < (xserver_params->count); i++) { log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char *)list_get_item(xserver_params, i)); } list_delete(xserver_params); g_exit(1); } else /* parent (child sesman)*/ { wait_for_xserver(display); g_snprintf(text, 255, "%d", display); g_setenv("XRDP_SESSVC_DISPLAY", text, 1); g_snprintf(text, 255, ":%d.0", display); g_setenv("DISPLAY", text, 1); /* new style waiting for clients */ session_start_sessvc(xpid, wmpid, data, username, display); } } } else /* parent sesman process */ { temp->item->pid = pid; temp->item->display = display; temp->item->width = width; temp->item->height = height; temp->item->bpp = bpp; temp->item->data = data; g_strncpy(temp->item->client_ip, client_ip, 255); /* store client ip data */ g_strncpy(temp->item->name, username, 255); ltime = g_time1(); localtime_r(<ime, &stime); temp->item->connect_time.year = (tui16)(stime.tm_year + 1900); temp->item->connect_time.month = (tui8)stime.tm_mon; temp->item->connect_time.day = (tui8)stime.tm_mday; temp->item->connect_time.hour = (tui8)stime.tm_hour; temp->item->connect_time.minute = (tui8)stime.tm_min; zero_time(&(temp->item->disconnect_time)); zero_time(&(temp->item->idle_time)); temp->item->type = type; temp->item->status = SESMAN_SESSION_STATUS_ACTIVE; temp->next = g_sessions; g_sessions = temp; g_session_count++; } return display; }
WebResponse* TransactionHandler::ExecuteByMap(WebRequest* pWebRequest, WebContext* pWebContext, User* pUser) { GLogger *pLogger = augeGetLoggerInstance(); TransactionRequest* pRequest = static_cast<TransactionRequest*>(pWebRequest); const char* mapName = pRequest->GetMapName(); if(mapName==NULL) { char msg[AUGE_MSG_MAX]; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); g_sprintf(msg, "No Map is attached"); pLogger->Error(msg, __FILE__, __LINE__); pExpResponse->SetMessage(msg); return pExpResponse; } CartoManager* pCartoManager = augeGetCartoManagerInstance(); Map *pMap = pCartoManager->LoadMap(pUser->GetID(), mapName); if(pMap==NULL) { char msg[AUGE_MSG_MAX]; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); g_sprintf(msg, "Cannot load map [%s]", mapName); pLogger->Error(msg, __FILE__, __LINE__); pExpResponse->SetMessage(msg); return pExpResponse; } const char* typeName = NULL; Layer* pLayer = NULL; XDocument* pxDoc = NULL; pxDoc = pRequest->GetXmlDoc(); if(pxDoc==NULL) { const char* msg = "transaction xml parse error"; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); pExpResponse->SetMessage(msg); pLogger->Error(msg, __FILE__, __LINE__); return pExpResponse; } XNodeSet *pxNodeSet = NULL; XElement *pxRoot = pxDoc->GetRootNode(); pxNodeSet = pxRoot->GetChildren("Insert"); g_uint num_insert = Insert(pxNodeSet, pWebContext, pMap); pxNodeSet->Release(); pxNodeSet = pxRoot->GetChildren("Update"); g_uint num_update = Update(pxNodeSet, pWebContext, pMap); pxNodeSet->Release(); pxNodeSet = pxRoot->GetChildren("Delete"); g_uint num_delete = Delete(pxNodeSet, pWebContext, pMap); pxNodeSet->Release(); TransactionResponse *pResponse = new TransactionResponse(pRequest); pResponse->SetInsertCount(num_insert); pResponse->SetUpdateCount(num_update); pResponse->SetDeleteCount(num_delete); pMap->Release(); return pResponse; }
/* FIXME: Throw error */ static GdkPixbuf* download_image(GtResourceDownloader* self, const gchar* uri, const gchar* name, SoupMessage* msg, GInputStream* istream, gboolean* from_file, GError** error) { RETURN_VAL_IF_FAIL(GT_IS_RESOURCE_DOWNLOADER(self), NULL); RETURN_VAL_IF_FAIL(!utils_str_empty(uri), NULL); RETURN_VAL_IF_FAIL(SOUP_IS_MESSAGE(msg), NULL); RETURN_VAL_IF_FAIL(G_IS_INPUT_STREAM(istream), NULL); GtResourceDownloaderPrivate* priv = gt_resource_downloader_get_instance_private(self); g_autofree gchar* filename = NULL; gint64 file_timestamp = 0; gboolean file_exists = FALSE; g_autoptr(GdkPixbuf) ret = NULL; g_autoptr(GError) err = NULL; /* NOTE: If we aren't supplied a filename, we'll just create one by hashing the uri */ if (utils_str_empty(name)) { gchar hash_str[15]; guint hash = 0; hash = g_str_hash(uri); /* TODO: Replace this with murmur3 hash */ g_sprintf(hash_str, "%ud", hash); filename = g_build_filename(priv->filepath, hash_str, NULL); } else filename = g_build_filename(priv->filepath, name, NULL); if (priv->filepath && (file_exists = g_file_test(filename, G_FILE_TEST_EXISTS))) { file_timestamp = utils_timestamp_file(filename, NULL); } if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { const gchar* last_modified_str = NULL; DEBUG("Successful return code from uri '%s'", uri); last_modified_str = soup_message_headers_get_one(msg->response_headers, "Last-Modified"); if (utils_str_empty(last_modified_str)) { DEBUG("No 'Last-Modified' header in response from uri '%s'", uri); goto download; } else if (utils_http_full_date_to_timestamp(last_modified_str) < file_timestamp) { DEBUG("No new image at uri '%s'", uri); if (file_exists) { DEBUG("Loading image from file '%s'", filename); ret = gdk_pixbuf_new_from_file(filename, NULL); if (from_file) *from_file = TRUE; } else { DEBUG("Image doesn't exist locally"); goto download; } } else { download: DEBUG("New image at uri '%s'", uri); ret = gdk_pixbuf_new_from_stream(istream, NULL, &err); if (err) { WARNING("Unable to download image from uri '%s' because: %s", uri, err->message); g_propagate_prefixed_error(error, g_steal_pointer(&err), "Unable to download image from uri '%s' because: ", uri); return NULL; } if (priv->filepath && STRING_EQUALS(priv->image_filetype, GT_IMAGE_FILETYPE_JPEG)) { gdk_pixbuf_save(ret, filename, priv->image_filetype, NULL, "quality", "100", NULL); } else if (priv->filepath) { gdk_pixbuf_save(ret, filename, priv->image_filetype, NULL, NULL); } if (from_file) *from_file = FALSE; } } return g_steal_pointer(&ret); }
STATIC gchar* post_rest_form( CURL *curl, const form_field_t *form ) { gchar *url_host; gchar *url_path; gchar *headers; struct curl_write_buffer_t body = { .data = NULL, .size = 0 }; gchar content_length[ 10 ]; gchar *html_post; GRegex *url_split_regex; GMatchInfo *match_info; long socket_value; curl_socket_t socket; size_t bytes_sent; char response_buffer[ 1024 ]; CURLcode status; size_t bytes_received; gboolean read_error; /* Split the form action URL into host and path. */ url_split_regex = g_regex_new( "^http[s?]://([a-zA-Z0-9_\\.-]+)/(.*)$", 0, 0, NULL ); if( g_regex_match( url_split_regex, form_action, 0, &match_info ) ) { url_host = g_match_info_fetch( match_info, 1 ); url_path = g_match_info_fetch( match_info, 2 ); g_match_info_free( match_info ); g_regex_unref( url_split_regex ); /* Build the HTML post. */ if( url_host != NULL ) { /* Build the body. */ if( form_name != NULL ) { body.data = g_strconcat( form_name, "=", form_value, NULL ); body.size = strlen( body.data ); } g_slist_foreach( form->input_fields, fill_body_with_input, &body ); /* Build the headers. */ g_sprintf( content_length, "%d\n\0", (gint) body.size ); headers = g_strconcat( "POST ", url_path, " HTTP/1.1\n", "Host: ", url_host, "\n", "Content-Type: application/x-www-form-urlencoded\n", "Content-Length: ", content_length, NULL ); g_free( url_path ); g_free( url_host ); /* Combine the headers and the body. */ html_post = g_strconcat( headers, "\n", body.data, NULL ); g_free( body.data ); g_free( headers ); printf( "DEBUG: Sending:\n-------\n%s-------", html_post ); /* Prepare a connection. */ curl_easy_setopt( curl, CURLOPT_URL, form_action ); curl_easy_setopt( curl, CURLOPT_CONNECT_ONLY, 1 ); curl_easy_perform( curl ); curl_easy_getinfo( curl, CURLINFO_LASTSOCKET, &socket_value ); socket = socket_value; /* Wait for the socket to become ready for sending. */ if( wait_for_socket( socket, FALSE, 60000L ) == FALSE ) { g_free( html_post ); g_fprintf( stderr, "Timeout connecting to " "the Google REST service\n" ); } else { /* Submit the post. */ curl_easy_send( curl, html_post, strlen( html_post ), &bytes_sent ); /* To do: verify that all the bytes were sent; if not, send the remainding bytes in a second, third, ... call. */ printf( "DEBUG: Sent %d out of %d bytes\n", (int)bytes_sent, (int) strlen(html_post) ); g_free( html_post ); /* Receive the response. */ read_error = FALSE; do { /* Wait for the socket to become ready for receiving. */ if( wait_for_socket( socket, TRUE, 60000L ) == FALSE ) { read_error = TRUE; g_fprintf( stderr, "Timeout connecting to " "the Google REST service\n" ); break; } /* Copy chunks of data into html_response. */ else { status = curl_easy_recv( curl, response_buffer, sizeof( response_buffer ), &bytes_received ); if( status == CURLE_OK ) { receive_curl_response( response_buffer, bytes_received, 1, &html_response ); } } } while( ( status == CURLE_AGAIN ) && ( read_error == FALSE ) ); printf( "DEBUG: CURL code %d: %s\n", (int)status, curl_easy_strerror( status ) ); } } } } #endif #if 0 /** * Auxiliary function used by decode_user_code_response to copy a JSON * response into a local data structure. * @param node [in] Object with JSON data (unused). * @param member_name [in] Name of the JSON field. * @param member_node [in] Node with JSON data. * @param user_code_ptr [out] Pointer to the structure where the JSON * data will be stored. * @return Nothing. */ STATIC void parse_user_code_json( const gchar *member_name, JsonNode *member_node, gpointer user_code_ptr ) { struct user_code_t *user_code = user_code_ptr; SET_JSON_MEMBER( user_code, device_code ); SET_JSON_MEMBER( user_code, verification_url ); SET_JSON_MEMBER( user_code, user_code ); } #endif /** * Decode the initial OAuth2 response with device code, user code, and * verification URL. * @param user_code_response [in] Raw JSON response data. * @return \a user_code_t structure with authentication data, or \a FALSE * if the user code could not be obtained. */ #if 0 STATIC struct user_code_t* decode_user_code_response( const gchar *user_code_response ) { struct user_code_t *user_code; user_code = g_new0( struct user_code_t, 1 ); if( user_code_response != NULL ) { /* Decode the JSON response. */ decode_json_reply( user_code_response, parse_user_code_json, user_code ); /* Verify that all fields have been decoded. */ if( ( user_code->device_code == NULL ) || ( user_code->user_code == NULL ) || ( user_code->verification_url == NULL ) ) { g_free( (gchar*) user_code->device_code ); g_free( (gchar*) user_code->user_code ); g_free( (gchar*) user_code->verification_url ); g_free( user_code ); user_code = NULL; } } return( user_code ); } #endif /** * Obtain a device code for device access. The CURL session must include the * user's login to Google, which may be obtained by calling \a login_to_gmail * with the user's credentials. * @param curl [in] CURL handle. * @param client_id [in] Google Developer Client ID. * @return Device code or \a NULL if an error occurred. * Test: manual (via non-automated test). */ struct user_code_t* obtain_device_code( CURL *curl, const gchar *client_id ) { /* Note: the following code is more elegant than the code that is currently used but is disabled because a bug in Google's API system prevents devices from using the tasks scope. */ #if 0 static gchar *form_action = "https://accounts.google.com/o/oauth2/device/code"; gchar *scope = // "https://www.googleapis.com/auth/userinfo.email " // "https://www.googleapis.com/auth/userinfo.profile"; "https://www.googleapis.com/auth/tasks"; form_field_t form = { .name = NULL, .value = NULL, .action = form_action, .input_fields = NULL }; gchar *user_code_response; struct user_code_t *user_code; gboolean success; /* Create a user code request. */ add_input_to_form( &form, "client_id", client_id ); add_input_to_form( &form, "scope", scope ); /* Post the request and decode the response. */ user_code_response = post_form( curl, &form ); destroy_form_inputs( &form ); g_printf( "%s\n", user_code_response ); user_code = decode_user_code_response( user_code_response ); return( user_code ); #endif } STATIC gboolean submit_approval_form( CURL *curl, const gchar *approval_page ) { form_field_t *approval_form; const gchar *const approval_names[ ] = { "submit_access", NULL }; gchar *form_response; gboolean success; approval_form = find_form( approval_page, "https://accounts.google.com/o/oauth2/", approval_names ); if( approval_form != NULL ) { g_printf( "Submitting approval form\n" ); /* Submit the approval form. */ form_response = post_form( curl, approval_form ); destroy_form( approval_form ); g_free( form_response ); success = TRUE; } else { success = FALSE; } return( success ); }
static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_after; gint txt_len; gint startpos; gint endpos; gint startline; gint endline; gint line_iter; gint linepos; gint linelen; gint startcol; gint endcol; gint i; ScintillaObject *sci; /* get a pointer to the scintilla object */ sci = document_get_current()->editor->sci; if (sci_has_selection(sci)){ startpos = sci_get_selection_start(sci); endpos = sci_get_selection_end(sci); /* sanity check -- we dont care which way the block was selected */ if(startpos > endpos){ i = endpos; endpos = startpos; startpos = i; } startline = sci_get_line_from_position(sci, startpos); linepos = sci_get_position_from_line(sci, startline); endline = sci_get_line_from_position(sci, endpos); /* normal mode */ if(startline == endline){ /* get the text in question */ txt_len = endpos - startpos; txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_after = sci_get_char_at(sci, endpos); /* set up new text buf */ (void) g_sprintf(txt, "%c%s", char_after, txt_i); /* start undo */ sci_start_undo_action(sci); /* put the new text in */ sci_set_selection_end(sci, endpos + 1); sci_replace_sel(sci, txt); /* select the right bit again */ sci_set_selection_start(sci, startpos + 1); sci_set_selection_end(sci, endpos + 1); /* end undo */ sci_end_undo_action(sci); g_free(txt); g_free(txt_i); } /* rectangle mode (we hope!) */ else{ startcol = sci_get_col_from_position(sci, startpos); endcol = sci_get_col_from_position(sci, endpos); /* start undo */ sci_start_undo_action(sci); for(line_iter = startline; line_iter <= endline; line_iter++){ linepos = sci_get_position_from_line(sci, line_iter); linelen = sci_get_line_length(sci, line_iter); /* do we need to do something */ if(linelen >= startcol - 1 ){ /* if between the two columns or at the end */ /* add in a space */ if(linelen <= endcol || linelen - 1 == endcol){ txt = g_malloc(sizeof(gchar) * 2); sprintf(txt, " "); sci_insert_text(sci, linepos + startcol, txt); g_free(txt); } else{ /* move the text itself */ sci_set_selection_mode(sci, 0); sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol); txt_len = sci_get_selected_text_length(sci); txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_after = sci_get_char_at(sci, linepos + endcol); /* set up new text buf */ (void) g_sprintf(txt, "%c%s", char_after, txt_i); /* put the new text in */ sci_set_selection_end(sci, linepos + endcol + 1); sci_replace_sel(sci, txt); g_free(txt); g_free(txt_i); } } } /* put the selection box back */ /* here we rely upon the last result of linepos */ sci_set_selection_mode(sci, 1); sci_set_selection_start(sci, startpos + 1); sci_set_selection_end(sci, linepos + endcol + 1); /* end undo action */ sci_end_undo_action(sci); } } }
/* Thread to handle incoming messages */ static void *janus_streaming_handler(void *data) { JANUS_LOG(LOG_VERB, "Joining thread\n"); janus_streaming_message *msg = NULL; int error_code = 0; char *error_cause = calloc(1024, sizeof(char)); if(error_cause == NULL) { JANUS_LOG(LOG_FATAL, "Memory error!\n"); return NULL; } while(initialized && !stopping) { if(!messages || (msg = g_queue_pop_head(messages)) == NULL) { usleep(50000); continue; } janus_streaming_session *session = (janus_streaming_session *)msg->handle->plugin_handle; if(!session) { JANUS_LOG(LOG_ERR, "No session associated with this handle...\n"); janus_streaming_message_free(msg); continue; } if(session->destroy) { janus_streaming_message_free(msg); continue; } /* Handle request */ error_code = 0; JANUS_LOG(LOG_VERB, "Handling message: %s\n", msg->message); if(msg->message == NULL) { JANUS_LOG(LOG_ERR, "No message??\n"); error_code = JANUS_STREAMING_ERROR_NO_MESSAGE; sprintf(error_cause, "%s", "No message??"); goto error; } json_error_t error; json_t *root = json_loads(msg->message, 0, &error); if(!root) { JANUS_LOG(LOG_ERR, "JSON error: on line %d: %s\n", error.line, error.text); error_code = JANUS_STREAMING_ERROR_INVALID_JSON; sprintf(error_cause, "JSON error: on line %d: %s", error.line, error.text); goto error; } if(!json_is_object(root)) { JANUS_LOG(LOG_ERR, "JSON error: not an object\n"); error_code = JANUS_STREAMING_ERROR_INVALID_JSON; sprintf(error_cause, "JSON error: not an object"); goto error; } json_t *request = json_object_get(root, "request"); if(!request) { JANUS_LOG(LOG_ERR, "Missing element (request)\n"); error_code = JANUS_STREAMING_ERROR_MISSING_ELEMENT; sprintf(error_cause, "Missing element (request)"); goto error; } if(!json_is_string(request)) { JANUS_LOG(LOG_ERR, "Invalid element (request should be a string)\n"); error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT; sprintf(error_cause, "Invalid element (request should be a string)"); goto error; } const char *request_text = json_string_value(request); json_t *result = NULL; char *sdp_type = NULL, *sdp = NULL; if(!strcasecmp(request_text, "list")) { result = json_object(); json_t *list = json_array(); JANUS_LOG(LOG_VERB, "Request for the list of mountpoints\n"); /* Return a list of all available mountpoints */ GList *mountpoints_list = g_hash_table_get_values(mountpoints); GList *m = mountpoints_list; while(m) { janus_streaming_mountpoint *mp = (janus_streaming_mountpoint *)m->data; json_t *ml = json_object(); json_object_set_new(ml, "id", json_integer(mp->id)); json_object_set_new(ml, "description", json_string(mp->description)); json_object_set_new(ml, "type", json_string(mp->streaming_type == janus_streaming_type_live ? "live" : "on demand")); json_array_append_new(list, ml); m = m->next; } json_object_set_new(result, "list", list); g_list_free(mountpoints_list); } else if(!strcasecmp(request_text, "watch")) { json_t *id = json_object_get(root, "id"); if(id && !json_is_integer(id)) { JANUS_LOG(LOG_ERR, "Invalid element (id should be an integer)\n"); error_code = JANUS_STREAMING_ERROR_INVALID_ELEMENT; sprintf(error_cause, "Invalid element (id should be an integer)"); goto error; } gint64 id_value = json_integer_value(id); janus_streaming_mountpoint *mp = g_hash_table_lookup(mountpoints, GINT_TO_POINTER(id_value)); if(mp == NULL) { JANUS_LOG(LOG_VERB, "No such mountpoint/stream %"SCNu64"\n", id_value); error_code = JANUS_STREAMING_ERROR_NO_SUCH_MOUNTPOINT; sprintf(error_cause, "No such mountpoint/stream %"SCNu64"", id_value); goto error; } JANUS_LOG(LOG_VERB, "Request to watch mountpoint/stream %"SCNu64"\n", id_value); session->stopping = FALSE; session->mountpoint = mp; if(mp->streaming_type == janus_streaming_type_on_demand) { g_thread_new(session->mountpoint->name, &janus_streaming_ondemand_thread, session); } /* TODO Check if user is already watching a stream, if the video is active, etc. */ mp->listeners = g_list_append(mp->listeners, session); sdp_type = "offer"; /* We're always going to do the offer ourselves, never answer */ char sdptemp[1024]; memset(sdptemp, 0, 1024); gchar buffer[100]; memset(buffer, 0, 100); gint64 sessid = janus_get_monotonic_time(); gint64 version = sessid; /* FIXME This needs to be increased when it changes, so time should be ok */ g_sprintf(buffer, "v=0\r\no=%s %"SCNu64" %"SCNu64" IN IP4 127.0.0.1\r\n", "-", sessid, version); g_strlcat(sdptemp, buffer, 1024); g_strlcat(sdptemp, "s=Streaming Test\r\nt=0 0\r\n", 1024); if(mp->codecs.audio_pt >= 0) { /* Add audio line */ g_sprintf(buffer, "m=audio 1 RTP/SAVPF %d\r\n" "c=IN IP4 1.1.1.1\r\n", mp->codecs.audio_pt); g_strlcat(sdptemp, buffer, 1024); if(mp->codecs.audio_rtpmap) { g_sprintf(buffer, "a=rtpmap:%d %s\r\n", mp->codecs.audio_pt, mp->codecs.audio_rtpmap); g_strlcat(sdptemp, buffer, 1024); } g_strlcat(sdptemp, "a=sendonly\r\n", 1024); } if(mp->codecs.video_pt >= 0) { /* Add video line */ g_sprintf(buffer, "m=video 1 RTP/SAVPF %d\r\n" "c=IN IP4 1.1.1.1\r\n", mp->codecs.video_pt); g_strlcat(sdptemp, buffer, 1024); if(mp->codecs.video_rtpmap) { g_sprintf(buffer, "a=rtpmap:%d %s\r\n", mp->codecs.video_pt, mp->codecs.video_rtpmap); g_strlcat(sdptemp, buffer, 1024); } g_strlcat(sdptemp, "a=sendonly\r\n", 1024); } sdp = g_strdup(sdptemp); JANUS_LOG(LOG_VERB, "Going to offer this SDP:\n%s\n", sdp); result = json_object(); json_object_set_new(result, "status", json_string("preparing")); } else if(!strcasecmp(request_text, "start")) { JANUS_LOG(LOG_VERB, "Starting the streaming\n"); result = json_object(); /* We wait for the setup_media event to start: on the other hand, it may have already arrived */ json_object_set_new(result, "status", json_string(session->started ? "started" : "starting")); } else if(!strcasecmp(request_text, "pause")) { JANUS_LOG(LOG_VERB, "Pausing the streaming\n"); session->started = FALSE; result = json_object(); json_object_set_new(result, "status", json_string("pausing")); } else if(!strcasecmp(request_text, "stop")) { JANUS_LOG(LOG_VERB, "Stopping the streaming\n"); session->stopping = TRUE; session->started = FALSE; result = json_object(); json_object_set_new(result, "status", json_string("stopping")); if(session->mountpoint) { JANUS_LOG(LOG_VERB, " -- Removing the session from the mountpoint listeners\n"); if(g_list_find(session->mountpoint->listeners, session) != NULL) { JANUS_LOG(LOG_VERB, " -- -- Found!\n"); } session->mountpoint->listeners = g_list_remove_all(session->mountpoint->listeners, session); } session->mountpoint = NULL; } else { JANUS_LOG(LOG_VERB, "Unknown request '%s'\n", request_text); error_code = JANUS_STREAMING_ERROR_INVALID_REQUEST; sprintf(error_cause, "Unknown request '%s'", request_text); goto error; } /* Any SDP to handle? */ if(msg->sdp) { JANUS_LOG(LOG_VERB, "This is involving a negotiation (%s) as well (but we really don't care):\n%s\n", msg->sdp_type, msg->sdp); } json_decref(root); /* Prepare JSON event */ json_t *event = json_object(); json_object_set_new(event, "streaming", json_string("event")); if(result != NULL) json_object_set(event, "result", result); char *event_text = json_dumps(event, JSON_INDENT(3)); json_decref(event); if(result != NULL) json_decref(result); JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text); int ret = gateway->push_event(msg->handle, &janus_streaming_plugin, msg->transaction, event_text, sdp_type, sdp); JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); g_free(event_text); if(sdp) g_free(sdp); janus_streaming_message_free(msg); continue; error: { if(root != NULL) json_decref(root); /* Prepare JSON error event */ json_t *event = json_object(); json_object_set_new(event, "streaming", json_string("event")); json_object_set_new(event, "error_code", json_integer(error_code)); json_object_set_new(event, "error", json_string(error_cause)); char *event_text = json_dumps(event, JSON_INDENT(3)); json_decref(event); JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text); int ret = gateway->push_event(msg->handle, &janus_streaming_plugin, msg->transaction, event_text, NULL, NULL); JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); g_free(event_text); janus_streaming_message_free(msg); } } g_free(error_cause); JANUS_LOG(LOG_VERB, "Leaving thread\n"); return NULL; }
int DEFAULT_CC send_session(int client, int session_id, char* user) { struct session_item* sess = NULL; xmlNodePtr node, node2; xmlDocPtr doc; xmlChar* version; xmlChar* response; xmlChar* session; xmlChar* id; xmlChar* id_value; xmlChar* username; xmlChar* username_value; xmlChar* status; xmlChar* status_value; log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_session]: " "request for session\n"); lock_chain_acquire(); if (user == NULL || user[0] == '\0') { sess = session_get_by_display(session_id); } else { sess = session_get_bydata(user); } lock_chain_release(); if( sess == NULL && session_id != 0) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_session]: " "the session %i did not exist",session_id); sess = g_malloc(sizeof(struct session_item), 1); sess->display = session_id; sess->status = SESMAN_SESSION_STATUS_UNKNOWN; g_snprintf(sess->name, sizeof(sess->name), "UNKNOW"); } version = xmlCharStrdup("1.0"); doc = xmlNewDoc(version); if (doc == NULL) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_session]: " "Unable to create the document"); if (sess != NULL) { g_free(sess); } return 1; } doc->encoding = xmlCharStrdup("UTF-8"); response = xmlCharStrdup("response"); session = xmlCharStrdup("session"); node = xmlNewNode(NULL, response); node2 = xmlNewNode(NULL, session); if (sess != NULL) { char prop[128] = {0}; g_sprintf(prop, "%i", sess->display); id = xmlCharStrdup("id"); id_value = xmlCharStrdup(prop); username = xmlCharStrdup("username"); username_value = xmlCharStrdup(sess->name); status = xmlCharStrdup("status"); status_value = xmlCharStrdup(session_get_status_string(sess->status)); xmlSetProp(node2, id, id_value); xmlSetProp(node2, username, username_value); xmlSetProp(node2, status, status_value ); xmlAddChild(node, node2); } xmlDocSetRootElement(doc, node); xml_send_info(client, doc); xmlFree(response); xmlFree(session); xmlFree(version); xmlFreeDoc(doc); if (sess != NULL) { xmlFree(id); xmlFree(id_value); xmlFree(username); xmlFree(username_value); xmlFree(status); xmlFree(status_value); g_free(sess); } return 0; }
FeatureClass* DescribeFeatureTypeHandler::GetFeatureClassByMap(WebRequest* pWebRequest, WebContext* pWebContext, User* pUser) { const char* typeName = NULL; Layer* pLayer = NULL; GLogger *pLogger = augeGetLoggerInstance(); DescribeFeatureTypeRequest* pRequest = static_cast<DescribeFeatureTypeRequest*>(pWebRequest); typeName = pRequest->GetTypeName(); const char* mapName = pRequest->GetMapName(); if(mapName==NULL) { GError* pError = augeGetErrorInstance(); pError->SetError("No Map is attached"); return NULL; } CartoManager* pCartoManager = augeGetCartoManagerInstance(); Map *pMap = pCartoManager->LoadMap(pUser->GetID(), mapName); if(pMap==NULL) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "Cannot load map [%s]", mapName); GError* pError = augeGetErrorInstance(); pError->SetError(msg); return NULL; } pLayer = pMap->GetLayer(typeName); if(pLayer==NULL) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "Cannot Find %s has not FeatureType [%s]",pWebContext->GetService(), typeName); pLogger->Error(msg, __FILE__, __LINE__); GError* pError = augeGetErrorInstance(); pError->SetError(msg); return NULL; } if(pLayer->GetType()!=augeLayerFeature) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "%s is not a Feature Layer",typeName); pLogger->Error(msg, __FILE__, __LINE__); GError* pError = augeGetErrorInstance(); pError->SetError(msg); return NULL; } FeatureClass* pFeatureClass = NULL; FeatureLayer* pFLayer = static_cast<FeatureLayer*>(pLayer); pFeatureClass = pFLayer->GetFeatureClass(); if(pFeatureClass==NULL) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "Cannot Get FeatureType %s",typeName); pLogger->Error(msg, __FILE__, __LINE__); GError* pError = augeGetErrorInstance(); pError->SetError(msg); return NULL; } pFeatureClass->AddRef(); return pFeatureClass; }
void note_save(UserInterface *ui) { time_t time_in_s; gchar* title; gchar* content; GtkTextIter iter, start, end; GtkTextMark *mark; gint cursor_position; AppData *app_data = app_data_get(); GtkTextBuffer *buffer = ui->buffer; ConboyNote *note = ui->note; /* If note is empty, don't save */ gtk_text_buffer_get_bounds(buffer, &start, &end); content = gtk_text_iter_get_text(&start, &end); if (is_empty_str(content)) { gtk_text_buffer_set_modified(buffer, FALSE); g_free(content); return; } g_free(content); /* If buffer is not dirty, don't save */ if (!gtk_text_buffer_get_modified(buffer)) { return; } /* Get time */ time_in_s = time(NULL); /* Get cursor position */ mark = gtk_text_buffer_get_insert(buffer); gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark); cursor_position = gtk_text_iter_get_offset(&iter); /* Get title */ title = note_extract_title_from_buffer(buffer); /* Check for duplicated title */ ConboyNote *existing_note = conboy_note_store_find_by_title(app_data->note_store, title); if (existing_note && (existing_note != note)) { /* Save alternative title if title is already taken */ int num = conboy_note_store_get_length(app_data->note_store) + 1; gchar new_title[100]; g_sprintf(new_title, _("New Note %i"), num); g_free(title); title = g_strdup(new_title); } /* Set meta data */ /* We don't change height, width, x and y because we don't use them */ g_object_set(note, "title", title, "change-date", time_in_s, "metadata-change-date", time_in_s, "cursor-position", cursor_position, "open-on-startup", FALSE, NULL); g_free(title); if (note->create_date == 0) { g_object_set(note, "create-date", time_in_s, NULL); } if (note->height == 0) { g_object_set(note, "height", 300, NULL); } if (note->width == 0) { g_object_set(note, "width", 600, NULL); } if (note->x == 0) { g_object_set(note, "x", 1, NULL); } if (note->y == 0) { g_object_set(note, "y", 1, NULL); } /* Clear note content, then set it with fresh data from the text buffer */ content = conboy_note_buffer_get_xml(CONBOY_NOTE_BUFFER(buffer)); /** DEBUG **/ if (!g_str_has_suffix(content, "</note-content>\n")) { g_printerr("WARN: Problem when saving:\n%s\n", content); g_free(content); content = NULL; /* Get XML again. See wheter is's ok now */ content = conboy_note_buffer_get_xml(CONBOY_NOTE_BUFFER(buffer)); if (!g_str_has_suffix(content, "</note-content>\n")) { g_printerr("ERROR: Second save NOT successful\n"); } else { g_printerr("INFO: Second save successful\n"); } gtk_text_buffer_set_modified(buffer, FALSE); return; } /****/ g_object_set(note, "content", content, NULL); g_free(content); /* Save the complete note */ conboy_storage_note_save(app_data->storage, note); /* If first save, add to list of all notes */ if (!conboy_note_store_find(app_data->note_store, note)) { conboy_note_store_add(app_data->note_store, note, NULL); } else { conboy_note_store_note_changed(app_data->note_store, note); } gtk_text_buffer_set_modified(buffer, FALSE); }
int DEFAULT_CC send_sessions(int client) { struct session_item* sess; xmlNodePtr node, node2, node3; xmlDocPtr doc; int count, i; xmlChar* version; xmlChar* encoding; xmlChar* s_node; xmlChar* s_node2; log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: " "request for sessions list"); lock_chain_acquire(); sess = (struct session_item*)session_list_session(&count); lock_chain_release(); log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: " "%i count sessions",count); version = xmlCharStrdup("1.0"); doc = xmlNewDoc(version); if (doc ==NULL) { log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[send_sessions]: " "Unable to create the document"); return 1; } doc->encoding = xmlCharStrdup("UTF-8"); s_node = xmlCharStrdup("response"); node = xmlNewNode(NULL, s_node); s_node2 = xmlCharStrdup("sessions"); node2 = xmlNewNode(NULL, s_node2); xmlAddChild(node, node2); char prop[128]; for ( i=0 ; i<count ; i++) { g_sprintf(prop, "%i", sess[i].display); xmlChar* s_session = xmlCharStrdup("session"); xmlChar* s_id = xmlCharStrdup("id"); xmlChar* s_id_value = xmlCharStrdup(prop); xmlChar* s_username = xmlCharStrdup("username"); xmlChar* s_username_value = xmlCharStrdup(sess[i].name); xmlChar* s_status = xmlCharStrdup("status"); xmlChar* s_status_value = xmlCharStrdup(session_get_status_string(sess[i].status)); node3 = xmlNewNode(NULL, s_session); xmlSetProp(node3, s_id, s_id_value ); xmlSetProp(node3, s_username, s_username_value); xmlSetProp(node3, s_status, s_status_value ); xmlAddChild(node2, node3); xmlFree(s_session); xmlFree(s_id); xmlFree(s_id_value); xmlFree(s_username); xmlFree(s_username_value); xmlFree(s_status); xmlFree(s_status_value); } xmlAddChild(node, node2); xmlDocSetRootElement(doc, node); xml_send_info(client, doc); xmlFree(version); xmlFree(s_node); xmlFree(s_node2); g_free(sess); xmlFreeDoc(doc); return 0; }
WebResponse* SetStyleHandler::Execute(WebRequest* pWebRequest) { SetStyleRequest* pRequest = static_cast<SetStyleRequest*>(pWebRequest); const char* mapName = pRequest->GetMapName(); const char* layerName = pRequest->GetLayerName(); const char* styleName = pRequest->GetStyleName(); if(mapName==NULL) { const char* msg = "Parameter map is null."; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); GLogger* pLogger = augeGetLoggerInstance(); pLogger->Error(msg); pExpResponse->SetMessage(msg); return pExpResponse; } if(layerName==NULL) { const char* msg = "Parameter layer is null."; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); GLogger* pLogger = augeGetLoggerInstance(); pLogger->Error(msg); pExpResponse->SetMessage(msg); return pExpResponse; } if(styleName==NULL) { const char* msg = "Parameter style is null."; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); GLogger* pLogger = augeGetLoggerInstance(); pLogger->Error(msg); pExpResponse->SetMessage(msg); return pExpResponse; } Map* pMap = NULL; CartoManager* pCartoManager = NULL; pCartoManager = augeGetCartoManagerInstance(); g_int l_id = pCartoManager->GetLayerID(layerName, mapName); if(l_id < 0) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "No Layer %s in Map %s.", layerName, mapName); GLogger* pLogger = augeGetLoggerInstance(); pLogger->Error(msg); WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); pExpResponse->SetMessage(msg); return pExpResponse; } g_int s_id = pCartoManager->GetStyleID(styleName); if(s_id<0) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "No Style %s.", styleName); GLogger* pLogger = augeGetLoggerInstance(); pLogger->Error(msg); WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); pExpResponse->SetMessage(msg); return pExpResponse; } RESULTCODE rc = pCartoManager->SetStyle(l_id, s_id); if(rc!=AG_SUCCESS) { GError* pError = augeGetErrorInstance(); GLogger* pLogger = augeGetLoggerInstance(); pLogger->Error(pError->GetLastError()); WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); pExpResponse->SetMessage(pError->GetLastError()); return pExpResponse; } WebSuccessResponse* pSusResponse = augeCreateWebSuccessResponse(); pSusResponse->SetRequest(pRequest->GetRequest()); return pSusResponse; }
int gfire_get_im(PurpleConnection *gc, int packet_len) { guint8 sid[16], peermsg; gchar tmp[100] = ""; int index,i = 0; guint16 ml = 0; guint32 msgtype,imindex = 0; gfire_im *im = NULL; gfire_data *gfire = (gfire_data*)gc->proto_data; if (packet_len < 16) { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: packet 133 recv'd but way too short?!? %d bytes\n", packet_len); return 0; } index = 6; /* check the packet for sid signature */ memcpy(tmp, gfire->buff_in + index, strlen("sid")); tmp[strlen("sid")]=0x00; if ( 0 == g_ascii_strcasecmp("sid",(char *)tmp)) { index+= strlen("sid") + 1; memcpy(&sid, gfire->buff_in + index, XFIRE_SID_LEN); index+= XFIRE_SID_LEN + 1; } else { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 133: sid signature isn't in the correct position.\n"); return 0; } /* get peer message */ memcpy(tmp, gfire->buff_in + index, strlen("peermsg")); tmp[strlen("peermsg")]=0x00; if ( 0 == g_ascii_strcasecmp("peermsg",(char *)tmp)) { index+= strlen("peermsg") + 1; memcpy(&peermsg, gfire->buff_in + index, sizeof(peermsg)); index+= 2; } else { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 133: peermsg signature isn't in the correct position.\n"); return 0; } /* get messsage type */ memcpy(tmp, gfire->buff_in + index, strlen("msgtype")); tmp[strlen("msgtype")]=0x00; if ( 0 == g_ascii_strcasecmp("msgtype",(char *)tmp)) { index+= strlen("msgtype") + 1; memcpy(&msgtype, gfire->buff_in + index, sizeof(msgtype)); index+= sizeof(msgtype) + 1; msgtype = GUINT32_FROM_LE(msgtype); } else { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 133: msgtype signature isn't in the correct position.\n"); return 0; } switch (msgtype) { case 0: /* got an im */ /* get imindex */ memcpy(tmp, gfire->buff_in + index, strlen("imindex")); tmp[strlen("imindex")]=0x00; if ( 0 == g_ascii_strcasecmp("imindex",(char *)tmp)) { index+= strlen("imindex") + 1; memcpy(&imindex, gfire->buff_in + index, sizeof(imindex)); index+= sizeof(imindex); imindex = GUINT32_FROM_LE(imindex); } else { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 133: imindex signature isn't in the correct position.\n"); return 0; } index++; if (index > packet_len) { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: IM packet says IM but packet to short.\n"); return 0; } /* get im */ memcpy(tmp, gfire->buff_in + index, strlen("im")); tmp[strlen("im")]=0x00; if ( 0 == g_ascii_strcasecmp("im",(char *)tmp)) { index+= strlen("im") + 1; /* get im length */ memcpy(&ml, gfire->buff_in + index, sizeof(ml)); index+= sizeof(ml); ml = GUINT16_FROM_LE(ml); purple_debug(PURPLE_DEBUG_MISC, "gfire", "IM: im length = %d\n", ml); /* get im string */ gchar *im_str = g_malloc0(sizeof(gchar) * ml+1); memcpy(im_str, gfire->buff_in + index, ml); im_str[ml] = 0x00; purple_debug(PURPLE_DEBUG_MISC, "gfire", "IM:(recvd): %s\n", NN(im_str)); im = g_malloc0(sizeof(gfire_im)); gfire->im = im; im->type = msgtype; im->peer = peermsg; im->index = imindex; im->im_str = im_str; /* covert sid to string */ for(i = 0;i < XFIRE_SID_LEN;i++) g_sprintf((gchar *)tmp + (i*2), "%02x", sid[i]); tmp[XFIRE_SID_LEN*2]=0x00; im->sid_str = g_strdup(tmp); /* make response packet */ memcpy(gfire->buff_out, gfire->buff_in, packet_len); gfire_add_header(gfire->buff_out, 62, 2, 2); gfire->buff_out[35] = 0x02; gfire->buff_out[45] = 0x01; return 62; } else { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 133: im signature isn't in the correct position.\n"); return 0; } return 0; break; case 1: /* got an ack packet from a previous IM sent */ purple_debug(PURPLE_DEBUG_MISC, "gfire", "IM ack packet recieved.\n"); return 0; break; case 2: /* got typing from other user */ purple_debug(PURPLE_DEBUG_MISC, "gfire", "(im): Got typing info.\n"); im = g_malloc0(sizeof(gfire_im)); gfire->im = im; im->type = msgtype; im->peer = peermsg; im->index = 0; im->im_str = NULL; /* covert sid to string */ for(i = 0;i < XFIRE_SID_LEN;i++) g_sprintf((gchar *)tmp + (i*2), "%02x", sid[i]); tmp[XFIRE_SID_LEN*2]=0x00; im->sid_str = g_strdup(tmp); return 0; break; default: purple_debug(PURPLE_DEBUG_MISC, "gfire", "unknown IM msgtype = %d.\n", msgtype); return 0; } return 0; }
GList *gfire_read_buddy_online(PurpleConnection *gc, int packet_len) { guchar tmp[100]; int index = 0; int itmp = 0; int i = 0; guint8 *str = NULL; GList *tmp_list = NULL; GList *userids = NULL; GList *sids = NULL; GList *ret = NULL; GList *u,*s; gfire_buddy *gf_buddy = NULL; gfire_data *gfire = (gfire_data *)gc->proto_data; memset((void *)tmp, 0x00, 100); if (packet_len < 16) { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: packet 132 recv'd but way too short?!? %d bytes\n", packet_len); return NULL; } index = 6; itmp = gfire_read_attrib(&userids, gfire->buff_in + index, packet_len - index, "userid", FALSE, TRUE, 0, 0, XFIRE_USERID_LEN); if (itmp < 1 ) { //FIXME add mem cleanup code FIXME("gfire_read_attrib returned < 1! userids"); return NULL; } index += itmp + 1; itmp = gfire_read_attrib(&sids, gfire->buff_in + index, packet_len - index, "sid", FALSE, TRUE, 0, 0, XFIRE_SID_LEN); if (itmp < 1 ) { //FIXME add mem cleanup code FIXME("gfire_read_attrib returned < 1! sids"); return NULL; } userids = g_list_first(userids); sids = g_list_first(sids); u = userids; s = sids; while ( NULL != u ) { tmp_list = gfire_find_buddy_in_list(gfire->buddies, u->data, GFFB_UIDBIN); if (NULL == tmp_list) { purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 132: NULL pointer from buddy find (userid).\n"); //FIXME add cleanup code return NULL; } gf_buddy = (gfire_buddy *)tmp_list->data; str = (guint8 *) s->data; if (NULL != gf_buddy->sid) g_free(gf_buddy->sid); gf_buddy->sid = str; /* covert sid to string */ for(i = 0;i < XFIRE_SID_LEN;i++) g_sprintf((gchar *)tmp + (i*2), "%02x", str[i]); tmp[XFIRE_SID_LEN*2]=0x00; if (NULL != gf_buddy->sid_str) g_free(gf_buddy->sid_str); gf_buddy->sid_str = g_strdup((gchar *)tmp); /* clear away state, xfire presence state isn't persistent (unlike purple) */ gf_buddy->away = FALSE; if (NULL != gf_buddy->away_msg) g_free(gf_buddy->away_msg); gf_buddy->away_msg = NULL; ret = g_list_append(ret, (gpointer *)gf_buddy); g_free(u->data); s->data = NULL; u->data = NULL; u = g_list_next(u); s = g_list_next(s); purple_debug(PURPLE_DEBUG_MISC, "gfire", "(on/offline): got info for %s -> %s\n", NN(gf_buddy->name), NN(gf_buddy->sid_str)); } g_list_free(userids); g_list_free(sids); return ret; }
/* its the responsibility of the caller to free passwd_file */ int env_set_user(const char *username, char **passwd_file, int display, const struct list *env_names, const struct list *env_values) { int error; int pw_uid; int pw_gid; int uid; int index; int len; char *name; char *value; char *pw_shell; char *pw_dir; char text[256]; char hostname[256]; pw_shell = 0; pw_dir = 0; error = g_getuser_info(username, &pw_gid, &pw_uid, &pw_shell, &pw_dir, 0); if (error == 0) { g_rm_temp_dir(); error = g_setgid(pw_gid); if (error == 0) { error = g_initgroups(username, pw_gid); } if (error == 0) { uid = pw_uid; error = g_setuid(uid); } g_mk_socket_path(0); if (error == 0) { g_clearenv(); g_setenv("SHELL", pw_shell, 1); g_setenv("PATH", "/sbin:/bin:/usr/bin:/usr/local/bin", 1); g_setenv("USER", username, 1); g_setenv("LOGNAME", username, 1); g_sprintf(text, "%d", uid); g_setenv("UID", text, 1); g_setenv("HOME", pw_dir, 1); g_set_current_dir(pw_dir); g_sprintf(text, ":%d.0", display); g_setenv("DISPLAY", text, 1); g_setenv("XRDP_SESSION", "1", 1); /* XRDP_SOCKET_PATH should be set even here, chansrv uses this */ g_setenv("XRDP_SOCKET_PATH", XRDP_SOCKET_PATH, 1); /* pulse sink socket */ g_snprintf(text, sizeof(text) - 1, CHANSRV_PORT_OUT_BASE_STR, display); g_setenv("XRDP_PULSE_SINK_SOCKET", text, 1); /* pulse source socket */ g_snprintf(text, sizeof(text) - 1, CHANSRV_PORT_IN_BASE_STR, display); g_setenv("XRDP_PULSE_SOURCE_SOCKET", text, 1); if ((env_names != 0) && (env_values != 0) && (env_names->count == env_values->count)) { for (index = 0; index < env_names->count; index++) { name = (char *) list_get_item(env_names, index), value = (char *) list_get_item(env_values, index), g_setenv(name, value, 1); } } g_gethostname(hostname, 255); hostname[255] = 0; if (passwd_file != 0) { if (0 == g_cfg->auth_file_path) { /* if no auth_file_path is set, then we go for $HOME/.vnc/sesman_passwd-USERNAME@HOSTNAME:DISPLAY */ if (!g_directory_exist(".vnc")) { if (g_mkdir(".vnc") < 0) { log_message(LOG_LEVEL_ERROR, "Error creating .vnc directory: %s", g_get_strerror()); } } len = g_snprintf(NULL, 0, "%s/.vnc/sesman_passwd-%s@%s:%d", pw_dir, username, hostname, display); *passwd_file = (char *) g_malloc(len + 1, 1); if (*passwd_file != NULL) { /* Try legacy names first, remove if found */ g_sprintf(*passwd_file, "%s/.vnc/sesman_%s_passwd:%d", pw_dir, username, display); if (g_file_exist(*passwd_file)) { log_message(LOG_LEVEL_WARNING, "Removing old " "password file %s", *passwd_file); g_file_delete(*passwd_file); } g_sprintf(*passwd_file, "%s/.vnc/sesman_%s_passwd", pw_dir, username); if (g_file_exist(*passwd_file)) { log_message(LOG_LEVEL_WARNING, "Removing insecure " "password file %s", *passwd_file); g_file_delete(*passwd_file); } g_sprintf(*passwd_file, "%s/.vnc/sesman_passwd-%s@%s:%d", pw_dir, username, hostname, display); } } else { /* we use auth_file_path as requested */ len = g_snprintf(NULL, 0, g_cfg->auth_file_path, username); *passwd_file = (char *) g_malloc(len + 1, 1); if (*passwd_file != NULL) { g_sprintf(*passwd_file, g_cfg->auth_file_path, username); } } if (*passwd_file != NULL) { LOG_DBG("pass file: %s", *passwd_file); } } g_free(pw_dir); g_free(pw_shell); } } else { log_message(LOG_LEVEL_ERROR, "error getting user info for user %s", username); } return error; }
bool DescribeFeatureTypeHandler::WriteDescribeFeatureType_1_1_0(WebContext* pWebContext, const char* typeName, FeatureClass* pFeatureClass) { char str[AUGE_NAME_MAX]; char cache_name[AUGE_NAME_MAX]; char cache_file[AUGE_PATH_MAX]; const char* cache_path = pWebContext->GetCacheProtocolPath(); g_snprintf(cache_name, AUGE_NAME_MAX,"%s_wfs_%s_describe_feauretype_1_1_0", pWebContext->GetService(), typeName); auge_make_path(cache_file, NULL, cache_path, cache_name,"xml"); XElement *pxNode = NULL; XElement *pxRoot = NULL; XDocument *pxDoc = new XDocument(); pxRoot = pxDoc->CreateRootNode("schema", NULL, NULL); pxRoot->SetNamespaceDeclaration("http://www.opengis.net/wfs",NULL); pxRoot->SetNamespaceDeclaration("http://www.opengis.net/wfs","wfs"); pxRoot->SetNamespaceDeclaration("http://www.opengis.net/ows","ows"); pxRoot->SetNamespaceDeclaration("http://www.opengis.net/gml","gml"); pxRoot->SetNamespaceDeclaration("http://www.w3.org/1999/xlink","xlink"); pxRoot->SetNamespaceDeclaration("http://www.w3.org/2001/XMLSchema-instance","xsi"); pxRoot->SetNamespaceDeclaration("http://www.w3.org/2001/XMLSchema","xsd"); pxRoot->SetAttribute("version", "1.1.0", NULL); // schema-->import XElement* pxImport = pxRoot->AddChild("import", "xsd"); pxImport->SetAttribute("namespace","http://www.opengis.net/gml", NULL); // schema-->complexType g_sprintf(str,"%sType", typeName); XElement* pxComplexType = pxRoot->AddChild("complexType", "xsd"); pxComplexType->SetAttribute("name", str, NULL, true); // schema-->complexType-->complexContent XElement* pxComplexContent = pxComplexType->AddChild("complexContent","xsd"); // schema-->complexType-->complexContent-->extentsion XElement* pxExtentsion = pxComplexContent->AddChild("extentsion", "xsd"); pxExtentsion->SetAttribute("base","gml:AbstractFeatureType", NULL); // schema-->complexType-->complexContent-->extentsion-->sequence XElement* pxSequence = pxExtentsion->AddChild("sequence", "xsd"); GField *pField = NULL; GFields *pFields = pFeatureClass->GetFields(); g_uint count = pFields->Count(); augeFieldType ftype = augeFieldTypeNone; // schema-->complexType-->complexContent-->extentsion-->sequence-->element XElement* pxElement = NULL; for(g_uint i=0; i<count; i++) { pField = pFields->GetField(i); pxElement = pxSequence->AddChild("element", "xsd"); const char* fname = pField->GetName(); const char* utf8_name = auge_encoding_convert("GBK","UTF-8",fname,strlen(fname)); pxElement->SetAttribute("name",utf8_name, NULL); pxElement->SetAttribute("nillable",pField->IsNullable()?"true":"false", NULL); pxElement->SetAttribute("minOccurs","0", NULL); pxElement->SetAttribute("maxOccurs","1", NULL); ftype = pField->GetType(); if(ftype==augeFieldTypeGeometry) { augeGeometryType gtype = pField->GetGeometryDef()->GeometryType(); const char* sss = GetOgcGeometryType(gtype); g_sprintf(str,"gml:%sPropertyType",sss); pxElement->SetAttribute("type",str, NULL); } else { g_sprintf(str, "xsd:%s", GetOgcFieldType(pField->GetType())); pxElement->SetAttribute("type",str, NULL); } if(ftype==augeFieldTypeString) { g_sprintf(str,"%d",pField->GetLength()); pxElement->SetAttribute("length",str, NULL); } } // schema-->element pxElement = pxRoot->AddChild("element", "xsd"); g_sprintf(str, "%sType", typeName); pxElement->SetAttribute("type",str, NULL, true); pxElement->SetAttribute("name",typeName, NULL, true); pxElement->SetAttribute("substitutionGroup","gml:_Feature", NULL); pxDoc->Save(cache_file, pWebContext->GetResponseEncoding(), 1); pxDoc->Release(); return true; }
/** * Deletes the first matching line from the rgb user file * that matches the color name and color value specified. * * color_value is given in hex format */ gboolean delete_color (gchar* color_name, gchar* color_value) { FILE *fp; gchar *p; gchar *file_color_name; gchar file_color_value[8]; gint r, g, b; gchar buffer[512] = ""; gchar newstuff[512] = ""; gboolean found = FALSE; /* remove from file */ fp = fopen (get_user_file (), "r"); if (!fp) { show_file_error (FILE_READ); return FALSE; } while ((p = fgets (buffer, sizeof buffer, fp)) != NULL) { if (buffer[0] == '!') continue; r = g_ascii_strtoull (p, &p, 10); g = g_ascii_strtoull (p, &p, 10); b = g_ascii_strtoull (p, &p, 10); p += strspn (p, " \t"); g_sprintf (file_color_value, "#%2X%2X%2X", r, g, b); file_color_name = g_strchomp (g_strdup (p)); /* make sure to only remove the first matching color. both value and name must match */ if (found || strcmp (file_color_name, color_name) != 0 || strcmp (g_ascii_strup (file_color_value, -1), color_value) != 0) { g_sprintf (newstuff, "%s%3d %3d %3d\t\t%s\n", newstuff, r, g, b, file_color_name); } else { found = TRUE; } } fclose (fp); /* only rewrite the file if we found a match */ if (found) { fp = fopen (get_user_file (), "w"); if (!fp) { show_file_error (FILE_WRITE); return FALSE; } fprintf (fp, "%s", newstuff); fclose (fp); return TRUE; } return FALSE; }
static void get_page_label_text(GtkWidget* label, document_page_t* doc_page) { gchar* text = (gchar*)g_malloc(sizeof(gchar)*256); g_sprintf(text, "Seite %i / %i", doc_page->page + 1, doc_page->page_count); gtk_label_set_text(label, text); g_free(text); }
static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_before; gint txt_len; gint startpos; gint endpos; gint startline; gint endline; gint line_iter; gint linepos; gint linelen; gint startcol; gint endcol; gint i; gint n_spaces; gchar *spaces; ScintillaObject *sci; /* get a pointer to the scintilla object */ sci = document_get_current()->editor->sci; if (sci_has_selection(sci)){ startpos = sci_get_selection_start(sci); endpos = sci_get_selection_end(sci); /* sanity check -- we dont care which way the block was selected */ if(startpos > endpos){ i = endpos; endpos = startpos; startpos = i; } startline = sci_get_line_from_position(sci, startpos); /* Setting also start point for 1st line */ linepos = sci_get_position_from_line(sci, startline); endline = sci_get_line_from_position(sci, endpos); /* normal mode */ if(startline == endline){ /* get the text in question */ txt_len = endpos - startpos; txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_before = sci_get_char_at(sci, startpos - 1); /* set up new text buf */ (void) g_sprintf(txt, "%s%c", txt_i, char_before); /* start undo */ sci_start_undo_action(sci); /* put the new text in */ sci_set_selection_start(sci, startpos - 1); sci_replace_sel(sci, txt); /* select the right bit again */ sci_set_selection_start(sci, startpos - 1); sci_set_selection_end(sci, endpos - 1); /* end undo */ sci_end_undo_action(sci); g_free(txt); g_free(txt_i); } /* rectangle mode (we hope!) */ else{ startcol = sci_get_col_from_position(sci, startpos); endcol = sci_get_col_from_position(sci, endpos); /* return early for the trivial case */ if(startcol == 0 || startcol == endcol){ return; } /* start undo */ sci_start_undo_action(sci); for(line_iter = startline; line_iter <= endline; line_iter++){ linepos = sci_get_position_from_line(sci, line_iter); linelen = sci_get_line_length(sci, line_iter); /* do we need to do something */ if(linelen >= startcol - 1 ){ /* if between the two columns */ /* pad to the end first */ if(linelen <= endcol){ /* bung in some spaces -- sorry, I dont like tabs */ n_spaces = endcol - linelen + 1; spaces = g_malloc(sizeof(gchar) * (n_spaces + 1)); for(i = 0; i < n_spaces; i++){ spaces[i] = ' '; } spaces[i] = '\0'; sci_insert_text(sci, linepos + linelen - 1, spaces); g_free(spaces); } /* now move the text itself */ sci_set_selection_mode(sci, 0); sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol); txt_len = sci_get_selected_text_length(sci); txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_before = sci_get_char_at(sci, linepos + startcol - 1); /* set up new text buf */ (void) g_sprintf(txt, "%s%c", txt_i, char_before); /* put the new text in */ sci_set_selection_start(sci, linepos + startcol - 1); sci_replace_sel(sci, txt); g_free(txt); g_free(txt_i); } } /* put the selection box back */ /* here we rely upon the last result of linepos */ sci_set_selection_mode(sci, 1); sci_set_selection_start(sci, startpos - 1); sci_set_selection_end(sci, linepos + endcol - 1); /* end undo action */ sci_end_undo_action(sci); } } }
int DEFAULT_CC main(int argc, char **argv) { int test; int host_be; #if defined(_WIN32) WSADATA w; SC_HANDLE sc_man; SC_HANDLE sc_ser; int run_as_service; SERVICE_TABLE_ENTRY te[2]; #else int pid; int fd; int no_daemon; char text[256]; char pid_file[256]; #endif g_init(); ssl_init(); /* check compiled endian with actual endian */ test = 1; host_be = !((int)(*(unsigned char *)(&test))); #if defined(B_ENDIAN) if (!host_be) #endif #if defined(L_ENDIAN) if (host_be) #endif { g_writeln("endian wrong, edit arch.h"); return 0; } /* check long, int and void* sizes */ if (sizeof(int) != 4) { g_writeln("unusable int size, must be 4"); return 0; } if (sizeof(long) != sizeof(void *)) { g_writeln("long size must match void* size"); return 0; } if (sizeof(long) != 4 && sizeof(long) != 8) { g_writeln("unusable long size, must be 4 or 8"); return 0; } if (sizeof(tui64) != 8) { g_writeln("unusable tui64 size, must be 8"); return 0; } #if defined(_WIN32) run_as_service = 1; if (argc == 2) { if (g_strncasecmp(argv[1], "-help", 255) == 0 || g_strncasecmp(argv[1], "--help", 255) == 0 || g_strncasecmp(argv[1], "-h", 255) == 0) { g_writeln(""); g_writeln("xrdp: A Remote Desktop Protocol server."); g_writeln("Copyright (C) Jay Sorg 2004-2011"); g_writeln("See http://xrdp.sourceforge.net for more information."); g_writeln(""); g_writeln("Usage: xrdp [options]"); g_writeln(" -h: show help"); g_writeln(" -install: install service"); g_writeln(" -remove: remove service"); g_writeln(""); g_exit(0); } else if (g_strncasecmp(argv[1], "-install", 255) == 0 || g_strncasecmp(argv[1], "--install", 255) == 0 || g_strncasecmp(argv[1], "-i", 255) == 0) { /* open service manager */ sc_man = OpenSCManager(0, 0, GENERIC_WRITE); if (sc_man == 0) { g_writeln("error OpenSCManager, do you have rights?"); g_exit(0); } /* check if service is allready installed */ sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS); if (sc_ser == 0) { /* install service */ CreateService(sc_man, "xrdp", "xrdp", SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, "c:\\temp\\xrdp\\xrdp.exe", 0, 0, 0, 0, 0); } else { g_writeln("error service is allready installed"); CloseServiceHandle(sc_ser); CloseServiceHandle(sc_man); g_exit(0); } CloseServiceHandle(sc_man); g_exit(0); } else if (g_strncasecmp(argv[1], "-remove", 255) == 0 || g_strncasecmp(argv[1], "--remove", 255) == 0 || g_strncasecmp(argv[1], "-r", 255) == 0) { /* open service manager */ sc_man = OpenSCManager(0, 0, GENERIC_WRITE); if (sc_man == 0) { g_writeln("error OpenSCManager, do you have rights?"); g_exit(0); } /* check if service is allready installed */ sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS); if (sc_ser == 0) { g_writeln("error service is not installed"); CloseServiceHandle(sc_man); g_exit(0); } DeleteService(sc_ser); CloseServiceHandle(sc_man); g_exit(0); } else { g_writeln("Unknown Parameter"); g_writeln("xrdp -h for help"); g_writeln(""); g_exit(0); } } else if (argc > 1) { g_writeln("Unknown Parameter"); g_writeln("xrdp -h for help"); g_writeln(""); g_exit(0); } if (run_as_service) { g_memset(&te, 0, sizeof(te)); te[0].lpServiceName = "xrdp"; te[0].lpServiceProc = MyServiceMain; StartServiceCtrlDispatcher(&te); g_exit(0); } WSAStartup(2, &w); #else /* _WIN32 */ g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH); no_daemon = 0; if (argc == 2) { if ((g_strncasecmp(argv[1], "-kill", 255) == 0) || (g_strncasecmp(argv[1], "--kill", 255) == 0) || (g_strncasecmp(argv[1], "-k", 255) == 0)) { g_writeln("stopping xrdp"); /* read the xrdp.pid file */ fd = -1; if (g_file_exist(pid_file)) /* xrdp.pid */ { fd = g_file_open(pid_file); /* xrdp.pid */ } if (fd == -1) { g_writeln("problem opening to xrdp.pid"); g_writeln("maybe its not running"); } else { g_memset(text, 0, 32); g_file_read(fd, text, 31); pid = g_atoi(text); g_writeln("stopping process id %d", pid); if (pid > 0) { g_sigterm(pid); } g_file_close(fd); } g_exit(0); } else if (g_strncasecmp(argv[1], "-nodaemon", 255) == 0 || g_strncasecmp(argv[1], "--nodaemon", 255) == 0 || g_strncasecmp(argv[1], "-nd", 255) == 0 || g_strncasecmp(argv[1], "--nd", 255) == 0 || g_strncasecmp(argv[1], "-ns", 255) == 0 || g_strncasecmp(argv[1], "--ns", 255) == 0) { no_daemon = 1; } else if (g_strncasecmp(argv[1], "-help", 255) == 0 || g_strncasecmp(argv[1], "--help", 255) == 0 || g_strncasecmp(argv[1], "-h", 255) == 0) { g_writeln(""); g_writeln("xrdp: A Remote Desktop Protocol server."); g_writeln("Copyright (C) Jay Sorg 2004-2011"); g_writeln("See http://xrdp.sourceforge.net for more information."); g_writeln(""); g_writeln("Usage: xrdp [options]"); g_writeln(" -h: show help"); g_writeln(" -nodaemon: don't fork into background"); g_writeln(" -kill: shut down xrdp"); g_writeln(""); g_exit(0); } else if ((g_strncasecmp(argv[1], "-v", 255) == 0) || (g_strncasecmp(argv[1], "--version", 255) == 0)) { g_writeln(""); g_writeln("xrdp: A Remote Desktop Protocol server."); g_writeln("Copyright (C) Jay Sorg 2004-2011"); g_writeln("See http://xrdp.sourceforge.net for more information."); g_writeln("Version %s", PACKAGE_VERSION); g_writeln(""); g_exit(0); } else { g_writeln("Unknown Parameter"); g_writeln("xrdp -h for help"); g_writeln(""); g_exit(0); } } else if (argc > 1) { g_writeln("Unknown Parameter"); g_writeln("xrdp -h for help"); g_writeln(""); g_exit(0); } if (g_file_exist(pid_file)) /* xrdp.pid */ { g_writeln("It looks like xrdp is allready running,"); g_writeln("if not delete the xrdp.pid file and try again"); g_exit(0); } if (!no_daemon) { /* make sure we can write to pid file */ fd = g_file_open(pid_file); /* xrdp.pid */ if (fd == -1) { g_writeln("running in daemon mode with no access to pid files, quitting"); g_exit(0); } if (g_file_write(fd, "0", 1) == -1) { g_writeln("running in daemon mode with no access to pid files, quitting"); g_exit(0); } g_file_close(fd); g_file_delete(pid_file); } if (!no_daemon) { /* start of daemonizing code */ pid = g_fork(); if (pid == -1) { g_writeln("problem forking"); g_exit(1); } if (0 != pid) { g_writeln("process %d started ok", pid); /* exit, this is the main process */ g_exit(0); } g_sleep(1000); g_file_close(0); g_file_close(1); g_file_close(2); g_file_open("/dev/null"); g_file_open("/dev/null"); g_file_open("/dev/null"); /* end of daemonizing code */ } if (!no_daemon) { /* write the pid to file */ pid = g_getpid(); fd = g_file_open(pid_file); /* xrdp.pid */ if (fd == -1) { g_writeln("trying to write process id to xrdp.pid"); g_writeln("problem opening xrdp.pid"); g_writeln("maybe no rights"); } else { g_sprintf(text, "%d", pid); g_file_write(fd, text, g_strlen(text)); g_file_close(fd); } } #endif g_threadid = tc_get_threadid(); g_listen = xrdp_listen_create(); g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */ g_signal_kill(xrdp_shutdown); /* SIGKILL */ g_signal_pipe(pipe_sig); /* SIGPIPE */ g_signal_terminate(xrdp_shutdown); /* SIGTERM */ g_sync_mutex = tc_mutex_create(); g_sync1_mutex = tc_mutex_create(); pid = g_getpid(); g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid); g_term_event = g_create_wait_obj(text); g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid); g_sync_event = g_create_wait_obj(text); if (g_term_event == 0) { g_writeln("error creating g_term_event"); } xrdp_listen_main_loop(g_listen); xrdp_listen_delete(g_listen); tc_mutex_delete(g_sync_mutex); tc_mutex_delete(g_sync1_mutex); g_delete_wait_obj(g_term_event); g_delete_wait_obj(g_sync_event); #if defined(_WIN32) /* I don't think it ever gets here */ /* when running in win32 app mode, control c exits right away */ WSACleanup(); #else /* delete the xrdp.pid file */ g_file_delete(pid_file); #endif return 0; }
/* FIXME: Make cancellable */ GdkPixbuf* gt_resource_downloader_download_image_immediately(GtResourceDownloader* self, const gchar* uri, const gchar* name, ResourceDownloaderFunc cb, gpointer udata, GError** error) { RETURN_VAL_IF_FAIL(GT_IS_RESOURCE_DOWNLOADER(self), NULL); RETURN_VAL_IF_FAIL(!utils_str_empty(uri), NULL); GtResourceDownloaderPrivate* priv = gt_resource_downloader_get_instance_private(self); g_autofree gchar* filename = NULL; g_autoptr(GdkPixbuf) ret = NULL; g_autoptr(GError) err = NULL; g_autoptr(SoupMessage) msg = NULL; ResourceData* data = NULL; /* NOTE: If we aren't supplied a filename, we'll just create one by hashing the uri */ if (utils_str_empty(name)) { gchar hash_str[15]; guint hash = 0; hash = g_str_hash(uri); /* TODO: Replace this with murmur3 hash */ g_sprintf(hash_str, "%ud", hash); filename = g_build_filename(priv->filepath, hash_str, NULL); } else filename = g_build_filename(priv->filepath, name, NULL); if (priv->filepath && g_file_test(filename, G_FILE_TEST_EXISTS)) { ret = gdk_pixbuf_new_from_file(filename, &err); if (err) { WARNING("Unable to download image because: %s", err->message); g_propagate_prefixed_error(error, g_steal_pointer(&err), "Unable to download image because: "); /* NOTE: Don't return here as we still might be able to * download a new image*/ } } msg = soup_message_new(SOUP_METHOD_GET, uri); soup_message_headers_append(msg->request_headers, "Client-ID", CLIENT_ID); data = resource_data_new(); data->uri = g_strdup(uri); data->name = g_strdup(name); data->cb = cb; data->udata = udata; data->self = g_object_ref(self); data->msg = g_steal_pointer(&msg); soup_session_send_async(priv->soup, data->msg, NULL, send_message_cb, data); /* NOTE: Return any found image immediately */ return g_steal_pointer(&ret); }
void info_get_nic_information (const gchar *nic, Netinfo *info) { GtkTreeModel *model; GtkTreeIter iter; gchar dst[INFO_ADDRSTRLEN]; InfoIpAddr *ip; gint prefix; struct in_addr addr, subnet; gchar *address_string, *subnet_string; gchar address6_string[INET6_ADDRSTRLEN]; glibtop_netload netload; #ifdef __linux__ mii_data_result data; #endif gtk_label_set_text (GTK_LABEL (info->hw_address), NOT_AVAILABLE); gtk_label_set_text (GTK_LABEL (info->mtu), NOT_AVAILABLE); gtk_label_set_text (GTK_LABEL (info->state), NOT_AVAILABLE); gtk_label_set_text (GTK_LABEL (info->multicast), NOT_AVAILABLE); gtk_label_set_text (GTK_LABEL (info->link_speed), NOT_AVAILABLE); glibtop_get_netload (&netload, nic); /* IPv6 */ /* FIXME: It shows only one IPv6 address. Bug #563768 */ inet_ntop (AF_INET6, netload.address6, address6_string, INET6_ADDRSTRLEN); prefix = info_ip6_masklen (netload.prefix6); ip = g_new0 (InfoIpAddr, 1); ip->ip_addr = g_strdup (address6_string); ip->ip_prefix = g_strdup_printf ("%d", prefix); ip->ip_bcast = g_strdup (""); switch (netload.scope6) { case GLIBTOP_IF_IN6_SCOPE_LINK: ip->ip_scope = g_strdup ("Link"); break; case GLIBTOP_IF_IN6_SCOPE_SITE: ip->ip_scope = g_strdup ("Site"); break; case GLIBTOP_IF_IN6_SCOPE_GLOBAL: ip->ip_scope = g_strdup ("Global"); break; case GLIBTOP_IF_IN6_SCOPE_HOST: ip->ip_scope = g_strdup ("Host"); break; case GLIBTOP_IF_IN6_SCOPE_UNKNOWN: ip->ip_scope = g_strdup (_("Unknown")); break; default: ip->ip_scope = g_strdup (_("Unknown")); break; } model = gtk_tree_view_get_model (GTK_TREE_VIEW (info->list_ip_addr)); gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, "IPv6", 1, ip->ip_addr, 2, ip->ip_prefix, 3, ip->ip_bcast, 4, ip->ip_scope, -1); info_ip_addr_free (ip); /* IPv4 */ addr.s_addr = netload.address; subnet.s_addr = netload.subnet; address_string = g_strdup (inet_ntoa (addr)); subnet_string = g_strdup (inet_ntoa (subnet)); ip = g_new0 (InfoIpAddr, 1); ip->ip_addr = g_strdup (address_string); ip->ip_prefix = g_strdup (subnet_string); /* FIXME: Get the broadcast address: Bug #563765 */ ip->ip_bcast = g_strdup (""); model = gtk_tree_view_get_model (GTK_TREE_VIEW (info->list_ip_addr)); gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, "IPv4", 1, ip->ip_addr, 2, ip->ip_prefix, 3, ip->ip_bcast, 4, "", -1); g_free (address_string); g_free (subnet_string); info_ip_addr_free (ip); /* Get general information about the interface */ /* Get the Hardware Address */ if (netload.flags & (1L << GLIBTOP_NETLOAD_HWADDRESS)) { g_sprintf (dst, "%02x:%02x:%02x:%02x:%02x:%02x", (int) ((guchar *) &netload.hwaddress)[0], (int) ((guchar *) &netload.hwaddress)[1], (int) ((guchar *) &netload.hwaddress)[2], (int) ((guchar *) &netload.hwaddress)[3], (int) ((guchar *) &netload.hwaddress)[4], (int) ((guchar *) &netload.hwaddress)[5]); } else { g_sprintf (dst, NOT_AVAILABLE); } gtk_label_set_text (GTK_LABEL (info->hw_address), dst); /* Get the interface's Maximum Transfer Unit */ g_sprintf (dst, "%d", netload.mtu); gtk_label_set_text (GTK_LABEL (info->mtu), dst); bzero (dst, strlen(dst)); /* Get Flags to determine other properties */ /* Is the interface up? */ if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_UP)) { gtk_label_set_text (GTK_LABEL (info->state), _("Active")); } else { gtk_label_set_text (GTK_LABEL (info->state), _("Inactive")); } /* Is this a loopback device? */ if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_LOOPBACK)) { gtk_label_set_text (GTK_LABEL (info->hw_address), _("Loopback")); ip->ip_bcast = g_strdup (""); info_setup_configure_button (info, FALSE); } else { info_setup_configure_button (info, TRUE); } /* Does this interface supports multicast? */ if (netload.if_flags & (1L << GLIBTOP_IF_FLAGS_MULTICAST)) { gtk_label_set_text (GTK_LABEL (info->multicast), _("Enabled")); } else { gtk_label_set_text (GTK_LABEL (info->multicast), _("Disabled")); } /* Get the Point-To-Point address if any */ /* FIXME: Bug #563767 */ /* Get the link negotiation speed. Only available on Linux * systems, and lately only for with super user privileges * See Bug #387198 */ #ifdef __linux__ data = mii_get_basic (nic); if (data.has_data) { gtk_label_set_text (GTK_LABEL (info->link_speed), data.media); } #else gtk_label_set_text (GTK_LABEL (info->link_speed), NOT_AVAILABLE); #endif }
gboolean update_track_info(track_t *t) { gchar dummy[10], *markup = NULL, *markupProps = NULL; gint i = 0; GdkPixbuf *starPix = NULL; PangoLayout *layout = NULL; get_track_info(&t->track); if (!validate_track_info(&t->track)) { g_print("Malformed track data\n"); gtk_main_quit(); } if (t->track.changed) { gtk_image_set_from_file(GTK_IMAGE(t->trackw.image), t->track.artworkId); markupProps = g_strdup("<span font='Sans 11' font_weight='bold' color='#FFFFFF'>%s</span>"); t->track.x.name = 0; t->track.x.name2 = 0; markup = g_markup_printf_escaped(markupProps, t->track.name); gtk_label_set_markup(GTK_LABEL(t->trackw.label.name), markup); layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.name)); pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.nameLen, NULL); if (t->track.nameLen > SCROLL_SIZE_W) { if (t->track.nameScroll) g_source_remove(t->track.nameTag); t->track.nameScroll = TRUE; t->track.nameTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_name, t); } else if (t->track.nameScroll) { /* if the previous label was scrolled and this one doesn't need do * it stops the scrolling and puts the label at it's origin. Failure to do * so causes the new label to be displayed at the last position the previous * label was scrolled. */ g_source_remove(t->track.nameTag); gtk_layout_move(GTK_LAYOUT(t->trackw.layout.name), t->trackw.label.name, 0, 0); t->track.nameScroll = FALSE; } g_free(markup); t->track.x.artist = 0; t->track.x.artist2 = 0; markup = g_markup_printf_escaped(markupProps, t->track.artist); gtk_label_set_markup(GTK_LABEL(t->trackw.label.artist), markup); layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.artist)); pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.artistLen, NULL); if (t->track.artistLen > SCROLL_SIZE_W-23) { if (t->track.artistScroll) g_source_remove(t->track.artistTag); t->track.artistScroll = TRUE; t->track.artistTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_artist, t); } else if (t->track.artistScroll) { g_source_remove(t->track.artistTag); gtk_layout_move(GTK_LAYOUT(t->trackw.layout.artist), t->trackw.label.artist, 0, 0); t->track.artistScroll = FALSE; } g_free(markup); t->track.x.album = 0; t->track.x.album2 = 0; markup = g_markup_printf_escaped(markupProps, t->track.album); gtk_label_set_markup(GTK_LABEL(t->trackw.label.album), markup); layout = gtk_label_get_layout(GTK_LABEL(t->trackw.label.album)); pango_layout_get_pixel_size(PANGO_LAYOUT(layout), &t->track.albumLen, NULL); if (t->track.albumLen > SCROLL_SIZE_W-40) { if (t->track.albumScroll) g_source_remove(t->track.albumTag); t->track.albumScroll = TRUE; t->track.albumTag = g_timeout_add(SCROLL_SPEED, (GSourceFunc) scroll_label_album, t); } else if (t->track.albumScroll) { g_source_remove(t->track.albumTag); gtk_layout_move(GTK_LAYOUT(t->trackw.layout.album), t->trackw.label.album, 0, 0); t->track.albumScroll = FALSE; } g_free(markup); g_free(markupProps); markupProps = g_strdup("<span font='Sans 11' color='#FFFFFF'>%s</span>"); markup = g_markup_printf_escaped(markupProps, t->track.genre); gtk_label_set_markup(GTK_LABEL(t->trackw.genre), markup); g_free(markup); g_sprintf(dummy, "%d", t->track.year); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.year), markup); g_free(markup); dummy[0] = '\0'; format_time(dummy, t->track.length); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.length), markup); g_free(markup); g_free(markupProps); dummy[0] = '\0'; gtk_range_set_range(GTK_RANGE(t->trackw.slider), 0, t->track.length); /* set the rating */ starPix = gdk_pixbuf_new_from_xpm_data(starFull_xpm); for (i = 1; i <= t->track.rating; i++) gtk_image_set_from_pixbuf(GTK_IMAGE(t->trackw.stars[i-1]), GDK_PIXBUF(starPix)); g_object_unref(starPix); starPix = gdk_pixbuf_new_from_xpm_data(starHollow_xpm); while (i <= 5) { gtk_image_set_from_pixbuf(GTK_IMAGE(t->trackw.stars[i-1]), GDK_PIXBUF(starPix)); i++; } g_object_unref(starPix); } markupProps = g_strdup("<span font='Sans 11' color='#FFFFFF'>%s</span>"); g_sprintf(dummy, "%d", t->track.playcount); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.playcount), markup); g_free(markup); dummy[0] = '\0'; format_time(dummy, t->track.position); markup = g_markup_printf_escaped(markupProps, dummy); gtk_label_set_markup(GTK_LABEL(t->trackw.position), markup); g_free(markup); g_free(markupProps); dummy[0] = '\0'; gtk_range_set_fill_level(GTK_RANGE(t->trackw.slider), t->track.position); gtk_range_set_value(GTK_RANGE(t->trackw.slider), t->track.position); /* NOTE: reuses the starPix pixbuf */ if (t->playerInfo.counter == 4) { /* 2 seconds on currently UPDATE_SPEED */ if (!get_player_info(&t->playerInfo)) return FALSE; else { if (t->playerInfo.status) { starPix = gdk_pixbuf_new_from_xpm_data(pause_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.playPause), starPix); g_object_unref(starPix); } else { starPix = gdk_pixbuf_new_from_xpm_data(play_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.playPause), starPix); g_object_unref(starPix); } if (t->playerInfo.repeat == 0) { starPix = gdk_pixbuf_new_from_xpm_data(repeatOff_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix); g_object_unref(starPix); } else if (t->playerInfo.repeat == 1) { starPix = gdk_pixbuf_new_from_xpm_data(repeatAll_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix); g_object_unref(starPix); } else { starPix = gdk_pixbuf_new_from_xpm_data(repeatSingle_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.repeat), starPix); g_object_unref(starPix); } if (t->playerInfo.shuffle) { starPix = gdk_pixbuf_new_from_xpm_data(shuffleOn_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.shuffle), starPix); g_object_unref(starPix); } else { starPix = gdk_pixbuf_new_from_xpm_data(shuffleOff_xpm); gtk_image_set_from_pixbuf(GTK_IMAGE(t->playerControls.shuffle), starPix); g_object_unref(starPix); } } t->playerInfo.counter = 0; } free_track_info(&t->track); t->playerInfo.counter++; return TRUE; }
static GtkTreeModel * create_palette () { FILE *fp; gchar *filename; gchar buf[1024], *name; GtkListStore *store; GdkPixbuf *pb; GtkTreeIter iter; gchar *cxpm[] = { "16 14 1 1", ". c #FFFFFF", "................", "................", "................", "................", "................", "................", "................", "................", "................", "................", "................", "................", "................", "................"}; gchar cl[] = ". c #FFFFFF"; if (options.color_data.palette) filename = options.color_data.palette; else filename = RGB_FILE; if ((fp = fopen (filename, "r")) == NULL) { g_printerr (_("Can't open file %s: %s"), filename, strerror (errno)); return NULL; } store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING); while ((name = fgets (buf, sizeof(buf), fp)) != NULL) { gint r, g, b; gchar spec[8]; if (buf[0] == '!') continue; sscanf (buf, "%d %d %d", &r, &g, &b); g_sprintf (spec, "#%.2X%.2X%.2X", r, g, b); g_sprintf (cl, ". c #%.2X%.2X%.2X", r, g, b); cxpm[1] = cl; pb = gdk_pixbuf_new_from_xpm_data ((const gchar **) cxpm); while (g_ascii_isdigit(*name) || g_ascii_isspace(*name)) name++; gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, pb, 1, spec, 2, g_strstrip (name), -1); } fclose (fp); return GTK_TREE_MODEL (store); }
static void DEFAULT_CC session_start_sessvc(int xpid, int wmpid, long data, char *username, int display) { struct list *sessvc_params = (struct list *)NULL; char wmpid_str[25]; char xpid_str[25]; char exe_path[262]; int i = 0; /* initialize (zero out) local variables: */ g_memset(wmpid_str, 0, sizeof(char) * 25); g_memset(xpid_str, 0, sizeof(char) * 25); g_memset(exe_path, 0, sizeof(char) * 262); /* new style waiting for clients */ g_sprintf(wmpid_str, "%d", wmpid); g_sprintf(xpid_str, "%d", xpid); log_message(LOG_LEVEL_INFO, "starting xrdp-sessvc - xpid=%s - wmpid=%s", xpid_str, wmpid_str); sessvc_params = list_create(); sessvc_params->auto_free = 1; /* building parameters */ g_snprintf(exe_path, 261, "%s/xrdp-sessvc", XRDP_SBIN_PATH); list_add_item(sessvc_params, (long)g_strdup(exe_path)); list_add_item(sessvc_params, (long)g_strdup(xpid_str)); list_add_item(sessvc_params, (long)g_strdup(wmpid_str)); list_add_item(sessvc_params, 0); /* mandatory */ env_set_user(username, 0, display); /* executing sessvc */ g_execvp(exe_path, ((char **)sessvc_params->items)); /* should not get here */ log_message(LOG_LEVEL_ALWAYS, "error starting xrdp-sessvc - pid %d - xpid=%s - wmpid=%s", g_getpid(), xpid_str, wmpid_str); /* logging parameters */ /* no problem calling strerror for thread safety: other threads are blocked */ log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s", errno, g_get_strerror()); log_message(LOG_LEVEL_DEBUG, "execve parameter list:"); for (i = 0; i < (sessvc_params->count); i++) { log_message(LOG_LEVEL_DEBUG, " argv[%d] = %s", i, (char *)list_get_item(sessvc_params, i)); } list_delete(sessvc_params); /* keep the old waitpid if some error occurs during execlp */ g_waitpid(wmpid); g_sigterm(xpid); g_sigterm(wmpid); g_sleep(1000); auth_end(data); g_exit(0); }
/* Hi, this method sucks and is very much untested. However, it did * actually render one utf-8 persian post i looked at, so its still * better than just using g_strescape. * * If you have any experience with non us-english languages, you should * look this over and make it more robust to corner cases. * * Cheers, -- Christian */ static gchar* json_strescape (const gchar *source) { gchar *dest, *q; gunichar *ucs4; gint i, len; if (!g_utf8_validate (source, -1, NULL)) return g_strescape (source, NULL); len = g_utf8_strlen (source, -1); dest = q = g_malloc (len * 6 + 1); ucs4 = g_utf8_to_ucs4_fast (source, -1, NULL); for (i = 0; i < len; i++) { switch (ucs4 [i]) { case '\\': *q++ = '\\'; *q++ = '\\'; break; case '"': *q++ = '\\'; *q++ = '"'; break; case '\b': *q++ = '\\'; *q++ = 'b'; break; case '\f': *q++ = '\\'; *q++ = 'f'; break; case '\n': *q++ = '\\'; *q++ = 'n'; break; case '\r': *q++ = '\\'; *q++ = 'r'; break; case '\t': *q++ = '\\'; *q++ = 't'; break; default: if ((ucs4 [i] >= (gunichar)0x20) || (ucs4 [i] <= (gunichar)0x1F)) { g_sprintf (q, "\\u%04x", ucs4 [i]); q += 6; } else *q++ = ((gchar)ucs4 [i]); } } *q++ = 0; g_free (ucs4); return dest; }
WebResponse* TransactionHandler::ExecuteBySource(WebRequest* pWebRequest, WebContext* pWebContext, User* pUser) { GLogger *pLogger = augeGetLoggerInstance(); TransactionRequest* pRequest = static_cast<TransactionRequest*>(pWebRequest); const char* sourceName = pRequest->GetSourceName(); if(sourceName==NULL) { char msg[AUGE_MSG_MAX]; WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); g_sprintf(msg, "No DataSource is Defined"); pExpResponse->SetMessage(msg); return pExpResponse; } ConnectionManager* pConnManager = augeGetConnectionManagerInstance(); FeatureWorkspace* pWorkspace = dynamic_cast<FeatureWorkspace*>(pConnManager->GetWorkspace(pUser->GetID(), sourceName)); if(pWorkspace==NULL) { char msg[AUGE_MSG_MAX]; g_sprintf(msg, "No DataSource Named [%s]", sourceName); GError* pError = augeGetErrorInstance(); pError->SetError(msg); WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); pExpResponse->SetMessage(msg); return pExpResponse; } const char* typeName = NULL; Layer* pLayer = NULL; XDocument* pxDoc = NULL; pxDoc = pRequest->GetXmlDoc(); if(pxDoc==NULL) { WebExceptionResponse* pExpResponse = augeCreateWebExceptionResponse(); pExpResponse->SetMessage("transaction xml parse error"); return pExpResponse; } XNodeSet *pxNodeSet = NULL; XElement *pxRoot = pxDoc->GetRootNode(); pxNodeSet = pxRoot->GetChildren("Insert"); g_uint num_insert = Insert(pxNodeSet, pWebContext, pWorkspace); pxNodeSet->Release(); pxNodeSet = pxRoot->GetChildren("Update"); g_uint num_update = Update(pxNodeSet, pWebContext, pWorkspace); pxNodeSet->Release(); pxNodeSet = pxRoot->GetChildren("Delete"); g_uint num_delete = Delete(pxNodeSet, pWebContext, pWorkspace); pxNodeSet->Release(); TransactionResponse *pResponse = new TransactionResponse(pRequest); pResponse->SetInsertCount(num_insert); pResponse->SetUpdateCount(num_update); pResponse->SetDeleteCount(num_delete); return pResponse; }
gint main (gint argc, gchar ** argv) { gint ret = 0; VsgPRTree3d *tree; gint i; VsgVector3d lb; VsgVector3d ub; MPI_Init (&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &sz); MPI_Comm_rank (MPI_COMM_WORLD, &rk); if (argc > 1 && g_ascii_strncasecmp (argv[1], "--version", 9) == 0) { if (rk == 0) g_print ("%s\n", PACKAGE_VERSION); return 0; } if (argc > 1 && g_ascii_strncasecmp (argv[1], "--write", 7) == 0) { _do_write = TRUE; } vsg_init_gdouble (); points = g_ptr_array_new (); regions = g_ptr_array_new (); if (rk == 0) { VsgVector3d *pt; Sphere *c; lb.x = -1.; lb.y = -1.; lb.z = -1.; ub.x = 0.; ub.y = 0.; ub.z = 0.; pt = pt_alloc (TRUE, NULL); pt->x = -0.5; pt->y = -0.5; pt->z = -0.5; c = rg_alloc (TRUE, NULL); c->center.x = -0.6; c->center.y = -0.6; c->center.z = -0.6; c->radius = 0.1; } else { VsgVector3d *pt; Sphere *c; lb.x = 0.; lb.y = 0.; lb.z = 0.; ub.x = 1.*rk; ub.y = 1.*rk; ub.z = 1.*rk; pt = pt_alloc (TRUE, NULL); pt->x = 0.5*rk; pt->y = 0.5*rk; pt->z = 0.5*rk; pt = pt_alloc (TRUE, NULL); pt->x = 0.60*rk; pt->y = 0.65*rk; pt->z = 0.70*rk; pt = pt_alloc (TRUE, NULL); pt->x = 0.15*rk; pt->y = 0.75*rk; pt->z = 0.80*rk; c = rg_alloc (TRUE, NULL); c->center.x = 0.6*rk; c->center.y = 0.6*rk; c->center.z = 0.6*rk; c->radius = 0.11; } /* create the tree */ tree = vsg_prtree3d_new_full (&lb, &ub, (VsgPoint3dLocFunc) vsg_vector3d_vector3d_locfunc, (VsgPoint3dDistFunc) vsg_vector3d_dist, (VsgRegion3dLocFunc) _sphere_loc3, 2); /* insert the points */ for (i=0; i<points->len; i++) { vsg_prtree3d_insert_point (tree, g_ptr_array_index (points, i)); } /* insert the regions */ for (i=0; i<regions->len; i++) { vsg_prtree3d_insert_region (tree, g_ptr_array_index (regions, i)); } /* count total created points and regions */ init_total_points_count (); init_total_regions_count (); /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: set_parallel begin\n", rk); */ vsg_prtree3d_set_parallel (tree, &pconfig); /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: set_parallel ok\n", rk); */ ret += check_points_number (tree); ret += check_regions_number (tree); /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: before migrate_flush ok\n", rk); */ { VsgVector3d *pt; Sphere *c; pt = pt_alloc (TRUE, NULL); pt->x = 0.5*rk; pt->y = 0.75*rk; pt->z = 0.75*rk; vsg_prtree3d_insert_point (tree, pt); c = rg_alloc (TRUE, NULL); c->center.x = 1.; c->center.y = 0.6*rk; c->center.z = 0.6*rk; c->radius = 0.1; vsg_prtree3d_insert_region (tree, c); } /* update total points and regions count */ init_total_points_count (); init_total_regions_count (); /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: migrate_flush begin\n", rk); */ vsg_prtree3d_migrate_flush (tree); /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: migrate_flush ok\n", rk); */ ret += check_points_number (tree); ret += check_regions_number (tree); /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: distribute_nodes begin\n", rk); */ for (i=0; i<sz; i++) { gint dst = (i+1) % sz; /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: move to %d\n", rk, dst); */ vsg_prtree3d_distribute_concentrate (tree, dst); ret += check_points_number (tree); ret += check_regions_number (tree); } /* MPI_Barrier (MPI_COMM_WORLD); */ /* g_printerr ("%d: split between nodes\n", rk); */ vsg_prtree3d_distribute_scatter_leaves (tree); ret += check_points_number (tree); ret += check_regions_number (tree); /* /\* MPI_Barrier (MPI_COMM_WORLD); *\/ */ /* /\* g_printerr ("%d: distribute_nodes ok\n", rk); *\/ */ if (_do_write) { MPI_Barrier (MPI_COMM_WORLD); _tree_write (tree); } if (_do_write) { gchar fn[1024]; FILE *f; g_sprintf (fn, "prtree3parallel-%03d.txt", rk); f = fopen (fn, "w"); vsg_prtree3d_write (tree, f); fclose (f); } /* destroy the points */ g_ptr_array_foreach (points, empty_array, NULL); g_ptr_array_free (points, TRUE); /* destroy the spheres */ g_ptr_array_foreach (regions, empty_array, NULL); g_ptr_array_free (regions, TRUE); /* destroy the tree */ vsg_prtree3d_free (tree); MPI_Finalize (); return ret; }
static void gegl_config_set_property (GObject *gobject, guint property_id, const GValue *value, GParamSpec *pspec) { GeglConfig *config = GEGL_CONFIG (gobject); switch (property_id) { case PROP_CACHE_SIZE: config->cache_size = g_value_get_int (value); break; case PROP_CHUNK_SIZE: config->chunk_size = g_value_get_int (value); break; case PROP_TILE_WIDTH: config->tile_width = g_value_get_int (value); break; case PROP_TILE_HEIGHT: config->tile_height = g_value_get_int (value); break; case PROP_QUALITY: config->quality = g_value_get_double (value); return; case PROP_BABL_TOLERANCE: { static gboolean first = TRUE; static gboolean overridden = FALSE; gchar buf[256]; if (first) { if (g_getenv ("BABL_TOLERANCE") != NULL) overridden = TRUE; first = FALSE; } if (!overridden) { config->babl_tolerance = g_value_get_double (value); g_sprintf (buf, "%f", config->babl_tolerance); g_setenv ("BABL_TOLERANCE", buf, 0); /* babl picks up the babl error through the environment, babl * caches valid conversions though so this needs to be set * before any processing is done */ } } return; case PROP_SWAP: if (config->swap) g_free (config->swap); config->swap = g_value_dup_string (value); break; case PROP_THREADS: config->threads = g_value_get_int (value); return; case PROP_USE_OPENCL: config->use_opencl = g_value_get_boolean (value); if (config->use_opencl) gegl_cl_init (NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec); break; } }
gint main (gint argc, gchar ** argv) { gint ret = 0; VsgPRTree2d *tree; VsgVector2d lb; VsgVector2d ub; GTimer *timer = NULL; MPI_Init (&argc, &argv); MPI_Comm_size (MPI_COMM_WORLD, &sz); MPI_Comm_rank (MPI_COMM_WORLD, &rk); vsg_init_gdouble (); parse_args (argc, argv); if (nc_padding > 0) { if (_verbose && rk == 0) g_printerr ("%d: NodeCounter padding: %d\n", rk, nc_padding); _nc_padding_buffer = g_malloc (nc_padding * sizeof (char)); } points = g_ptr_array_new (); lb.x = -1.; lb.y = -1.; ub.x = 1.; ub.y = 1.; /* create the tree */ tree = vsg_prtree2d_new_full (&lb, &ub, (VsgPoint2dLocFunc) vsg_vector2d_vector2d_locfunc, (VsgPoint2dDistFunc) vsg_vector2d_dist, NULL, _maxbox); if (_hilbert) { /* configure for hilbert curve order traversal */ vsg_prtree2d_set_children_order_hilbert (tree); } if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: set_parallel begin\n", rk); } vsg_prtree2d_set_parallel (tree, &pconfig); if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: set_parallel ok\n", rk); } if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: fill begin\n", rk); } _fill (tree, _np); /* /\* try one exterior point *\/ */ /* if (sz > 1) */ /* { */ /* if (rk == 1) */ /* { */ /* Pt *pt; */ /* _ref_count += _np+1; */ /* pt = pt_alloc (TRUE, NULL); */ /* pt->vector.x = ub.x+1.; */ /* pt->vector.y = ub.y+1.; */ /* pt->weight = _np+1; */ /* vsg_prtree2d_insert_point (tree, pt); */ /* } */ /* else */ /* { */ /* _ref_count += _np+1; */ /* } */ /* vsg_prtree2d_migrate_flush (tree); */ /* _distribute (tree); */ /* } */ if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: fill ok\n", rk); } if (_do_write) { gchar fn[1024]; FILE *f; sprintf (fn, "comm-%03d.svg", rk); f = fopen (fn, "w"); fprintf (f, "\n<g style=\"stroke-width:0.01; stroke:black; " \ "fill:none\">\n"); fclose (f); } if (_verbose) { g_printerr ("%d: near/far traversal begin\n", rk); MPI_Barrier (MPI_COMM_WORLD); timer = g_timer_new (); } /* accumulate the point counts across the tree */ _do_upward_pass (tree); /* do some near/far traversal */ vsg_prtree2d_near_far_traversal (tree, (VsgPRTree2dFarInteractionFunc) _far, (VsgPRTree2dInteractionFunc) _near, &ret); /* accumulate from top to leaves */ vsg_prtree2d_traverse (tree, G_PRE_ORDER, (VsgPRTree2dFunc) _down, NULL); if (_verbose) { MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: near/far traversal ok elapsed=%f seconds\n", rk, g_timer_elapsed (timer, NULL)); g_timer_destroy (timer); } if (_do_write) { gchar fn[1024]; FILE *f; MPI_Barrier (MPI_COMM_WORLD); g_sprintf (fn, "prtree2parallel-%03d.txt", rk); f = fopen (fn, "w"); vsg_prtree2d_write (tree, f); fclose (f); _tree_write (tree, "prtree2parallel-"); } if (_do_write) { gchar fn[1024]; FILE *f; sprintf (fn, "comm-%03d.svg", rk); f = fopen (fn, "a"); fprintf (f, "</g>\n"); fclose (f); } if (_verbose) { gint near_count_sum, far_count_sum; MPI_Barrier (MPI_COMM_WORLD); g_printerr ("%d: processor msg stats fw=%d bw=%d\n", rk, _fw_count, _bw_count); g_printerr ("%d: processor call stats near=%d far=%d\n", rk, _near_count, _far_count); MPI_Reduce (&_near_count, &near_count_sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce (&_far_count, &far_count_sum, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); if (rk == 0) { g_printerr ("%d: mean call stats near=%f far=%f\n", rk, (1.*near_count_sum)/sz, (1.*far_count_sum)/sz); } } /* check correctness of results */ g_ptr_array_foreach (points, (GFunc) _check_pt_count, &_ref_count); /* destroy the points */ g_ptr_array_foreach (points, empty_array, NULL); g_ptr_array_free (points, TRUE); /* destroy the tree */ vsg_prtree2d_free (tree); if (nc_padding > 0) g_free (_nc_padding_buffer); MPI_Finalize (); return ret; }